Преглед изворни кода

typed arrays fixes for nodeJS (does not respect spec wrt optional length) close #4142

Nicolas Cannasse пре 10 година
родитељ
комит
4c1e83c64f

+ 1 - 0
std/js/_std/haxe/io/Float32Array.hx

@@ -80,6 +80,7 @@ abstract Float32Array(Float32ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : Float32Array {
+		if( length == null ) length = (bytes.length - bytePos) >> 2;
 		return fromData(new Float32ArrayData(bytes.getData(), bytePos, length));
 	}
 }

+ 1 - 0
std/js/_std/haxe/io/Float64Array.hx

@@ -80,6 +80,7 @@ abstract Float64Array(Float64ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : Float64Array {
+		if( length == null ) length = (bytes.length - bytePos) >> 3;
 		return fromData(new Float64ArrayData(bytes.getData(), bytePos, length));
 	}
 }

+ 1 - 0
std/js/_std/haxe/io/Int32Array.hx

@@ -78,6 +78,7 @@ abstract Int32Array(Int32ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : Int32Array {
+		if( length == null ) length = (bytes.length - bytePos) >> 2;
 		return fromData(new Int32ArrayData(bytes.getData(), bytePos, length));
 	}
 

+ 1 - 0
std/js/_std/haxe/io/UInt16Array.hx

@@ -78,6 +78,7 @@ abstract UInt16Array(UInt16ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : UInt16Array {
+		if( length == null ) length = (bytes.length - bytePos) >> 1;
 		return fromData(new UInt16ArrayData(bytes.getData(), bytePos, length));
 	}
 

+ 1 - 0
std/js/_std/haxe/io/UInt32Array.hx

@@ -78,6 +78,7 @@ abstract UInt32Array(UInt32ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : UInt32Array {
+		if( length == null ) length = (bytes.length - bytePos) >> 2;
 		return fromData(new UInt32ArrayData(bytes.getData(), bytePos, length));
 	}
 

+ 1 - 0
std/js/_std/haxe/io/UInt8Array.hx

@@ -78,6 +78,7 @@ abstract UInt8Array(UInt8ArrayData) {
 	}
 
 	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : UInt8Array {
+		if( length == null ) length = bytes.length - bytePos;
 		return fromData(new UInt8ArrayData(bytes.getData(), bytePos, length));
 	}