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

js : ensure that including twice doesn't break timer array

Nicolas Cannasse 14 жил өмнө
parent
commit
6933d258e6
1 өөрчлөгдсөн 9 нэмэгдсэн , 3 устгасан
  1. 9 3
      std/haxe/Timer.hx

+ 9 - 3
std/haxe/Timer.hx

@@ -31,7 +31,6 @@ class Timer {
 	private var id : Null<Int>;
 
 	#if js
-	private static var arr : Array<Timer>;
 	private var timerId : Int;
 	#end
 
@@ -43,10 +42,10 @@ class Timer {
 			var me = this;
 			id = untyped _global["setInterval"](function() { me.run(); },time_ms);
 		#elseif js
-			if( arr == null ) arr = [];
+			var arr : Array<Timer> = untyped haxe_timers;
 			id = arr.length;
 			arr[id] = this;
-			timerId = untyped window.setInterval("haxe.Timer.arr["+id+"].run();",time_ms);
+			timerId = untyped window.setInterval("haxe_timers["+id+"].run();",time_ms);
 		#end
 	}
 
@@ -59,6 +58,7 @@ class Timer {
 			untyped _global["clearInterval"](id);
 		#elseif js
 			untyped window.clearInterval(timerId);
+			var arr = untyped haxe_timers;
 			arr[id] = null;
 			if( id > 100 && id == arr.length - 1 ) {
 				// compact array
@@ -111,4 +111,10 @@ class Timer {
 		#end
 	}
 
+	#if js
+	static function __init__() untyped {
+		if( __js__('typeof')(haxe_timers) == 'undefined' ) haxe_timers = [];
+	}
+	#end
+	
 }