2
0
Эх сурвалжийг харах

[js] fix(?) ObjectMap static init (see #6792)

Dan Korostelev 7 жил өмнө
parent
commit
392806ae8e

+ 7 - 2
std/js/_std/haxe/ds/ObjectMap.hx

@@ -25,7 +25,12 @@ package haxe.ds;
 @:coreApi
 class ObjectMap<K:{ }, V> implements haxe.Constraints.IMap<K,V> {
 
-	static var count = 0;
+	static var count:Int;
+
+	// initialize count through __init__ magic, because these are generated
+	// before normal static initializations for which ObjectMap should be ready to use
+	// see https://github.com/HaxeFoundation/haxe/issues/6792
+	static inline function __init__():Void count = 0;
 
 	static inline function assignId(obj: { } ):Int {
 		return untyped obj.__id__ = ++count;
@@ -82,7 +87,7 @@ class ObjectMap<K:{ }, V> implements haxe.Constraints.IMap<K,V> {
 			next : function() { var i = __this__.it.next(); return __this__.ref[getId(i)]; }
 		};
 	}
-	
+
 	public function copy() : ObjectMap<K,V> {
 		var copied = new ObjectMap();
 		for(key in keys()) copied.set(key, get(key));