Skip to content

Implement portable variants of TypedArray.wrap #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ under the licensing terms detailed in LICENSE:
* Vladimir Tikhonov <[email protected]>
* Duncan Uszkay <[email protected]>
* Surma <[email protected]>
* Julien Letellier <[email protected]>

Portions of this software are derived from third-party works licensed under
the following terms:
Expand Down
45 changes: 45 additions & 0 deletions std/portable/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,48 @@ declare function unmanaged(constructor: Function): void;

/** Environmental tracing function. */
declare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;

declare interface Int8ArrayConstructor {
/** Equivalent to calling `new Int8Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int8Array;
}

declare interface Uint8ArrayConstructor {
/** Equivalent to calling `new Uint8Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8Array;
}

declare interface Uint8ClampedArrayConstructor {
/** Equivalent to calling `new Uint8ClampedArray` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint8ClampedArray;
}

declare interface Int16ArrayConstructor {
/** Equivalent to calling `new Int16Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int16Array;
}

declare interface Uint16ArrayConstructor {
/** Equivalent to calling `new Uint16Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint16Array;
}

declare interface Int32ArrayConstructor {
/** Equivalent to calling `new Int32Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Int32Array;
}

declare interface Uint32ArrayConstructor {
/** Equivalent to calling `new Uint32Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Uint32Array;
}

declare interface Float32ArrayConstructor {
/** Equivalent to calling `new Float32Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float32Array;
}

declare interface Float64ArrayConstructor {
/** Equivalent to calling `new Float64Array` with multiple arguments. */
wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): Float64Array;
}
54 changes: 54 additions & 0 deletions std/portable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,57 @@ globalScope["trace"] = function(message, n) {
if (n) message += Array.prototype.slice.call(arguments, 2, 2 + n);
console.error("trace: " + message);
};

Object.defineProperty(Int8Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Int8Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Uint8Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Uint8Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Uint8ClampedArray, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Uint8ClampedArray(buffer, byteOffset, length);
}
});

Object.defineProperty(Int16Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Int16Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Uint16Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Uint16Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Int32Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Int32Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Uint32Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Uint32Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Float32Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Float32Array(buffer, byteOffset, length);
}
});

Object.defineProperty(Float64Array, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new Float64Array(buffer, byteOffset, length);
}
});