tor-browser

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

wasm-caching.js (1116B)


      1 const {Module, Instance, compileStreaming, RuntimeError} = WebAssembly;
      2 
      3 function testCached(code, imports, test) {
      4    if (typeof code === 'string')
      5        code = wasmTextToBinary(code);
      6 
      7    let success = false;
      8    let cache = streamCacheEntry(code);
      9    assertEq(cache.cached, false);
     10    compileStreaming(cache)
     11    .then(m => {
     12         test(new Instance(m, imports));
     13         if (!wasmTestSerializationEnabled()) {
     14             assertEq(wasmLoadedFromCache(m), false);
     15         }
     16         while (!wasmHasTier2CompilationCompleted(m)) {
     17            sleep(1);
     18         }
     19         assertEq(cache.cached, true);
     20         return compileStreaming(cache);
     21     })
     22     .then(m => {
     23         test(new Instance(m, imports));
     24         assertEq(wasmLoadedFromCache(m), true);
     25         assertEq(cache.cached, true);
     26 
     27         let m2 = wasmCompileInSeparateProcess(code);
     28         test(new Instance(m2, imports));
     29         assertEq(wasmLoadedFromCache(m2), true);
     30 
     31         success = true;
     32     })
     33     .catch(err => { print(String(err) + " at:\n" + err.stack) });
     34 
     35     drainJobQueue();
     36     assertEq(success, true);
     37 }