Skip to content

Instantly share code, notes, and snippets.

@MrTelanie
Created October 19, 2019 21:13
Show Gist options
  • Select an option

  • Save MrTelanie/1ca027780afe27d293f9716578f7ab52 to your computer and use it in GitHub Desktop.

Select an option

Save MrTelanie/1ca027780afe27d293f9716578f7ab52 to your computer and use it in GitHub Desktop.
const ORG_SHARED = Symbol('org shared');
const checkOrg = (array, one) => {
if (one instanceof SharedArrayBuffer) {
array[ORG_SHARED] = one;
}
};
class MyInt8Array extends Int8Array {
constructor(one, two, three) {
super(one, two, three);
if (one instanceof SharedArrayBuffer) {
this[ORG_SHARED] = one;
}
}
get org () {
return this[ORG_SHARED];
}
}
class MyInt16Array extends Int16Array {
constructor(one, two, three) {
super(one, two, three);
checkOrg(this, one);
}
get org () {
return this[ORG_SHARED];
}
}
class MyInt32Array extends Int32Array {
constructor(one, two, three) {
super(one, two, three);
checkOrg(this, one);
}
get org () {
return this[ORG_SHARED];
}
}
class MyUint8Array extends Uint8Array {
constructor(one, two, three) {
super(one, two, three);
checkOrg(this, one);
}
get org () {
return this[ORG_SHARED];
}
}
export function init (window) {
window.ArrayBuffer = SharedArrayBuffer;
window.Int8Array = MyInt8Array;
window.Int16Array = MyInt16Array;
window.Int32Array = MyInt32Array;
window.Uint8Array = MyUint8Array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment