Skip to content

fix(portable): avoid duplicated adding wrap function #1949

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

Closed
wants to merge 1 commit into from
Closed
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
72 changes: 20 additions & 52 deletions std/portable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,56 +375,24 @@ globalScope["trace"] = function(message, 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);
var wrapTypes = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
];

for(const type of wrapTypes) {
if(!type.wrap) {
Object.defineProperty(type, "wrap", {
value: function wrap(buffer, byteOffset, length) {
return new type(buffer, byteOffset, length);
}
});
}
});
}