tor-browser

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

full-cycle.js (3788B)


      1 wasmFullPass(`(module
      2    (func $test (param i32) (param i32) (result i32) (i32.add (local.get 0) (local.get 1)))
      3    (func $run (result i32) (call $test (i32.const 1) (i32.const ${Math.pow(2, 31) - 1})))
      4    (export "run" (func $run))
      5 )`, -Math.pow(2, 31));
      6 
      7 wasmFullPass(`(module
      8    (func (result i32)
      9        i32.const 1
     10        i32.const 42
     11        i32.add
     12        return
     13        unreachable
     14        i32.const 0
     15        call 3
     16        i32.const 42
     17        i32.add
     18    )
     19    (func) (func) (func)
     20 (export "run" (func 0)))`, 43);
     21 
     22 wasmFullPass(`
     23 (module
     24  (import "env" "a" (global $a i32))
     25  (import "env" "b" (func $b (param i32) (result i32)))
     26  (func (export "run") (param $0 i32) (result i32) local.get 0 call $b)
     27 )`, 43, { env: { a: 1337, b: x => x+1 } }, 42);
     28 
     29 // Global section.
     30 wasmFullPass(`(module
     31 (import "globals" "x" (global $imported i32))
     32 (global $mut_local (mut i32) (i32.const 0))
     33 (global $imm_local i32 (i32.const 37))
     34 (global $imm_local_2 i32 (global.get 0))
     35 (func $get (result i32)
     36  i32.const 13
     37  global.set $mut_local
     38  global.get $imported
     39  global.get $mut_local
     40  i32.add
     41  global.get $imm_local
     42  i32.add
     43  global.get $imm_local_2
     44  i32.add
     45 )
     46 (export "run" (func $get))
     47 )`, 13 + 42 + 37 + 42, { globals: {x: 42} });
     48 
     49 // Memory.
     50 wasmFullPass(`(module
     51    (memory (export "memory") 1 2)
     52    (data (i32.const 0) "\\00\\01\\02" "\\03\\04\\05")
     53    (data (i32.const 6) "\\06")
     54    (func (export "run") (result i32)
     55        i32.const 1
     56        i32.load offset=2
     57    )
     58 )`, 0x06050403);
     59 
     60 let memory = new WebAssembly.Memory({ initial: 1, maximum: 2 });
     61 
     62 wasmFullPass(`(module
     63    (memory (import "" "memory") 1 2)
     64    (data (i32.const 0) "\\00\\01\\02\\03\\04\\05")
     65    (func (export "run") (result i32)
     66        i32.const 1
     67        i32.load offset=2
     68    )
     69    (export "mem" (memory 0))
     70 )`, 0x050403, {"": {memory}});
     71 
     72 // Tables.
     73 wasmFullPass(`(module
     74    (table (export "table") 3 funcref)
     75    (type $t (func (result i32)))
     76    (func $foo (result i32) (i32.const 1))
     77    (func $bar (result i32) (i32.const 2))
     78    (func $baz (result i32) (i32.const 3))
     79    (elem (i32.const 0) $baz $bar)
     80    (elem (i32.const 2) $foo)
     81    (func (export "run") (param i32) (result i32)
     82        local.get 0
     83        call_indirect (type $t)
     84    )
     85 )`, 3, {}, 0);
     86 
     87 let table = new WebAssembly.Table({ element: 'anyfunc', initial: 3, maximum: 3 });
     88 
     89 wasmFullPass(`(module
     90    (table (import "" "table") 3 4 funcref)
     91    (type $t (func (result i32)))
     92    (func $foo (result i32) (i32.const 1))
     93    (func $bar (result i32) (i32.const 2))
     94    (func $baz (result i32) (i32.const 3))
     95    (elem (i32.const 0) $baz $bar)
     96    (elem (i32.const 2) $foo)
     97    (func (export "run") (param i32) (result i32)
     98        local.get 0
     99        call_indirect (type $t)
    100    )
    101 )`, 3, {"":{table}}, 0);
    102 
    103 // Start function.
    104 wasmFullPass(`(module
    105    (global $g (mut i32) (i32.const 0))
    106    (func $start
    107        global.get $g
    108        i32.const 1
    109        i32.add
    110        global.set $g
    111    )
    112    (start $start)
    113    (func (export "run") (result i32)
    114        global.get $g
    115    )
    116 )`, 1);
    117 
    118 // Branch table.
    119 for (let [p, result] of [
    120    [0, 7],
    121    [1, 6],
    122    [2, 4],
    123    [42, 4]
    124 ]) {
    125    wasmFullPass(`(module
    126        (func (export "run") (param $p i32) (result i32) (local $n i32)
    127            i32.const 0
    128            local.set $n
    129            block $c block $b block $a
    130                local.get $p
    131                br_table $a $b $c
    132            end $a
    133                local.get $n
    134                i32.const 1
    135                i32.add
    136                local.set $n
    137            end $b
    138                local.get $n
    139                i32.const 2
    140                i32.add
    141                local.set $n
    142            end $c
    143            local.get $n
    144            i32.const 4
    145            i32.add
    146        )
    147    )`, result, {}, p);
    148 }