Debian Codegraph @

js/src/jit-test/tests/debug/wasm-binary-sources.js

raw
1 // |jit-test| skip-if: !wasmDebuggingEnabled()
2
3 // Tests that wasm module scripts have access to binary sources.
4
5 load(libdir + "asserts.js");
6 load(libdir + "array-compare.js");
7
8 var g = newGlobal({newCompartment: true});
9 var dbg = new Debugger(g);
10
11 var s;
12 dbg.onNewScript = (script) => {
13 s = script;
14 }
15
16 g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
17 assertEq(s.format, "wasm");
18
19 var source = s.source;
20
21 // The text is never generated with the native Debugger API.
22 assertEq(source.text.includes('module'), false);
23
24 g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary('(module (func) (export "" (func 0)))')));`);
25 assertEq(s.format, "wasm");
26
27 var source2 = s.source;
28
29 // The text is predefined if wasm binary sources are enabled.
30 assertEq(source2.text, '[debugger missing wasm binary-to-text conversion]');
31 // The binary contains Uint8Array which is equal to wasm bytecode;
32 arraysEqual(source2.binary, wasmTextToBinary('(module (func) (export "" (func 0)))'));