tor-browser

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

utf8.js (1315B)


      1 /*
      2 (module
      3 (func (param i32) (result i32)
      4       (i32.add (local.get 0) (local.get 0)))
      5 (export "hello" (func 0)))
      6 */
      7 
      8 var txt =
      9 `00 61 73 6d 01 00 00 00 01 06 01 60 01 7f 01 7f
     10 03 02 01 00 07 09 01 05 68 65 6c 6c 6f 00 00 0a
     11 09 01 07 00 20 00 20 00 6a 0b`
     12 
     13 var bin = new Uint8Array(txt.split(" ").map((x) => parseInt(x, 16)));
     14 var mod = new WebAssembly.Module(bin);
     15 var ins = new WebAssembly.Instance(mod);
     16 
     17 assertEq(ins.exports.hello(37), 2*37);
     18 
     19 assertEq(bin[25], 0x65);	// the 'e' in 'hello'
     20 bin[25] = 0x85;			// bad UTF-8
     21 
     22 assertEq(WebAssembly.validate(bin), false);
     23 
     24 assertThrowsInstanceOf(() => new WebAssembly.Module(bin), WebAssembly.CompileError);
     25 
     26 assertThrowsInstanceOf(() => wasmEvalText(`(module (import "\u2603" "" (func))) `, {}), TypeError);
     27 
     28 {
     29    let i1 = wasmEvalText(` (module (func (export "\u2603")))`);
     30    assertThrowsInstanceOf(() => wasmEvalText(`(module (import "" "\u2603" (func (result i32))))`,
     31                                              { "": { "\u2603": i1.exports['\u2603'] } }),
     32                           WebAssembly.LinkError);
     33    assertThrowsInstanceOf(() => wasmEvalText(`(module (import "\u2603" "" (func (result i32))))`,
     34                                              { "\u2603": { "": i1.exports['\u2603'] } }),
     35                           WebAssembly.LinkError);
     36 }