tor-browser

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

browser_webconsole_wasm_errors.js (1572B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that WASM errors are reported to the console.
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>Wasm errors`;
      9 
     10 add_task(async function () {
     11  const hud = await openNewTabAndConsole(TEST_URI);
     12 
     13  const onCompileError = waitForMessageByType(
     14    hud,
     15    `Uncaught (in promise) CompileError: wasm validation error: at offset 0: failed to match magic number`,
     16    ".error"
     17  );
     18  execute(hud, `WebAssembly.instantiate(new Uint8Array())`);
     19  await onCompileError;
     20  ok(true, "The expected error message is displayed for CompileError");
     21 
     22  const onLinkError = waitForMessageByType(
     23    hud,
     24    `Uncaught (in promise) LinkError: import object field 'f' is not a Function`,
     25    ".error"
     26  );
     27  execute(
     28    hud,
     29    `WebAssembly.instantiate(
     30      new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,2,7,1,1,109,1,102,0,0]),
     31      { m: { f: 3 } }
     32    )`
     33  );
     34  await onLinkError;
     35  ok(true, "The expected error message is displayed for LinkError");
     36 
     37  const onRuntimeError = waitForMessageByType(
     38    hud,
     39    "Uncaught RuntimeError: unreachable executed",
     40    ".error"
     41  );
     42  execute(
     43    hud,
     44    `
     45    const uintArray = new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,7,7,1,3,114,117,110,0,0,10,5,1,3,0,0,11]);
     46    const module = new WebAssembly.Module(uintArray);
     47    new WebAssembly.Instance(module).exports.run()`
     48  );
     49  await onRuntimeError;
     50  ok(true, "The expected error message is displayed for RuntimeError");
     51 });