| 1 |
// |jit-test| skip-if: !wasmLazyTieringEnabled() |
| 2 |
|
| 3 |
// This test can only succeed if we are running in lazy-tiering mode, because |
| 4 |
// it requires module compilation to hold on to the bytecode -- in this test, |
| 5 |
// so that we can subsequently disassemble the module using `wasmModuleToText`. |
| 6 |
// And that only happens in lazy tiering mode. See comments on |
| 7 |
// CodeMetadata::codeSectionBytecode. |
| 8 |
|
| 9 |
const m1 = new WebAssembly.Module(wasmTextToBinary(`(module |
| 10 |
(type (struct)) |
| 11 |
(type $f (func)) |
| 12 |
(type (func (param i32 i64) (result i32))) |
| 13 |
(type (array (mut i8))) |
| 14 |
(type $s (sub (struct))) |
| 15 |
(type (sub final (struct (field i32)))) |
| 16 |
(type (sub final $s (struct (field i32)))) |
| 17 |
(type (array (mut i8))) |
| 18 |
(rec |
| 19 |
(type (struct (field i8) (field (mut i16)) (field (mut i32)))) |
| 20 |
(type (array (mut i8))) |
| 21 |
) |
| 22 |
(type (struct (field anyref))) |
| 23 |
(type (struct (field (ref any)))) |
| 24 |
(type (struct (field (ref null none)))) |
| 25 |
(type (struct (field (ref 3)))) |
| 26 |
(type (struct (field (ref null 3)))) |
| 27 |
|
| 28 |
(import "foo" "bar" (func (type $f))) |
| 29 |
(import "foo" "💇🏻♂️" (func (param i32) (result anyref))) |
| 30 |
(import "foo" "\\"big cheese\\"" (func (type $f))) |
| 31 |
|
| 32 |
(import "foo" "table32" (table i32 1 2 funcref)) |
| 33 |
(import "foo" "table64" (table i64 1 funcref)) |
| 34 |
|
| 35 |
(import "foo" "memory32" (memory 1 2)) |
| 36 |
(import "foo" "memory64" (memory i64 1)) |
| 37 |
|
| 38 |
(import "foo" "globalStruct" (global (mut structref))) |
| 39 |
(import "foo" "globalI64" (global i64)) |
| 40 |
|
| 41 |
(import "foo" "tag1" (tag)) |
| 42 |
(import "foo" "tag2" (tag (param i32 i64))) |
| 43 |
|
| 44 |
(memory 1 2) |
| 45 |
(memory (export "memory") i64 1) |
| 46 |
|
| 47 |
(table $tab 10 100 funcref) |
| 48 |
(table (export "table") i64 10 anyref (ref.i31 (i32.const 123))) |
| 49 |
(table 10 funcref (ref.null $f)) |
| 50 |
(table 10 funcref (ref.null func)) |
| 51 |
|
| 52 |
(global (ref eq) (struct.new $s)) |
| 53 |
(global (export "global") (mut i32) (i32.const 0)) |
| 54 |
(global i32 i32.const 2 i32.const 1 i32.sub) |
| 55 |
(global (ref i31) (ref.i31 (i32.const 123))) |
| 56 |
|
| 57 |
(tag) |
| 58 |
(tag (export "tag") (param i32)) |
| 59 |
|
| 60 |
(export "foo" (table 2)) |
| 61 |
|
| 62 |
(start 0) |
| 63 |
|
| 64 |
(elem func 1 0 1 0) |
| 65 |
(elem (ref func) (ref.func 1) (ref.func 0) (ref.func 1) (ref.func 0)) |
| 66 |
(elem (ref func) (ref.func 1)) |
| 67 |
(elem anyref (ref.i31 (i32.const 123)) (ref.null any)) |
| 68 |
(elem (table $tab) (offset i32.const 0) func 1 0 1 0) |
| 69 |
(elem (table $tab) (offset i32.const 0) funcref (ref.func 1)) |
| 70 |
(elem (table $tab) (offset (i32.add (i32.const 2) (i32.const 3))) func 1 0 1 0) |
| 71 |
(elem (table $tab) (offset (i32.add (i32.const 2) (i32.const 3))) funcref (ref.func 1) (ref.func 0)) |
| 72 |
(elem (table $tab) (offset i32.const 2) funcref (ref.func 1) (ref.func 0)) |
| 73 |
(elem declare funcref (ref.func 0)) |
| 74 |
(elem declare funcref (ref.func 1) (ref.func 0)) |
| 75 |
(elem (table $tab) (offset (i32.add (i32.const 2) (i32.const 3))) funcref (ref.func 1)) |
| 76 |
|
| 77 |
(func unreachable) |
| 78 |
(func (export "😎") (param i32 i32) (result i64) |
| 79 |
(local i32) |
| 80 |
|
| 81 |
local.get 0 |
| 82 |
local.get 1 |
| 83 |
i32.add |
| 84 |
local.set 2 |
| 85 |
|
| 86 |
local.get 2 |
| 87 |
i64.extend_i32_u |
| 88 |
) |
| 89 |
(func (param i32 i32 i32 i32 i32 i32 i32 i32 i32)) |
| 90 |
(func |
| 91 |
(local i32 i64) |
| 92 |
|
| 93 |
(if (i32.const 0) |
| 94 |
(then unreachable) |
| 95 |
(else unreachable) |
| 96 |
) |
| 97 |
) |
| 98 |
|
| 99 |
(data "asdfasdf") |
| 100 |
(data (memory 0) (offset i32.const 0) "asdfasdf") |
| 101 |
(data (memory 1) (offset i64.const 0) "asdfasdf\\00") |
| 102 |
(data (memory 0) (offset (i32.add (i32.const 2) (i32.const 3))) "asdfasdf") |
| 103 |
(data "The \\"big cheese\\" needs...\\nhis cut. 💇🏻♂️") |
| 104 |
)`)); |
| 105 |
const t1 = wasmModuleToText(m1); |
| 106 |
print(t1); |
| 107 |
|
| 108 |
const m2 = new WebAssembly.Module(wasmTextToBinary(t1)); |
| 109 |
const t2 = wasmModuleToText(m2); |
| 110 |
assertEq(t1, t2); |
| 111 |
|
| 112 |
const imports = { |
| 113 |
"foo": { |
| 114 |
"bar": () => {}, |
| 115 |
"💇🏻♂️": () => {}, |
| 116 |
"\"big cheese\"": () => {}, |
| 117 |
|
| 118 |
"table32": new WebAssembly.Table({ element: "anyfunc", initial: 1, maximum: 2 }), |
| 119 |
"table64": new WebAssembly.Table({ element: "anyfunc", address: "i64", initial: 1n }), |
| 120 |
|
| 121 |
"memory32": new WebAssembly.Memory({ initial: 1, maximum: 2 }), |
| 122 |
"memory64": new WebAssembly.Memory({ address: "i64", initial: 1n }), |
| 123 |
|
| 124 |
"globalStruct": new WebAssembly.Global({ value: "structref", mutable: true }), |
| 125 |
"globalI64": new WebAssembly.Global({ value: "i64" }), |
| 126 |
|
| 127 |
"tag1": new WebAssembly.Tag({ parameters: [] }), |
| 128 |
"tag2": new WebAssembly.Tag({ parameters: ["i32", "i64"] }), |
| 129 |
}, |
| 130 |
}; |
| 131 |
|
| 132 |
const { "😎": test1 } = new WebAssembly.Instance(m1, imports).exports; |
| 133 |
const { "😎": test2 } = new WebAssembly.Instance(m2, imports).exports; |
| 134 |
|
| 135 |
assertEq(test1(2, 3), 5n); |
| 136 |
assertEq(test2(2, 3), 5n); |