2
0
Nicolas Cannasse 10 жил өмнө
parent
commit
90e09a4b52

+ 23 - 0
std/haxe/io/Bytes.hx

@@ -292,6 +292,29 @@ class Bytes {
 		#end
 	}
 
+	/**
+		Returns the 16 bit unsignged integer at given position (in low endian encoding).
+	**/
+	public inline function getUInt16( pos : Int ) : Int {
+		#if neko_v21
+		return untyped $sget16(b, pos, false);
+		#else
+		return get(pos) | (get(pos + 1) << 8);
+		#end
+	}
+
+	/**
+		Returns the 16 bit unsignged integer at given position (in low endian encoding).
+	**/
+	public inline function setUInt16( pos : Int, v : Int ) : Void {
+		#if neko_v21
+		untyped $sset16(b, pos, v, false);
+		#else
+		set(pos, v);
+		set(pos + 1, v >> 8);
+		#end
+	}
+
 	/**
 		Returns the 32 bit integer at given position (in low endian encoding).
 	**/

+ 85 - 0
std/haxe/io/Float64Array.hx

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef Float64ArrayData = ArrayBufferView.ArrayBufferViewData;
+
+abstract Float64Array(Float64ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 8;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
+	}
+
+	inline function get_length() {
+		return this.byteLength >> 3;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Float {
+		return this.bytes.getFloat((index<<3) + this.byteOffset);
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Float ) : Float {
+		if( index >= 0 && index < length ) {
+			this.bytes.setFloat((index<<3) + this.byteOffset, value);
+			return value;
+		}
+		return 0;
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : Float64Array {
+		return fromData(this.sub(begin<<3,length == null ? null : length<<3));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : Float64Array {
+		return fromData(this.subarray(begin==null?null:begin<<3,end==null?null:end<<3));
+	}
+
+	public inline function getData() : Float64ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : Float64ArrayData ) : Float64Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Float>, pos = 0, ?length : Int ) : Float64Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		var i = new Float64Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos = 0, ?length : Int ) : Float64Array {
+		return fromData(ArrayBufferView.fromBytes(bytes,bytePos,(length == null ? (bytes.length - bytePos)>>3 : length)<<3).getData());
+	}
+}
+

+ 85 - 0
std/haxe/io/Int32Array.hx

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef Int32ArrayData = ArrayBufferView.ArrayBufferViewData;
+
+abstract Int32Array(Int32ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 4;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
+	}
+
+	inline function get_length() {
+		return this.byteLength >> 2;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Int {
+		return this.bytes.getInt32((index<<2) + this.byteOffset);
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
+		if( index >= 0 && index < length ) {
+			this.bytes.setInt32((index<<2) + this.byteOffset, value);
+			return value;
+		}
+		return 0;
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : Int32Array {
+		return fromData(this.sub(begin<<2,length == null ? null : length<<2));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : Int32Array {
+		return fromData(this.subarray(begin==null?null:begin<<2,end==null?null:end<<2));
+	}
+
+	public inline function getData() : Int32ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : Int32ArrayData ) : Int32Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Int>, pos = 0, ?length : Int ) : Int32Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		var i = new Int32Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos = 0, ?length : Int ) : Int32Array {
+		return fromData(ArrayBufferView.fromBytes(bytes,bytePos,(length == null ? (bytes.length - bytePos)>>2 : length)<<2).getData());
+	}
+}
+

+ 85 - 0
std/haxe/io/UInt16Array.hx

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef UInt16ArrayData = ArrayBufferView.ArrayBufferViewData;
+
+abstract UInt16Array(UInt16ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 2;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
+	}
+
+	inline function get_length() {
+		return this.byteLength >> 1;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Int {
+		return this.bytes.getUInt16((index<<1) + this.byteOffset);
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
+		if( index >= 0 && index < length ) {
+			this.bytes.setUInt16((index<<1) + this.byteOffset, value);
+			return value;
+		}
+		return 0;
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : UInt16Array {
+		return fromData(this.sub(begin<<1,length == null ? null : length<<1));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : UInt16Array {
+		return fromData(this.subarray(begin==null?null:begin<<1,end==null?null:end<<1));
+	}
+
+	public inline function getData() : UInt16ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : UInt16ArrayData ) : UInt16Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Int>, pos = 0, ?length : Int ) : UInt16Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		var i = new UInt16Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos = 0, ?length : Int ) : UInt16Array {
+		return fromData(ArrayBufferView.fromBytes(bytes,bytePos,(length == null ? (bytes.length - bytePos)>>1 : length)<<1).getData());
+	}
+}
+

+ 85 - 0
std/haxe/io/UInt32Array.hx

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef UInt32ArrayData = ArrayBufferView.ArrayBufferViewData;
+
+abstract UInt32Array(UInt32ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 4;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new ArrayBufferView(elements * BYTES_PER_ELEMENT).getData();
+	}
+
+	inline function get_length() {
+		return this.byteLength >> 2;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : UInt {
+		return this.bytes.getInt32((index<<2) + this.byteOffset);
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : UInt ) : UInt {
+		if( index >= 0 && index < length ) {
+			this.bytes.setInt32((index<<2) + this.byteOffset, value);
+			return value;
+		}
+		return 0;
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : UInt32Array {
+		return fromData(this.sub(begin<<2,length == null ? null : length<<2));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : UInt32Array {
+		return fromData(this.subarray(begin==null?null:begin<<2,end==null?null:end<<2));
+	}
+
+	public inline function getData() : UInt32ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : UInt32ArrayData ) : UInt32Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<UInt>, pos = 0, ?length : Int ) : UInt32Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		var i = new UInt32Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos = 0, ?length : Int ) : UInt32Array {
+		return fromData(ArrayBufferView.fromBytes(bytes,bytePos,(length == null ? (bytes.length - bytePos)>>2 : length)<<2).getData());
+	}
+}
+

+ 10 - 0
std/js/_std/haxe/io/Bytes.hx

@@ -96,6 +96,16 @@ class Bytes {
 		data.setFloat32(pos, v, true);
 	}
 
+	public function getUInt16( pos : Int ) : Int {
+		initData();
+		return data.getUint16(pos, true);
+	}
+
+	public function setUInt16( pos : Int, v : Int ) : Void {
+		initData();
+		data.setUint16(pos, v, true);
+	}
+
 	public function getInt32( pos : Int ) : Int {
 		initData();
 		return data.getInt32(pos, true);

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

@@ -0,0 +1,86 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+import js.html.compat.Float64Array;
+
+typedef Float64ArrayData = js.html.Float64Array;
+
+@:coreApi
+abstract Float64Array(Float64ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 4;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) : Void {
+		this = new Float64ArrayData(elements);
+	}
+
+	inline function get_length() : Int {
+		return this.length;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Float {
+		return this[index];
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Float ) : Float {
+		return this[index] = value;
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : Float64Array {
+		return fromData(this.subarray(begin, length == null ? this.length : begin+length));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : Float64Array {
+		return fromData(this.subarray(begin, end));
+	}
+
+	public inline function getData() : Float64ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : Float64ArrayData ) : Float64Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Float>, pos : Int = 0, ?length : Int ) : Float64Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		if( pos == 0 && length == a.length )
+			return fromData(new Float64ArrayData(a));
+		var i = new Float64Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : Float64Array {
+		return fromData(new Float64ArrayData(bytes.getData(), bytePos, length));
+	}
+}
+

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

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef Int32ArrayData = js.html.Int32Array;
+
+@:coreApi
+abstract Int32Array(Int32ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 1;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new Int32ArrayData(elements * BYTES_PER_ELEMENT);
+	}
+
+	inline function get_length() : Int {
+		return this.length;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Int {
+		return this[index];
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
+		return this[index] = value | 0; // necessary for html compat
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : Int32Array {
+		return fromData(this.subarray(begin, length == null ? this.length : begin+length));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : Int32Array {
+		return fromData(this.subarray(begin, end));
+	}
+
+	public inline function getData() : Int32ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : Int32ArrayData ) : Int32Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Int>, pos : Int = 0, ?length : Int ) : Int32Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		if( pos == 0 && length == a.length )
+			return fromData(new Int32ArrayData(a));
+		var i = new Int32Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : Int32Array {
+		return fromData(new Int32ArrayData(bytes.getData(), bytePos, length));
+	}
+
+}
+

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

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef UInt16ArrayData = js.html.Uint16Array;
+
+@:coreApi
+abstract UInt16Array(UInt16ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 2;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new UInt16ArrayData(elements);
+	}
+
+	inline function get_length() : Int {
+		return this.length;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : Int {
+		return this[index];
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : Int ) : Int {
+		return this[index] = value & 0xFFFF; // &0xFFFF necessary for html compat
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : UInt16Array {
+		return fromData(this.subarray(begin, length == null ? this.length : begin+length));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : UInt16Array {
+		return fromData(this.subarray(begin, end));
+	}
+
+	public inline function getData() : UInt16ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : UInt16ArrayData ) : UInt16Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<Int>, pos : Int = 0, ?length : Int ) : UInt16Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		if( pos == 0 && length == a.length )
+			return fromData(new UInt16ArrayData(a));
+		var i = new UInt16Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : UInt16Array {
+		return fromData(new UInt16ArrayData(bytes.getData(), bytePos, length));
+	}
+
+}
+

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

@@ -0,0 +1,85 @@
+/*
+ * Copyright (C)2005-2015 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.io;
+
+typedef UInt32ArrayData = js.html.Uint32Array;
+
+@:coreApi
+abstract UInt32Array(UInt32ArrayData) {
+
+	public static inline var BYTES_PER_ELEMENT = 4;
+	public var length(get,never) : Int;
+	public var view(get,never) : ArrayBufferView;
+
+	public inline function new( elements : Int ) {
+		this = new UInt32ArrayData(elements);
+	}
+
+	inline function get_length() : Int {
+		return this.length;
+	}
+
+	public inline function get_view() : ArrayBufferView {
+		return ArrayBufferView.fromData(this);
+	}
+
+	@:arrayAccess public inline function get( index : Int ) : UInt {
+		return this[index];
+	}
+
+	@:arrayAccess public inline function set( index : Int, value : UInt ) : UInt {
+		return this[index] = value | 0; // necessary for html compat
+	}
+
+	public inline function sub( begin : Int, ?length : Int ) : UInt32Array {
+		return fromData(this.subarray(begin, length == null ? this.length : begin+length));
+	}
+
+	public inline function subarray( ?begin : Int, ?end : Int ) : UInt32Array {
+		return fromData(this.subarray(begin, end));
+	}
+
+	public inline function getData() : UInt32ArrayData {
+		return this;
+	}
+
+	public static function fromData( d : UInt32ArrayData ) : UInt32Array {
+		return cast d;
+	}
+
+	public static function fromArray( a : Array<UInt>, pos : Int = 0, ?length : Int ) : UInt32Array {
+		if( length == null ) length = a.length - pos;
+		if( pos < 0 || length < 0 || pos + length > a.length ) throw Error.OutsideBounds;
+		if( pos == 0 && length == a.length )
+			return fromData(new UInt32ArrayData(a));
+		var i = new UInt32Array(a.length);
+		for( idx in 0...length )
+			i[idx] = a[idx + pos];
+		return i;
+	}
+
+	public static function fromBytes( bytes : haxe.io.Bytes, bytePos : Int = 0, ?length : Int ) : UInt32Array {
+		return fromData(new UInt32ArrayData(bytes.getData(), bytePos, length));
+	}
+
+}
+

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

@@ -31,7 +31,7 @@ abstract UInt8Array(UInt8ArrayData) {
 	public var view(get,never) : ArrayBufferView;
 
 	public inline function new( elements : Int ) {
-		this = new UInt8ArrayData(elements * BYTES_PER_ELEMENT);
+		this = new UInt8ArrayData(elements);
 	}
 
 	inline function get_length() : Int {

+ 116 - 0
std/js/html/compat/Float64Array.hx

@@ -0,0 +1,116 @@
+/*
+ * Copyright (C)2005-2014 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package js.html.compat;
+
+@:keep
+class Float64Array {
+
+	static var BYTES_PER_ELEMENT = 8;
+
+	static function _new( ?arg1 : Dynamic, ?offset : Int, ?length : Int ) : Dynamic {
+		var arr : Array<Float>;
+		if( untyped __typeof__(arg1) == 'number' ) {
+			arr = new Array();
+			for( i in 0...arg1 )
+				arr[i] = 0;
+			untyped {
+				arr.byteLength = arr.length << 3;
+				arr.byteOffset = 0;
+				arr.buffer = new ArrayBuffer([for( i in 0...arr.length << 3 ) 0]); // no sync
+			}
+		} else if( Std.is(arg1,ArrayBuffer) ) {
+			var buffer : ArrayBuffer = arg1;
+			if( offset == null ) offset = 0;
+			if( length == null ) length = (buffer.byteLength - offset) >> 3;
+			arr = [];
+			// decode buffer
+			for( i in 0...length ) {
+				var val1 = untyped buffer.a[offset++] | (buffer.a[offset++] << 8) | (buffer.a[offset++] << 16) | (buffer.a[offset++] << 24);
+				var val2 = untyped buffer.a[offset++] | (buffer.a[offset++] << 8) | (buffer.a[offset++] << 16) | (buffer.a[offset++] << 24);
+				arr.push(haxe.io.FPHelper.i64ToDouble(val1,val2));
+			}
+			untyped {
+				arr.byteLength = arr.length<<3;
+				arr.byteOffset = offset;
+				arr.buffer = buffer;
+			}
+		} else if( Std.is(arg1, Array) ) {
+			arr = (arg1 : Array<Float>).copy();
+			// loss of memory sync between buffer and array
+			var buffer = [];
+			for( f in arr ) {
+				var v = haxe.io.FPHelper.doubleToI64(f);
+				var i = v.low;
+				buffer.push(i&0xFF);
+				buffer.push((i>>8)&0xFF);
+				buffer.push((i>>16)&0xFF);
+				buffer.push(i>>>24);
+				var i = v.high;
+				buffer.push(i&0xFF);
+				buffer.push((i>>8)&0xFF);
+				buffer.push((i>>16)&0xFF);
+				buffer.push(i>>>24);
+			}
+			untyped {
+				arr.byteLength = arr.length << 3;
+				arr.byteOffset = 0;
+				arr.buffer = new ArrayBuffer(buffer);
+			}
+		} else
+			throw "TODO "+arg1;
+		untyped {
+			arr.subarray = _subarray;
+			arr.set = _set;
+		}
+		return arr;
+	}
+
+	static function _set( ?arg : Dynamic, ?offset : Int ) {
+		var t : Dynamic = untyped __js__("this");
+		if( Std.is(arg.buffer,ArrayBuffer) ) {
+			var a : Array<Int> = arg;
+			if( arg.byteLength + offset > t.byteLength )
+				throw "set() outside of range";
+			for( i in 0...arg.byteLength )
+				t[i + offset] = a[i];
+		} else if( Std.is(arg,Array) ) {
+			var a : Array<Int> = arg;
+			if( a.length + offset > t.byteLength )
+				throw "set() outside of range";
+			for( i in 0...a.length )
+				t[i + offset] = a[i];
+		} else
+			throw "TODO";
+	}
+
+	static function _subarray( start : Int, ?end : Int ) {
+		var t : Dynamic = untyped __js__("this");
+		var a = _new(t.slice(start,end));
+		a.byteOffset = start * 8;
+		return a;
+	}
+
+	static function __init__() untyped {
+		var Float64Array = __js__('typeof(window) != "undefined" && window.Float64Array') || (__js__('typeof(global) != "undefined" && global.Float64Array')) || _new;
+	}
+
+}

+ 74 - 0
tests/unit/src/unitstd/haxe/io/Float64Array.unit.hx

@@ -0,0 +1,74 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
+var b = new haxe.io.Float64Array(5);
+b[0] == 0;
+b[4] == 0;
+b.length == 5;
+
+// check float write
+b[1] = 1.25;
+b[1] == 1.25;
+
+// set
+for( i in 0...5 )
+	b[i] = i + 1;
+b[0] == 1;
+b[4] == 5;
+
+// access outside bounds is unspecified but should not crash
+try b[-1] catch( e : Dynamic ) {};
+try b[5] catch(e : Dynamic) {};
+
+// same for writing
+try b[-1] = 55 catch( e : Dynamic ) {};
+try b[5] = 55 catch(e : Dynamic) {};
+
+var b2 = b.sub(1,3);
+b2[0] == 2;
+b2[2] == 4;
+b2.length == 3;
+
+// check memory sharing
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
+
+// should we allow writing past bounds ?
+try b2[-1] = 0xBB catch( e : Dynamic ) {};
+b[0] == 1;
+
+try b2[3] = 0xBB catch( e : Dynamic ) {};
+b[4] == 5;
+
+
+b.view == b.view; // no alloc
+
+if( !emulated ) b.view.buffer == b2.view.buffer;
+b.view.byteLength == 40;
+b.view.byteOffset == 0;
+b2.view.byteLength == 24;
+b2.view.byteOffset == 8;
+
+// check sub
+var sub = b.sub(1);
+sub.length == b.length - 1;
+sub[0] == (emulated ? 2 : 0xCC);
+sub[0] = 0xDD;
+if( !emulated ) b[1] == 0xDD;
+
+var sub = b.subarray(2,3);
+sub.length == 1;
+sub[0] == 3;
+sub[0] = 0xEE;
+if( !emulated ) b[2] == 0xEE;
+
+// from bytes
+var b3 = haxe.io.Float64Array.fromBytes(b.view.buffer, 2*8, 3);
+b3.length == 3;
+for( i in 0...3 )
+	b3[i] == b[i+2];
+b3[0] = b[3] + 1;
+if( !emulated ) b3[0] == b[2];

+ 79 - 0
tests/unit/src/unitstd/haxe/io/Int32Array.unit.hx

@@ -0,0 +1,79 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
+var b = new haxe.io.Int32Array(5);
+b[0] == 0;
+b[4] == 0;
+b.length == 5;
+
+// check write negative
+b[0] = -2;
+b[0] == -2;
+
+// check write for big int
+b[1] = 65535 * 65534 * 65533;
+b[1] == 720890;
+
+// set
+for( i in 0...5 )
+	b[i] = i + 1;
+b[0] == 1;
+b[4] == 5;
+
+// access outside bounds is unspecified but should not crash
+try b[-1] catch( e : Dynamic ) {};
+try b[5] catch(e : Dynamic) {};
+
+// same for writing
+try b[-1] = 55 catch( e : Dynamic ) {};
+try b[5] = 55 catch(e : Dynamic) {};
+
+var b2 = b.sub(1,3);
+b2[0] == 2;
+b2[2] == 4;
+b2.length == 3;
+
+// check memory sharing
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
+
+// should we allow writing past bounds ?
+try b2[-1] = 0xBB catch( e : Dynamic ) {};
+b[0] == 1;
+
+try b2[3] = 0xBB catch( e : Dynamic ) {};
+b[4] == 5;
+
+b.view == b.view; // no alloc
+
+if( !emulated ) b.view.buffer == b2.view.buffer;
+b.view.byteLength == 20;
+b.view.byteOffset == 0;
+b2.view.byteLength == 12;
+b2.view.byteOffset == 4;
+
+
+// check sub
+var sub = b.sub(1);
+sub.length == b.length - 1;
+sub[0] == (emulated ? 2 : 0xCC);
+sub[0] = 0xDD;
+if( !emulated ) b[1] == 0xDD;
+
+var sub = b.subarray(2,3);
+sub.length == 1;
+sub[0] == 3;
+sub[0] = 0xEE;
+if( !emulated ) b[2] == 0xEE;
+
+// from bytes
+var b3 = haxe.io.Int32Array.fromBytes(b.view.buffer, 2*4, 3);
+b3.length == 3;
+for( i in 0...3 )
+	b3[i] == b[i+2];
+b3[0] = b3[0] + 1;
+if( !emulated ) b3[0] == b[2];
+

+ 81 - 0
tests/unit/src/unitstd/haxe/io/UInt16Array.unit.hx

@@ -0,0 +1,81 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
+var b = new haxe.io.UInt16Array(5);
+b[0] == 0;
+b[4] == 0;
+b.length == 5;
+
+// check write mod 0xFFFF
+b[0] = 123456;
+b[0] == 57920;
+b[0] = -2;
+b[0] == 65534;
+
+// check write for big int
+b[1] = 65535 * 65534 * 65533;
+b[1] == 65530;
+
+// set
+for( i in 0...5 )
+	b[i] = i + 1;
+b[0] == 1;
+b[4] == 5;
+
+// access outside bounds is unspecified but should not crash
+try b[-1] catch( e : Dynamic ) {};
+try b[5] catch(e : Dynamic) {};
+
+// same for writing
+try b[-1] = 55 catch( e : Dynamic ) {};
+try b[5] = 55 catch(e : Dynamic) {};
+
+var b2 = b.sub(1,3);
+b2[0] == 2;
+b2[2] == 4;
+b2.length == 3;
+
+// check memory sharing
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
+
+// should we allow writing past bounds ?
+try b2[-1] = 0xBB catch( e : Dynamic ) {};
+b[0] == 1;
+
+try b2[3] = 0xBB catch( e : Dynamic ) {};
+b[4] == 5;
+
+b.view == b.view; // no alloc
+
+if( !emulated ) b.view.buffer == b2.view.buffer;
+b.view.byteLength == 10;
+b.view.byteOffset == 0;
+b2.view.byteLength == 6;
+b2.view.byteOffset == 2;
+
+
+// check sub
+var sub = b.sub(1);
+sub.length == b.length - 1;
+sub[0] == (emulated ? 2 : 0xCC);
+sub[0] = 0xDD;
+if( !emulated ) b[1] == 0xDD;
+
+var sub = b.subarray(2,3);
+sub.length == 1;
+sub[0] == 3;
+sub[0] = 0xEE;
+if( !emulated ) b[2] == 0xEE;
+
+// from bytes
+var b3 = haxe.io.UInt16Array.fromBytes(b.view.buffer, 2*2, 3);
+b3.length == 3;
+for( i in 0...3 )
+	b3[i] == b[i+2];
+b3[0] = b3[0] + 1;
+if( !emulated ) b3[0] == b[2];
+

+ 79 - 0
tests/unit/src/unitstd/haxe/io/UInt32Array.unit.hx

@@ -0,0 +1,79 @@
+
+var emulated = haxe.io.ArrayBufferView.EMULATED;
+
+var b = new haxe.io.UInt32Array(5);
+b[0] == 0;
+b[4] == 0;
+b.length == 5;
+
+// check write negative
+b[0] = -2;
+(b[0] : Float) == 4294967294.;
+
+// check write for big int
+b[1] = 65535 * 65534 * 65533;
+b[1] == 720890;
+
+// set
+for( i in 0...5 )
+	b[i] = i + 1;
+b[0] == 1;
+b[4] == 5;
+
+// access outside bounds is unspecified but should not crash
+try b[-1] catch( e : Dynamic ) {};
+try b[5] catch(e : Dynamic) {};
+
+// same for writing
+try b[-1] = 55 catch( e : Dynamic ) {};
+try b[5] = 55 catch(e : Dynamic) {};
+
+var b2 = b.sub(1,3);
+b2[0] == 2;
+b2[2] == 4;
+b2.length == 3;
+
+// check memory sharing
+if( !emulated ) {
+	b2[0] = 0xCC;
+	b2[0] == 0xCC;
+	b[1] == 0xCC;
+}
+
+// should we allow writing past bounds ?
+try b2[-1] = 0xBB catch( e : Dynamic ) {};
+b[0] == 1;
+
+try b2[3] = 0xBB catch( e : Dynamic ) {};
+b[4] == 5;
+
+b.view == b.view; // no alloc
+
+if( !emulated ) b.view.buffer == b2.view.buffer;
+b.view.byteLength == 20;
+b.view.byteOffset == 0;
+b2.view.byteLength == 12;
+b2.view.byteOffset == 4;
+
+
+// check sub
+var sub = b.sub(1);
+sub.length == b.length - 1;
+sub[0] == (emulated ? 2 : 0xCC);
+sub[0] = 0xDD;
+if( !emulated ) b[1] == 0xDD;
+
+var sub = b.subarray(2,3);
+sub.length == 1;
+sub[0] == 3;
+sub[0] = 0xEE;
+if( !emulated ) b[2] == 0xEE;
+
+// from bytes
+var b3 = haxe.io.UInt32Array.fromBytes(b.view.buffer, 2*4, 3);
+b3.length == 3;
+for( i in 0...3 )
+	b3[i] == b[i+2];
+b3[0] = b3[0] + 1;
+if( !emulated ) b3[0] == b[2];
+

+ 0 - 0
tests/unit/src/unitstd/haxe/io/Uint8Array.unit.hx → tests/unit/src/unitstd/haxe/io/UInt8Array.unit.hx