summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-getAllColumnOffsets.js
blob: 05b032397ef18840a891d8a242a9df67859fbd86 (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
// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled()

// Tests that wasm module scripts have column and line to bytecode offset
// information when source text is generated.

load(libdir + "asserts.js");

// Checking if experimental format generates internal source map to binary file
// by querying debugger scripts getAllColumnOffsets.
function getAllOffsets(wast) {
  var sandbox = newGlobal({newCompartment: true});
  var dbg = new Debugger();
  dbg.addDebuggee(sandbox);
  dbg.allowWasmBinarySource = true;
  sandbox.eval(`
    var wasm = wasmTextToBinary('${wast}');
    var m = new WebAssembly.Instance(new WebAssembly.Module(wasm));
  `);
  var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
  return wasmScript.getAllColumnOffsets();
}

var offsets1 = getAllOffsets('(module \
  (func (nop)) \
  (func (drop (f32.sqrt (f32.add (f32.const 1.0) (f32.const 2.0))))) \
)');

// There shall be total 5 lines with single and unique offset per line.
var usedOffsets = Object.create(null),
    usedLines = Object.create(null);
assertEq(offsets1.length, 5);

offsets1.forEach(({offset, lineNumber, columnNumber}) => {
  assertEq(offset > 0, true);
  assertEq(lineNumber > 0, true);
  assertEq(columnNumber > 0, true);
  usedOffsets[offset] = true;
  usedLines[lineNumber] = true;
});
assertEq(Object.keys(usedOffsets).length, 5);
assertEq(Object.keys(usedLines).length, 5);