| 1 |
// |jit-test| skip-if: !wasmCachingEnabled() |
| 2 |
|
| 3 |
load(libdir + "wasm-caching.js"); |
| 4 |
load(libdir + "wasm-binary.js"); |
| 5 |
|
| 6 |
testCached(`(module |
| 7 |
(func $test (param i64) (result f64) |
| 8 |
local.get 0 |
| 9 |
f64.convert_i64_u |
| 10 |
) |
| 11 |
(func (export "run") (result i32) |
| 12 |
i64.const 1 |
| 13 |
call $test |
| 14 |
f64.const 1 |
| 15 |
f64.eq |
| 16 |
) |
| 17 |
)`, |
| 18 |
undefined, |
| 19 |
i => { assertEq(i.exports.run(), 1); } |
| 20 |
); |
| 21 |
|
| 22 |
testCached( |
| 23 |
`(module |
| 24 |
(type $long-serialized-type (func (param |
| 25 |
i64 i32 f64 f32 i64 i32 f64 f32 i64 i32 f64 f32 i64 i32 f64 f32))) |
| 26 |
(func (export "run") (result i32) |
| 27 |
(i32.const 42)))`, |
| 28 |
undefined, |
| 29 |
i => { assertEq(i.exports.run(), 42); } |
| 30 |
); |
| 31 |
|
| 32 |
testCached( |
| 33 |
`(module |
| 34 |
(type $T (func (result i32))) |
| 35 |
(func $t1 (import "" "t1") (type $T)) |
| 36 |
(func $t2 (import "" "t2") (type $T)) |
| 37 |
(func $t3 (type $T) (i32.const 30)) |
| 38 |
(func $t4 (type $T) (i32.const 40)) |
| 39 |
(table funcref (elem $t1 $t2 $t3 $t4)) |
| 40 |
(func (export "run") (param i32) (result i32) |
| 41 |
(call_indirect (type $T) (local.get 0))))`, |
| 42 |
{'':{ t1() { return 10 }, t2() { return 20 } }}, |
| 43 |
i => { |
| 44 |
assertEq(i.exports.run(0), 10); |
| 45 |
assertEq(i.exports.run(1), 20); |
| 46 |
assertEq(i.exports.run(2), 30); |
| 47 |
assertEq(i.exports.run(3), 40); |
| 48 |
} |
| 49 |
); |
| 50 |
|
| 51 |
testCached( |
| 52 |
moduleWithSections([ |
| 53 |
sigSection([{args:[], ret:VoidCode}]), |
| 54 |
declSection([0]), |
| 55 |
exportSection([{funcIndex:0, name:"run"}]), |
| 56 |
bodySection([funcBody({locals:[], body:[UnreachableCode]})]), |
| 57 |
nameSection([funcNameSubsection([{name:"wee"}])]) |
| 58 |
]), |
| 59 |
undefined, |
| 60 |
i => assertErrorMessage(() => i.exports.run(), RuntimeError, /unreachable/) |
| 61 |
); |
| 62 |
|
| 63 |
// Note: a fuller behavioral test of caching is in bench/wasm_box2d.js. |