瀏覽代碼

[js] use js.Lib.nativeThis instead of untyped __js__('this') in js.html.compat. this saves some $this closures

Dan Korostelev 9 年之前
父節點
當前提交
f3ba7f199b

+ 7 - 7
std/js/html/compat/ArrayBuffer.hx

@@ -27,7 +27,7 @@ class ArrayBuffer {
 
 
 	public var byteLength : Int;
 	public var byteLength : Int;
 	var a : Array<Int>;
 	var a : Array<Int>;
-	
+
 	public function new( ?a : Dynamic ) {
 	public function new( ?a : Dynamic ) {
 		if( Std.is(a,Array) ) {
 		if( Std.is(a,Array) ) {
 			this.a = a;
 			this.a = a;
@@ -40,17 +40,17 @@ class ArrayBuffer {
 			byteLength = len;
 			byteLength = len;
 		}
 		}
 	}
 	}
-	
+
 	public function slice(begin,?end) {
 	public function slice(begin,?end) {
 		return new ArrayBuffer(a.slice(begin,end));
 		return new ArrayBuffer(a.slice(begin,end));
 	}
 	}
-	
+
 	static function sliceImpl(begin,?end) {
 	static function sliceImpl(begin,?end) {
-		var u = new js.html.Uint8Array(untyped __js__('this'), begin, end == null ? null : end - begin);
-        var result = new js.html.ArrayBuffer(u.byteLength);
-        var resultArray = new js.html.Uint8Array(result);
+		var u = new js.html.Uint8Array(js.Lib.nativeThis, begin, end == null ? null : end - begin);
+		var result = new js.html.ArrayBuffer(u.byteLength);
+		var resultArray = new js.html.Uint8Array(result);
 		resultArray.set(u);
 		resultArray.set(u);
-        return result;
+		return result;
 	}
 	}
 
 
 	static function __init__() untyped {
 	static function __init__() untyped {

+ 8 - 8
std/js/html/compat/Float32Array.hx

@@ -22,6 +22,8 @@
 package js.html.compat;
 package js.html.compat;
 
 
 #if !nodejs
 #if !nodejs
+import js.Lib.nativeThis;
+
 @:keep
 @:keep
 class Float32Array {
 class Float32Array {
 
 
@@ -45,7 +47,7 @@ class Float32Array {
 			arr = [];
 			arr = [];
 			// decode buffer
 			// decode buffer
 			for( i in 0...length ) {
 			for( i in 0...length ) {
-				var val = untyped buffer.a[offset++] | (buffer.a[offset++] << 8) | (buffer.a[offset++] << 16) | (buffer.a[offset++] << 24);  
+				var val = untyped buffer.a[offset++] | (buffer.a[offset++] << 8) | (buffer.a[offset++] << 16) | (buffer.a[offset++] << 24);
 				arr.push(haxe.io.FPHelper.i32ToFloat(val));
 				arr.push(haxe.io.FPHelper.i32ToFloat(val));
 			}
 			}
 			untyped {
 			untyped {
@@ -79,26 +81,24 @@ class Float32Array {
 	}
 	}
 
 
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
-		var t : Dynamic = untyped __js__("this");
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( arg.byteLength + offset > t.byteLength )
+			if( arg.byteLength + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...arg.byteLength )
 			for( i in 0...arg.byteLength )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else if( Std.is(arg,Array) ) {
 		} else if( Std.is(arg,Array) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( a.length + offset > t.byteLength )
+			if( a.length + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...a.length )
 			for( i in 0...a.length )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else
 		} else
 			throw "TODO";
 			throw "TODO";
 	}
 	}
 
 
 	static function _subarray( start : Int, ?end : Int ) {
 	static function _subarray( start : Int, ?end : Int ) {
-		var t : Dynamic = untyped __js__("this");
-		var a = _new(t.slice(start,end));
+		var a = _new(nativeThis.slice(start,end));
 		a.byteOffset = start * 4;
 		a.byteOffset = start * 4;
 		return a;
 		return a;
 	}
 	}

+ 7 - 7
std/js/html/compat/Float64Array.hx

@@ -22,6 +22,8 @@
 package js.html.compat;
 package js.html.compat;
 
 
 #if !nodejs
 #if !nodejs
+import js.Lib.nativeThis;
+
 @:keep
 @:keep
 class Float64Array {
 class Float64Array {
 
 
@@ -86,26 +88,24 @@ class Float64Array {
 	}
 	}
 
 
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
-		var t : Dynamic = untyped __js__("this");
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( arg.byteLength + offset > t.byteLength )
+			if( arg.byteLength + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...arg.byteLength )
 			for( i in 0...arg.byteLength )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else if( Std.is(arg,Array) ) {
 		} else if( Std.is(arg,Array) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( a.length + offset > t.byteLength )
+			if( a.length + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...a.length )
 			for( i in 0...a.length )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else
 		} else
 			throw "TODO";
 			throw "TODO";
 	}
 	}
 
 
 	static function _subarray( start : Int, ?end : Int ) {
 	static function _subarray( start : Int, ?end : Int ) {
-		var t : Dynamic = untyped __js__("this");
-		var a = _new(t.slice(start,end));
+		var a = _new(nativeThis.slice(start,end));
 		a.byteOffset = start * 8;
 		a.byteOffset = start * 8;
 		return a;
 		return a;
 	}
 	}

+ 7 - 7
std/js/html/compat/Uint8Array.hx

@@ -22,6 +22,8 @@
 package js.html.compat;
 package js.html.compat;
 
 
 #if !nodejs
 #if !nodejs
+import js.Lib.nativeThis;
+
 @:keep
 @:keep
 class Uint8Array {
 class Uint8Array {
 
 
@@ -70,26 +72,24 @@ class Uint8Array {
 	}
 	}
 
 
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
 	static function _set( ?arg : Dynamic, ?offset : Int ) {
-		var t : Dynamic = untyped __js__("this");
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 		if( Std.is(arg.buffer,ArrayBuffer) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( arg.byteLength + offset > t.byteLength )
+			if( arg.byteLength + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...arg.byteLength )
 			for( i in 0...arg.byteLength )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else if( Std.is(arg,Array) ) {
 		} else if( Std.is(arg,Array) ) {
 			var a : Array<Int> = arg;
 			var a : Array<Int> = arg;
-			if( a.length + offset > t.byteLength )
+			if( a.length + offset > nativeThis.byteLength )
 				throw "set() outside of range";
 				throw "set() outside of range";
 			for( i in 0...a.length )
 			for( i in 0...a.length )
-				t[i + offset] = a[i];
+				nativeThis[i + offset] = a[i];
 		} else
 		} else
 			throw "TODO";
 			throw "TODO";
 	}
 	}
 
 
 	static function _subarray( start : Int, ?end : Int ) {
 	static function _subarray( start : Int, ?end : Int ) {
-		var t : Dynamic = untyped __js__("this");
-		var a = _new(t.slice(start,end));
+		var a = _new(nativeThis.slice(start,end));
 		a.byteOffset = start;
 		a.byteOffset = start;
 		return a;
 		return a;
 	}
 	}