1const createBuffer = (() => { 2 // See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()` 3 let sabConstructor; 4 try { 5 sabConstructor = new WebAssembly.Memory({ shared:true, initial:0, maximum:0 }).buffer.constructor; 6 } catch(e) { 7 sabConstructor = null; 8 } 9 return (type, length) => { 10 if (type === "ArrayBuffer") { 11 return new ArrayBuffer(length); 12 } else if (type === "SharedArrayBuffer") { 13 if (sabConstructor && sabConstructor.name !== "SharedArrayBuffer") { 14 throw new Error("WebAssembly.Memory does not support shared:true"); 15 } 16 return new sabConstructor(length); 17 } else { 18 throw new Error("type has to be ArrayBuffer or SharedArrayBuffer"); 19 } 20 } 21})(); 22