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

[js] lose some untyped and add some @:pure

Dan Korostelev 8 жил өмнө
parent
commit
6f617bfc23

+ 6 - 5
std/js/_std/Array.hx

@@ -38,7 +38,7 @@ extern class Array<T> {
 	function unshift( x : T ) : Void;
 
 	inline function insert( pos : Int, x : T ) : Void {
-		(untyped this).splice(pos,0,x);
+		(cast this).splice(pos,0,x);
 	}
 
 	inline function remove( x : T ) : Bool {
@@ -46,8 +46,8 @@ extern class Array<T> {
 	}
 
 #if (js_es >= 5)
-	function indexOf( x : T, ?fromIndex:Int ) : Int;
-	function lastIndexOf( x : T, ?fromIndex:Int ) : Int;
+	@:pure function indexOf( x : T, ?fromIndex:Int ) : Int;
+	@:pure function lastIndexOf( x : T, ?fromIndex:Int ) : Int;
 
 #else
 	inline function indexOf( x : T, ?fromIndex:Int ) : Int {
@@ -59,15 +59,16 @@ extern class Array<T> {
 	}
 #end
 
+	@:pure
 	inline function copy() : Array<T> {
-		return (untyped this).slice();
+		return (cast this).slice();
 	}
 
 	function map<S>(f:T->S):Array<S>;
 	function filter(f:T->Bool):Array<T>;
 
 	@:runtime inline function iterator() : Iterator<T> {
-		return untyped HxOverrides.iter(this);
+		return @:privateAccess HxOverrides.iter(this);
 	}
 
 }

+ 6 - 1
std/js/_std/HxOverrides.hx

@@ -59,6 +59,7 @@ class HxOverrides {
 		}
 	}
 
+	@:pure
 	static function cca( s : String, index : Int ) : Null<Int> {
 		var x = (cast s).charCodeAt(index);
 		if( x != x ) // fast isNaN
@@ -66,6 +67,7 @@ class HxOverrides {
 		return x;
 	}
 
+	@:pure
 	static function substr( s : String, pos : Int, ?len : Int ) : String {
 		if (len == null) {
 			len = s.length;
@@ -84,9 +86,10 @@ class HxOverrides {
 		}
 		#end
 
-		return (untyped s).substr(pos, len);
+		return (cast s).substr(pos, len);
 	}
 
+	@:pure
 	static function indexOf<T>( a : Array<T>, obj : T, i : Int) {
 		var len = a.length;
 		if (i < 0) {
@@ -102,6 +105,7 @@ class HxOverrides {
 		return -1;
 	}
 
+	@:pure
 	static function lastIndexOf<T>( a : Array<T>, obj : T, i : Int) {
 		var len = a.length;
 		if (i >= len)
@@ -124,6 +128,7 @@ class HxOverrides {
 		return true;
 	}
 
+	@:pure
 	static function iter<T>( a : Array<T> ) : Iterator<T> untyped {
 		return {
 			cur : 0,