summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/js-promise-integration/multi.js
blob: 7713637642d090eb6f0f0bb8aabd601dc7f70427 (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
// Multiple promises at the same time.

function js_import() {
    return Promise.resolve(42);
}
var wasm_js_import = new WebAssembly.Function(
    { parameters: ['externref'], results: ['i32'] },
    js_import,
    { suspending: 'first' });

var ins = wasmEvalText(`(module
    (import "m" "import" (func $f (param externref) (result i32)))
    (func (export "test") (param externref) (result i32)
      local.get 0
      call $f
    )
)`, {"m": {import: wasm_js_import}});

let wrapped_export = new WebAssembly.Function(
    {
        parameters: [],
        results: ['externref']
    },
    ins.exports.test, { promising: 'first' });

Promise.resolve().then(() => {
    wrapped_export().then(i => {
        assertEq(42, i)
    });
});

Promise.resolve().then(() => {
    wrapped_export().then(i => {
        assertEq(42, i)
    });
});