mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-30 03:25:47 -05:00
Fix issue with deepMerge() caused by handling maps incorrectly, causing an unhandleable crash.
This commit is contained in:
parent
ad39ce3c21
commit
4f2f28cb31
1 changed files with 64 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package funkin.util;
|
||||
|
||||
import funkin.util.tools.MapTools;
|
||||
import haxe.DynamicAccess;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +27,57 @@ class StructureUtil
|
|||
return result;
|
||||
}
|
||||
|
||||
public static function toMap(a:Dynamic):haxe.ds.Map<String, Dynamic>
|
||||
{
|
||||
var result:haxe.ds.Map<String, Dynamic> = [];
|
||||
|
||||
for (field in Reflect.fields(a))
|
||||
{
|
||||
result.set(field, Reflect.field(a, field));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static function isMap(a:Dynamic):Bool
|
||||
{
|
||||
return Std.isOfType(a, haxe.Constraints.IMap);
|
||||
}
|
||||
|
||||
public static function isObject(a:Dynamic):Bool
|
||||
{
|
||||
switch (Type.typeof(a))
|
||||
{
|
||||
case TObject:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isPrimitive(a:Dynamic):Bool
|
||||
{
|
||||
switch (Type.typeof(a))
|
||||
{
|
||||
case TInt | TFloat | TBool:
|
||||
return true;
|
||||
case TClass(c):
|
||||
return false;
|
||||
case TEnum(e):
|
||||
return false;
|
||||
case TObject:
|
||||
return false;
|
||||
case TFunction:
|
||||
return false;
|
||||
case TNull:
|
||||
return true;
|
||||
case TUnknown:
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two structures, with the second overwriting the first.
|
||||
* Performs a DEEP clone, where child structures are also merged recursively.
|
||||
|
@ -37,6 +89,18 @@ class StructureUtil
|
|||
{
|
||||
if (a == null) return b;
|
||||
if (b == null) return null;
|
||||
if (isPrimitive(a) && isPrimitive(b)) return b;
|
||||
if (isMap(b))
|
||||
{
|
||||
if (isMap(a))
|
||||
{
|
||||
return MapTools.merge(a, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
return StructureUtil.toMap(a).merge(b);
|
||||
}
|
||||
}
|
||||
if (!Reflect.isObject(a) || !Reflect.isObject(b)) return b;
|
||||
|
||||
var result:DynamicAccess<Dynamic> = Reflect.copy(a);
|
||||
|
|
Loading…
Reference in a new issue