mirror of
https://github.com/servo/servo.git
synced 2025-10-15 16:00:28 +01:00
13 lines
519 B
JavaScript
13 lines
519 B
JavaScript
const createBuffer = (() => {
|
|
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
|
|
const sabConstructor = new WebAssembly.Memory({ shared:true, initial:0, maximum:0 }).buffer.constructor;
|
|
return (type, length) => {
|
|
if (type === "ArrayBuffer") {
|
|
return new ArrayBuffer(length);
|
|
} else if (type === "SharedArrayBuffer") {
|
|
return new sabConstructor(length);
|
|
} else {
|
|
throw new Error("type has to be ArrayBuffer or SharedArrayBuffer");
|
|
}
|
|
}
|
|
})();
|