summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/wasm-sourceMappingURL.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/debug/wasm-sourceMappingURL.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
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.js72
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');