Bug 1254893 - Tests for perfunctory functionality of wasm Debugger.Scripts and Debugger.Sources. (r=jimb)
authorShu-yu Guo <shu@rfrn.org>
Fri, 11 Mar 2016 21:43:21 -0800
changeset 288414 3300390349c66d11ca89c7862c165b8f241933f0
parent 288413 eb0831a7ef134c51f64bcee7bf5a18b4078d8fd4
child 288415 9ac34b44f27662f5a574b85bf9f4234c4f22f8ba
push id30079
push userryanvm@gmail.com
push dateSat, 12 Mar 2016 20:24:19 +0000
treeherdermozilla-central@d1d47ba19ce9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1254893
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1254893 - Tests for perfunctory functionality of wasm Debugger.Scripts and Debugger.Sources. (r=jimb)
js/src/jit-test/tests/debug/wasm-01.js
js/src/jit-test/tests/debug/wasm-02.js
js/src/jit-test/tests/debug/wasm-03.js
js/src/jit-test/tests/debug/wasm-04.js
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/wasm-01.js
@@ -0,0 +1,33 @@
+// Tests that wasm module scripts are available via findScripts.
+
+if (!wasmIsSupported())
+  quit();
+
+var g = newGlobal();
+g.eval(`o = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "" 0))'));`);
+
+function isWasm(script) { return script.format === "wasm"; }
+
+var dbg = new Debugger(g);
+var foundScripts1 = dbg.findScripts().filter(isWasm);
+assertEq(foundScripts1.length, 1);
+var found = foundScripts1[0];
+
+// Add another module, we should be able to find it via findScripts.
+g.eval(`o2 = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "a" 0))'));`);
+var foundScripts2 = dbg.findScripts().filter(isWasm);
+assertEq(foundScripts2.length, 2);
+
+// The first module should be in the list as wrapping the same wasm module
+// twice gets the same Debugger.Script.
+assertEq(foundScripts2.indexOf(found) !== -1, true);
+
+// The two modules are distinct.
+assertEq(foundScripts2[0] !== foundScripts2[1], true);
+
+// We should be able to find the same script via its source.
+for (var ws of foundScripts2) {
+  var scriptsFromSource = dbg.findScripts({ source: ws.source });
+  assertEq(scriptsFromSource.length, 1);
+  assertEq(scriptsFromSource[0], ws);
+}
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/wasm-02.js
@@ -0,0 +1,22 @@
+// Tests that wasm module scripts are available via onNewScript.
+
+if (!wasmIsSupported())
+  quit();
+
+var g = newGlobal();
+var dbg = new Debugger(g);
+
+var gotScript;
+dbg.onNewScript = (script) => {
+  gotScript = script;
+}
+
+g.eval(`o = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "" 0))'));`);
+assertEq(gotScript.format, "wasm");
+
+var gotScript2 = gotScript;
+g.eval(`o = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "a" 0))'));`);
+assertEq(gotScript.format, "wasm");
+
+// The two wasm Debugger.Scripts are distinct.
+assertEq(gotScript !== gotScript2, true);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/wasm-03.js
@@ -0,0 +1,40 @@
+// Tests that wasm module scripts have synthesized sources.
+
+load(libdir + "asserts.js");
+
+if (!wasmIsSupported())
+  quit();
+
+var g = newGlobal();
+var dbg = new Debugger(g);
+
+var s;
+dbg.onNewScript = (script) => {
+  s = script;
+}
+
+g.eval(`o = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "" 0))'));`);
+assertEq(s.format, "wasm");
+
+var source = s.source;
+
+assertEq(s.source, source);
+assertEq(source.introductionType, "wasm");
+assertEq(source.introductionScript, s);
+// Wasm sources shouldn't be considered source mapped.
+assertEq(!source.sourceMapURL, true);
+assertThrowsInstanceOf(() => source.sourceMapURL = 'foo', Error);
+// We must have some text.
+assertEq(!!source.text, true);
+
+// TODOshu: Wasm is moving very fast and what we return for these values is
+// currently not interesting to test. Instead, test that they do not throw.
+source.url;
+source.element;
+source.displayURL;
+source.introductionOffset;
+source.elementAttributeName;
+
+// canonicalId doesn't make sense since wasm sources aren't backed by
+// ScriptSource.
+assertThrowsInstanceOf(() => source.canonicalId, Error);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/wasm-04.js
@@ -0,0 +1,35 @@
+// Tests that wasm module scripts throw for everything except text.
+
+load(libdir + "asserts.js");
+
+if (!wasmIsSupported())
+  quit();
+
+var g = newGlobal();
+var dbg = new Debugger(g);
+
+var s;
+dbg.onNewScript = (script) => {
+  s = script;
+}
+
+g.eval(`o = Wasm.instantiateModule(wasmTextToBinary('(module (func) (export "" 0))'));`);
+assertEq(s.format, "wasm");
+
+assertThrowsInstanceOf(() => s.displayName, Error);
+assertThrowsInstanceOf(() => s.url, Error);
+assertThrowsInstanceOf(() => s.startLine, Error);
+assertThrowsInstanceOf(() => s.lineCount, Error);
+assertThrowsInstanceOf(() => s.sourceStart, Error);
+assertThrowsInstanceOf(() => s.sourceLength, Error);
+assertThrowsInstanceOf(() => s.global, Error);
+assertThrowsInstanceOf(() => s.getChildScripts(), Error);
+assertThrowsInstanceOf(() => s.getAllOffsets(), Error);
+assertThrowsInstanceOf(() => s.getAllColumnOffsets(), Error);
+assertThrowsInstanceOf(() => s.getLineOffsets(0), Error);
+assertThrowsInstanceOf(() => s.setBreakpoint(0, { hit: () => {} }), Error);
+assertThrowsInstanceOf(() => s.getBreakpoint(0), Error);
+assertThrowsInstanceOf(() => s.clearBreakpoint({}), Error);
+assertThrowsInstanceOf(() => s.clearAllBreakpoints(), Error);
+assertThrowsInstanceOf(() => s.isInCatchScope(0), Error);
+assertThrowsInstanceOf(() => s.getOffsetsCoverage(), Error);