summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/bug1858423.js
blob: a90d3089061e4680e5d02fe4d41cf6db174dac4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// |jit-test| --wasm-gc; skip-if: !wasmCachingEnabled() || !wasmGcEnabled()

const code = wasmTextToBinary(`(module
  (type $t (struct (field i32) (field anyref)))
  (type $t2 (struct (field f32) (field externref)))
  (func (export "test") (param externref) (result externref)
    i32.const 42
    f32.const 1.0
    local.get 0
    struct.new $t2
    struct.new $t
    extern.convert_any
  )

  (func (export "check") (param externref) (result externref)
    local.get 0
    any.convert_extern
    ref.cast (ref $t)
    struct.get $t 1
    ref.cast (ref $t2)
    struct.get $t2 1
  )
)`);

function instantiateCached(code, imports) {
  // Cache the code.
  wasmCompileInSeparateProcess(code);
  // Load from cache.
  let m = wasmCompileInSeparateProcess(code);
  assertEq(wasmLoadedFromCache(m), true);
  return new WebAssembly.Instance(m, imports);
}

const {test,check} = instantiateCached(code).exports;
let obj = test({i:1});
gc();
assertEq(check(obj).i, 1);