summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-get-return.js
blob: 233d8cf5da9dfb534990c31165f6b965a0ade1d3 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled()
// Tests that wasm frame opPop event can access function resumption value.

load(libdir + "wasm.js");
load(libdir + 'eqArrayHelper.js');

function monitorFrameOnPopReturns(wast, expected) {
    var values = [];
    wasmRunWithDebugger(
        wast,
        undefined,
        function ({dbg}) {
            dbg.onEnterFrame = function (frame) {
                if (frame.type != 'wasmcall') return;
                frame.onPop = function (value) {
                    values.push(value.return);
                };
            };
        },
        function ({error}) {
            assertEq(error, undefined);
        }
    );
    assertEqArray(values, expected);
}

monitorFrameOnPopReturns(
  `(module (func (export "test")))`,
  [undefined]);
monitorFrameOnPopReturns(
  `(module (func (export "test") (result i32) (i32.const 42)))`,
  [42]);
monitorFrameOnPopReturns(
  `(module (func (export "test") (result f32) (f32.const 0.5)))`,
  [0.5]);
monitorFrameOnPopReturns(
  `(module (func (export "test") (result f64) (f64.const -42.75)))`,
  [-42.75]);
monitorFrameOnPopReturns(
  `(module (func (result i64) (i64.const 2)) (func (export "test") (call 0) (drop)))`,
  [2, undefined]);

// Checking if throwing frame has right resumption value.
var throwCount = 0;
wasmRunWithDebugger(
    '(module (func (unreachable)) (func (export "test") (result i32) (call 0) (i32.const 1)))',
    undefined,
    function ({dbg, g}) {
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;
            frame.onPop = function (value) {
                if ('throw' in value)
                    throwCount++;
            };
        };
    },
    function ({error}) {
        assertEq(error != undefined, true);
        assertEq(throwCount, 2);
    }
);