summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-14.js
blob: b47b540d724ac89c7bbd1f1950cd647c03f7b790 (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; test-also=--setpref=wasm_gc=true; skip-if: !wasmDebuggingEnabled() || !wasmGcEnabled(); skip-if: true
// An extension of wasm-10.js, testing that wasm GC objects are inspectable in locals.

// As of bug 1825098, this test is disabled. (skip-if: true)
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1836320

load(libdir + "wasm.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);
    for (const n of localsNames) {
      const actualValues = frameLocals[n];
      const expectedValues = expectedLocals[n];
      for (let j = 0; j < expectedValues.length; j++) {
        const actual = actualValues[j];
        const expected = expectedValues[j];
        if (expected === null) {
          assertEq(actual, null, `values differed at index ${j}`);
        } else {
          for (const key of Object.keys(expected)) {
            const actualField = actual.getProperty(key).return;
            const expectedField = expected[key];
            assertEq(actualField, expectedField, `values differed for key "${key}"`);
          }
        }
      }
    }
  }
}

monitorLocalValues(
  `(module
  (type (struct i32 i64))
  (func (export "test")
    (local (ref null 0))
    (local.set 0 (struct.new 0 (i32.const 1) (i64.const 2)))
  )
)`,
  undefined,
  [{var0: [null, {0: 1, 1: 2n}]}]
);
monitorLocalValues(
  `(module
  (type (array i32))
  (func (export "test")
    (local (ref null 0))
    (i64.const 3)
    (local.set 0 (array.new 0 (i32.const 123) (i32.const 2)))
    drop
  )
)`,
  undefined,
  [{var0: [null, {length: 2, 0: 123, 1: 123}]}]
);