tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sab.js (768B)


      1 const 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, opts) => {
     10    if (type === "ArrayBuffer") {
     11      return new ArrayBuffer(length, opts);
     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, opts);
     17    } else {
     18      throw new Error("type has to be ArrayBuffer or SharedArrayBuffer");
     19    }
     20  }
     21 })();