diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/debug/wasm-sourceMappingURL.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/debug/wasm-sourceMappingURL.js')
-rw-r--r-- | js/src/jit-test/tests/debug/wasm-sourceMappingURL.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/wasm-sourceMappingURL.js b/js/src/jit-test/tests/debug/wasm-sourceMappingURL.js new file mode 100644 index 0000000000..7f7f245faf --- /dev/null +++ b/js/src/jit-test/tests/debug/wasm-sourceMappingURL.js @@ -0,0 +1,72 @@ +// |jit-test| test-also=--wasm-compiler=optimizing; skip-if: !wasmDebuggingEnabled() + +// Tests that wasm module sourceMappingURL section is parsed. + +load(libdir + "asserts.js"); +load(libdir + "wasm-binary.js"); + +var g = newGlobal({newCompartment: true}); +var dbg = new Debugger(g); + +var gotScript; +dbg.allowWasmBinarySource = true; +dbg.onNewScript = (script) => { + gotScript = script; +} + +function toU8(array) { + for (let b of array) + assertEq(b < 256, true); + return Uint8Array.from(array); +} + +function varU32(u32) { + assertEq(u32 >= 0, true); + assertEq(u32 < Math.pow(2,32), true); + var bytes = []; + do { + var byte = u32 & 0x7f; + u32 >>>= 7; + if (u32 != 0) + byte |= 0x80; + bytes.push(byte); + } while (u32 != 0); + return bytes; +} + +function string(name) { + var nameBytes = name.split('').map(c => { + var code = c.charCodeAt(0); + assertEq(code < 128, true); // TODO + return code; + }); + return varU32(nameBytes.length).concat(nameBytes); +} + +function appendSourceMappingURL(wasmBytes, url) { + if (!url) + return wasmBytes; + var payload = [...string('sourceMappingURL'), ...string(url)]; + return Uint8Array.from([...wasmBytes, userDefinedId, payload.length, ...payload]); +} +g.toWasm = (wast, url) => appendSourceMappingURL(wasmTextToBinary(wast), url); + +// The sourceMappingURL section is not present +g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "" (func 0)))')));`); +assertEq(gotScript.format, "wasm"); +assertEq(gotScript.source.sourceMapURL, null); + +// The sourceMappingURL section is present +g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" (func 0)))', 'http://example.org/test')));`); +assertEq(gotScript.format, "wasm"); +assertEq(gotScript.source.sourceMapURL, 'http://example.org/test'); + +// The sourceMapURL is read-only for wasm +assertThrowsInstanceOf(() => gotScript.source.sourceMapURL = 'foo', Error); + +// The sourceMappingURL section is present, and is still available when wasm +// binary source is disabled. +dbg.allowWasmBinarySource = false; +g.eval(`o = new WebAssembly.Instance(new WebAssembly.Module(toWasm('(module (func) (export "a" (func 0)))', 'http://example.org/test2')));`); +assertEq(gotScript.format, "wasm"); +assertEq(gotScript.source.sourceMapURL, 'http://example.org/test2'); |