summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-10.js
blob: 0dc762398001837e688c8baf7477468bd629e43c (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
// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled()
// Tests that wasm module scripts has inspectable locals.

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

function monitorLocalValues(wast, lib, expected) {
    function setupFrame(frame) {
        var locals = {};
        framesLocals.push(locals);
        frame.environment.names().forEach(n => {
            locals[n] = [frame.environment.getVariable(n)];
        });
        frame.onStep = function () {
            frame.environment.names().forEach(n => {
                var prevValues = locals[n];
                if (!prevValues)
                    locals[n] = prevValues = [void 0];
                var value = frame.environment.getVariable(n);
                if (prevValues[prevValues.length - 1] !== value)
                    prevValues.push(value);
            });
        }
    }
    var framesLocals = [];
    wasmRunWithDebugger(wast, lib,
        function ({dbg}) {
            dbg.onEnterFrame = function(frame) {
                if (frame.type == "wasmcall")
                    setupFrame(frame);
            }
        },
        function ({error}) {
            assertEq(error, undefined);
        }
    );
    assertEq(framesLocals.length, expected.length);
    for (var i = 0; i < framesLocals.length; i++) {
        var frameLocals = framesLocals[i];
        var expectedLocals = expected[i];
        var localsNames = Object.keys(frameLocals);
        assertEq(localsNames.length, Object.keys(expectedLocals).length);
        localsNames.forEach(n => {
            assertEqArray(frameLocals[n], expectedLocals[n]);
        });
    }
}

monitorLocalValues(
    '(module (func (nop) (nop)) (export "test" (func 0)))',
    undefined,
    [{}]
);
monitorLocalValues(
    '(module (func (export "test") (local i32) (i32.const 1) (local.set 0)))',
    undefined,
    [{var0: [0, 1]}]
);
monitorLocalValues(
    '(module (func (export "test") (local f32) (f32.const 1.5) (local.set 0)))',
    undefined,
    [{var0: [0, 1.5]}]
);
monitorLocalValues(
    '(module (func (export "test") (local f64) (f64.const 42.25) (local.set 0)))',
    undefined,
    [{var0: [0, 42.25]}]
);
monitorLocalValues(
    `(module
  (func (param i32) (result i32) (local.get 0) (i32.const 2) (i32.add))
  (func (param i32) (local i32) (local.get 0) (call 0) (local.set 1))
  (func (export "test") (i32.const 1) (call 1))
)`.replace(/\n/g, " "),
    undefined,
    [{}, {var0: [1], var1: [0, 3]}, {var0: [1]}]
);