tor-browser

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

source-phase-js-string.tentative.html (886B)


      1 <!DOCTYPE html>
      2 <title>Testing import of WebAssembly source phase with js-string builtins</title>
      3 
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script type=module>
      7 setup({ single_test: true });
      8 
      9 import source module from "./resources/js-string-module.wasm";
     10 
     11 const instance = await WebAssembly.instantiate(module, {
     12  "wasm:js-string": {
     13    // Example builtin polyfill for function returning the number of uppercase letters
     14    newbuiltin: (str) => {
     15      if (typeof str !== "string") return 0;
     16      return (str.match(/[A-Z]/g) || []).length;
     17    }
     18  }
     19 });
     20 
     21 assert_equals(instance.exports.useBuiltins("hello"), 5);
     22 assert_equals(instance.exports.useBuiltins(123), -1);
     23 
     24 assert_equals(instance.exports.concatStrings("Hello", " World"));
     25 
     26 assert_equals(instance.exports.useNewBuiltin("Hello World"), 2);
     27 
     28 done();
     29 </script>