Add a .data pointer on ArrayBuffers for convenience, see #291

This commit is contained in:
dcodeIO
2018-10-03 01:06:48 +02:00
parent b7e7be20cf
commit db0e82fbc3
13 changed files with 89 additions and 31 deletions

View File

@ -9,6 +9,9 @@ export class ArrayBuffer {
readonly byteLength: i32; // capped to [0, MAX_LENGTH]
// @unsafe
get data(): usize { return changetype<usize>(this) + HEADER_SIZE; }
constructor(length: i32, unsafe: bool = false) {
if (<u32>length > <u32>MAX_BLENGTH) throw new RangeError("Invalid array buffer length");
var buffer = allocateUnsafe(length);

View File

@ -372,6 +372,8 @@ declare namespace table {
declare class ArrayBuffer {
/** The size, in bytes, of the array. */
readonly byteLength: i32;
/** Unsafe pointer to the start of the data in memory. */
readonly data: usize;
/** Constructs a new array buffer of the given length in bytes. */
constructor(length: i32, unsafe?: bool);
/** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */