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

[js] Add ArrayBuffer.slice polyfill for IE 10 support

George Corney 7 жил өмнө
parent
commit
918b822ffe

+ 20 - 1
std/js/html/ArrayBuffer.hx

@@ -33,4 +33,23 @@ extern class ArrayBuffer
 	/** @throws DOMError */
 	function new( length : Int ) : Void;
 	function slice( begin : Int, ?end : Int ) : ArrayBuffer;
-}
+}
+
+#if (js_es <= 5)
+@:ifFeature('js.html.ArrayBuffer.slice')
+private class ArrayBufferCompat {
+
+	static function sliceImpl(begin, ?end) {	
+		var u = new js.html.Uint8Array(js.Lib.nativeThis, begin, end == null ? null : (end - begin));
+		var resultArray = new js.html.Uint8Array(u.byteLength);	
+		resultArray.set(u);	
+		return resultArray.buffer;
+	}
+
+	static inline function __init__(): Void untyped {
+		// IE10 ArrayBuffer.slice polyfill
+		if( __js__("ArrayBuffer").prototype.slice == null ) __js__("ArrayBuffer").prototype.slice = sliceImpl;
+	}
+
+}
+#end