Implement missing ArrayBuffer methods/properties

This commit is contained in:
Joshua Granick
2019-11-11 14:08:08 -08:00
parent 883ba6260e
commit 4b059c4cbf

View File

@@ -10,9 +10,35 @@ abstract ArrayBuffer(Bytes) from Bytes to Bytes
#if doc_gen from Dynamic to Dynamic
#end
{
public var byteLength(get, never):Int;
private inline function get_byteLength() { return this.length; }
public inline function new(byteLength:Int)
{
this = Bytes.alloc(byteLength);
}
public static inline function isView(arg:Dynamic):Bool
{
return (arg != null && Std.is(arg, ArrayBufferView));
}
public inline function slice(begin:Int, end:Null<Int> = null)
{
if (end == null) end = this.length;
if (begin < 0) begin = 0;
if (end > this.length) end = this.length;
var length = end - begin;
if (begin < 0 || length <= 0)
{
return new ArrayBuffer(0);
}
else
{
var bytes = Bytes.alloc(length);
bytes.blit(0, this, begin, length);
return cast bytes;
}
}
}
#end // !js