Browse Source

more work on ie8-9 emulation

Nicolas Cannasse 10 years ago
parent
commit
06068a5298

+ 5 - 0
std/haxe/io/ArrayBufferView.hx

@@ -22,6 +22,11 @@ class ArrayBufferViewImpl {
 
 
 abstract ArrayBufferView(ArrayBufferViewData) {
 abstract ArrayBufferView(ArrayBufferViewData) {
 
 
+	public static var EMULATED(get,never) : Bool;
+	static #if !js inline #end function get_EMULATED() {
+		return #if js (cast js.html.ArrayBuffer) == js.html.compat.ArrayBuffer #else false #end;
+	}
+
 	public var buffer(get,never) : haxe.io.Bytes;
 	public var buffer(get,never) : haxe.io.Bytes;
 	public var byteOffset(get, never) : Int;
 	public var byteOffset(get, never) : Int;
 	public var byteLength(get, never) : Int;
 	public var byteLength(get, never) : Int;

+ 1 - 1
std/haxe/io/Uint8Array.hx

@@ -59,7 +59,7 @@ abstract Uint8Array(Uint8ArrayData) {
 	
 	
 	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
 	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
 		#if js
 		#if js
-		return this[index] = value;
+		return this[index] = value & 0xFF; // &0xFF necessary for html compat
 		#else
 		#else
 		if( index >= 0 && index < length ) {
 		if( index >= 0 && index < length ) {
 			this.bytes.set(index + this.byteOffset, value);
 			this.bytes.set(index + this.byteOffset, value);

+ 13 - 6
tests/unit/src/unitstd/haxe/io/Float32Array.unit.hx

@@ -1,3 +1,6 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
 var b = new haxe.io.Float32Array(5);
 var b = new haxe.io.Float32Array(5);
 b[0] == 0;
 b[0] == 0;
 b[4] == 0;
 b[4] == 0;
@@ -7,9 +10,11 @@ b.length == 5;
 b[1] = 1.25;
 b[1] = 1.25;
 b[1] == 1.25;
 b[1] == 1.25;
 
 
-// check loss of precision
-b[1] = 8589934592.;
-b[1] == 8589934592.;
+// check loss of precision due to 32 bits
+if( !emulated ) {
+	b[1] = 8589934591.;
+	b[1] == 8589934592.;
+}
 
 
 // set
 // set
 for( i in 0...5 )
 for( i in 0...5 )
@@ -31,9 +36,11 @@ b2[2] == 4;
 b2.length == 3;
 b2.length == 3;
 
 
 // check memory sharing
 // check memory sharing
-b2[0] = 0xCC;
-b2[0] == 0xCC;
-b[1] == 0xCC;
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
 
 
 // should we allow writing past bounds ?
 // should we allow writing past bounds ?
 try b2[-1] = 0xBB catch( e : Dynamic ) {};
 try b2[-1] = 0xBB catch( e : Dynamic ) {};

+ 9 - 4
tests/unit/src/unitstd/haxe/io/Uint8Array.unit.hx

@@ -1,3 +1,6 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
 var b = new haxe.io.Uint8Array(5);
 var b = new haxe.io.Uint8Array(5);
 b[0] == 0;
 b[0] == 0;
 b[4] == 0;
 b[4] == 0;
@@ -9,7 +12,7 @@ b[0] == 1;
 b[0] = -2;
 b[0] = -2;
 b[0] == 254;
 b[0] == 254;
 
 
-// vheck write for big int
+// check write for big int
 b[1] = 65535 * 65534 * 65533;
 b[1] = 65535 * 65534 * 65533;
 b[1] == 0xFA;
 b[1] == 0xFA;
 
 
@@ -33,9 +36,11 @@ b2[2] == 4;
 b2.length == 3;
 b2.length == 3;
 
 
 // check memory sharing
 // check memory sharing
-b2[0] = 0xCC;
-b2[0] == 0xCC;
-b[1] == 0xCC;
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
 
 
 // should we allow writing past bounds ?
 // should we allow writing past bounds ?
 try b2[-1] = 0xBB catch( e : Dynamic ) {};
 try b2[-1] = 0xBB catch( e : Dynamic ) {};