summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-jseval.js
blob: 9b23d9ac6cdf2ff0351bdf249568a48f6d5e0a15 (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
// |jit-test| skip-if: !wasmDebuggingEnabled()
// Tests that JS can be evaluated on wasm module scripts frames.

load(libdir + "wasm.js");

wasmRunWithDebugger(
    '(module (memory 1 1)\
     (global (mut f64) (f64.const 0.5))\
     (global f32 (f32.const 3.5))\
     (func (param i32) (local f64) \
       nop \
       f64.const 1.0 \
       local.tee 1 \
       global.set 0 \
       nop) \
     (export "test" (func 0))\
     (data (i32.const 0) "Abc\\x2A"))',
    undefined,
    function ({dbg}) {
        dbg.onEnterFrame = function (frame) {
            if (frame.type != 'wasmcall') return;

            var memoryContent = frame.eval('new DataView(memory0.buffer).getUint8(3)').return;
            assertEq(memoryContent, 42, 'valid memory content is expected (0x2A)');

            var global1AndParamSum = frame.eval('global1 + var0').return;
            assertEq(global1AndParamSum, 3.5);

            var stepNumber = 0;
            frame.onStep = function () {
                switch (stepNumber) {
                  case 0: // before nop
                    assertEq(frame.offset, 65);
                    assertEq(frame.eval('global0').return, 0.5);
                    assertEq(frame.eval('var1').return, 0.0);
                    break;
                  case 2: // after local.tee $var1
                    assertEq(frame.offset, 79);
                    assertEq(frame.eval('var1').return, 1.0);
                    break;
                  case 3: // after global.set $global0
                    assertEq(frame.offset, 80);
                    assertEq(frame.eval('global0').return, 1.0);
                    break;
                }
                stepNumber++;
            };
        };
  },
  function ({error}) {
      assertEq(error, undefined);
  }
);