summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-15.js
blob: c2af3bdc17db819d567ff3655654c9050cd479e3 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled() || !wasmTailCallsEnabled()

// Tests that wasm module scripts raises onEnterFrame and onLeaveFrame events in
// wasm return calls.

load(libdir + "wasm.js");

// Checking if enter/leave frame at return_call.
var onEnterFrameCalled, onLeaveFrameCalled, onStepCalled;
wasmRunWithDebugger(
    '(module (func) (func (return_call 0)) (func (call 1)) (export "test" (func 2)))',
    undefined,
    function ({dbg}) {
        onEnterFrameCalled = 0;
        onLeaveFrameCalled = 0;
        onStepCalled = [];
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;
            onEnterFrameCalled++;
            frame.onStep = function () {
                onStepCalled.push(frame.offset);
            };
            frame.onPop = function () {
                onLeaveFrameCalled++;
            };
        };
  },
  function ({error}) {
      assertEq(error, undefined);
      assertEq(onEnterFrameCalled, 3);
      assertEq(onLeaveFrameCalled, 3);
      assertEq(onStepCalled.length, 4);
      assertEq(onStepCalled[0] > 0, true);
  }
);

// Checking if enter/leave frame at return_call_indirect.
wasmRunWithDebugger(
    '(module (func) (func (return_call_indirect (i32.const 0))) (func (call 1)) (table 1 1 funcref) (elem (i32.const 0) 0) (export "test" (func 2)))',
    undefined,
    function ({dbg}) {
        onEnterFrameCalled = 0;
        onLeaveFrameCalled = 0;
        onStepCalled = [];
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;
            onEnterFrameCalled++;
            frame.onStep = function () {
                onStepCalled.push(frame.offset);
            };
            frame.onPop = function () {
                onLeaveFrameCalled++;
            };
        };
  },
  function ({error}) {
      assertEq(error, undefined);
      assertEq(onEnterFrameCalled, 3);
      assertEq(onLeaveFrameCalled, 3);
      assertEq(onStepCalled.length, 4);
      assertEq(onStepCalled[0] > 0, true);
  }
);

// Checking if enter/leave frame at return_call_ref.
wasmGcEnabled() && wasmRunWithDebugger(
    '(module (type $t (func)) (elem declare func 0) (func) (func (return_call_ref $t (ref.func 0))) (func (call 1)) (export "test" (func 2)))',
    undefined,
    function ({dbg}) {
        onEnterFrameCalled = 0;
        onLeaveFrameCalled = 0;
        onStepCalled = [];
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;
            onEnterFrameCalled++;
            frame.onStep = function () {
                onStepCalled.push(frame.offset);
            };
            frame.onPop = function () {
                onLeaveFrameCalled++;
            };
        };
  },
  function ({error}) {
      assertEq(error, undefined);
      assertEq(onEnterFrameCalled, 3);
      assertEq(onLeaveFrameCalled, 3);
      assertEq(onStepCalled.length, 5);
      assertEq(onStepCalled[0] > 0, true);
  }
);