Преглед изворни кода

[eval] add prefix to object prototype identification string

Otherwise we cannot distinguish the empty object from an object which has one field that has no name, which apparently is a thing.

closes #8053
Simon Krajewski пре 6 година
родитељ
комит
8ae4e7f364
2 измењених фајлова са 11 додато и 1 уклоњено
  1. 1 1
      src/macro/eval/evalPrototype.ml
  2. 10 0
      tests/unit/src/unit/issues/Issue8053.hx

+ 1 - 1
src/macro/eval/evalPrototype.ml

@@ -285,7 +285,7 @@ let create_instance_prototype ctx c =
 
 let get_object_prototype ctx l =
 	let l = List.sort (fun (i1,_) (i2,_) -> if i1 = i2 then 0 else if i1 < i2 then -1 else 1) l in
-	let sfields = String.concat "," (List.map (fun (i,_) -> rev_hash i) l) in
+	let sfields = String.concat "," (List.map (fun (i,_) -> (Printf.sprintf ":%s" (rev_hash i))) l) in
 	let name = hash (Printf.sprintf "eval.object.Object[%s]" sfields) in
 	try
 		IntMap.find name ctx.instance_prototypes,l

+ 10 - 0
tests/unit/src/unit/issues/Issue8053.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+class Issue8053 extends unit.Test {
+	function test() {
+		var a:Dynamic = { };
+		var b = "";
+		Reflect.setField(a, b, 1);
+		eq(1, Reflect.field(a, b));
+	}
+}