From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- .../jit-test/tests/debug/wasm-sourceMappingURL.js | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 js/src/jit-test/tests/debug/wasm-sourceMappingURL.js (limited to 'js/src/jit-test/tests/debug/wasm-sourceMappingURL.js') 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'); -- cgit v1.2.3