Bug 1335489 - Fixes Debugger.Script lineCount getter behavior. r=luke
authorYury Delendik <ydelendik@mozilla.com>
Tue, 31 Jan 2017 12:55:32 -0600
changeset 331985 a8643fc321642ee3b4ceff2ea4b99508a5437560
parent 331984 8f1c7cbbbdde668b8f0fc4369acab4017d8a0961
child 331986 d70a7e18fe84dbe3e35f282def60544897ce04dc
push id31293
push userkwierso@gmail.com
push dateThu, 02 Feb 2017 00:07:12 +0000
treeherdermozilla-central@8196774c6b8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1335489
milestone54.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 1335489 - Fixes Debugger.Script lineCount getter behavior. r=luke MozReview-Commit-ID: FO0ko60XNPF
js/src/jit-test/tests/debug/wasm-05.js
js/src/jit-test/tests/debug/wasm-09.js
js/src/vm/Debugger.cpp
js/src/wasm/WasmCode.cpp
--- a/js/src/jit-test/tests/debug/wasm-05.js
+++ b/js/src/jit-test/tests/debug/wasm-05.js
@@ -52,16 +52,18 @@ for (let descriptor of WebAssembly.Modul
     imports[descriptor.module] = {}
     switch(descriptor.kind) {
         case "function": imports[descriptor.module][descriptor.name] = new Function(''); break;
     }
 }
 var instance = new WebAssembly.Instance(module, imports);
 `);
     var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
+    assertEq(wasmScript.startLine, 1);
+    assertEq(wasmScript.lineCount > 0, true);
     var lines = wasmScript.source.text.split('\n');
     var offsetsFound = 0;
     lines.forEach(function (l, n) {
         var offsets = wasmScript.getLineOffsets(n + 1);
         if (offsets.length < 1) return;
         assertEq(offsets.length, 1);
         assertEq(offsets[0] > 0, true);
         offsetsFound++;
@@ -97,15 +99,17 @@ function getWasmScriptAfterDebuggerAttac
     // Attaching after wasm instance is created.
     dbg.addDebuggee(sandbox);
     var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
     return wasmScript;
 }
 
 var wasmScript1 = getWasmScriptAfterDebuggerAttached('(module (func (nop)))');
 var wasmLines1 = wasmScript1.source.text.split('\n');
+assertEq(wasmScript1.startLine, 1);
+assertEq(wasmScript1.lineCount, 0);
 assertEq(wasmLines1.every((l, n) => wasmScript1.getLineOffsets(n + 1).length == 0), true);
 
 // Checking that we must not resolve any location for any offset in a wasm
 // instance which debug mode was not enabled.
 var wasmScript2 = getWasmScriptAfterDebuggerAttached('(module (func (nop)))');
 for (var i = wasmTextToBinary('(module (func (nop)))').length - 1; i >= 0; i--)
     assertThrowsInstanceOf(() => wasmScript2.getOffsetLocation(i), Error);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/wasm-09.js
@@ -0,0 +1,35 @@
+// |jit-test| test-also-wasm-baseline
+// Tests debugEnabled state of wasm when allowUnobservedAsmJS == true.
+
+load(libdir + "asserts.js");
+
+if (!wasmIsSupported())
+     quit();
+
+// Checking that there are no offsets are present in a wasm instance script for
+// which debug mode was not enabled.
+function getWasmScriptWithoutAllowUnobservedAsmJS(wast) {
+    var sandbox = newGlobal('');
+    var dbg = new Debugger();
+    dbg.allowUnobservedAsmJS = true;
+    dbg.addDebuggee(sandbox);
+    sandbox.eval(`
+        var wasm = wasmTextToBinary('${wast}');
+        var m = new WebAssembly.Instance(new WebAssembly.Module(wasm));
+    `);
+    // Attaching after wasm instance is created.
+    var wasmScript = dbg.findScripts().filter(s => s.format == 'wasm')[0];
+    return wasmScript;
+}
+
+var wasmScript1 = getWasmScriptWithoutAllowUnobservedAsmJS('(module (func (nop)))');
+var wasmLines1 = wasmScript1.source.text.split('\n');
+assertEq(wasmScript1.startLine, 1);
+assertEq(wasmScript1.lineCount, 0);
+assertEq(wasmLines1.every((l, n) => wasmScript1.getLineOffsets(n + 1).length == 0), true);
+
+// Checking that we must not resolve any location for any offset in a wasm
+// instance which debug mode was not enabled.
+var wasmScript2 = getWasmScriptWithoutAllowUnobservedAsmJS('(module (func (nop)))');
+for (var i = wasmTextToBinary('(module (func (nop)))').length - 1; i >= 0; i--)
+    assertThrowsInstanceOf(() => wasmScript2.getOffsetLocation(i), Error);
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -5672,17 +5672,17 @@ struct DebuggerScriptGetLineCountMatcher
     using ReturnType = bool;
 
     ReturnType match(HandleScript script) {
         totalLines = double(GetScriptLineExtent(script));
         return true;
     }
     ReturnType match(Handle<WasmInstanceObject*> wasmInstance) {
         uint32_t result;
-        if (wasmInstance->instance().code().totalSourceLines(cx_, &result))
+        if (!wasmInstance->instance().code().totalSourceLines(cx_, &result))
             return false;
         totalLines = double(result);
         return true;
     }
 };
 
 static bool
 DebuggerScript_getLineCount(JSContext* cx, unsigned argc, Value* vp)
--- a/js/src/wasm/WasmCode.cpp
+++ b/js/src/wasm/WasmCode.cpp
@@ -859,22 +859,24 @@ Code::getOffsetLocation(JSContext* cx, u
     *lineno = loc.lineno + experimentalWarningLinesCount;
     *column = loc.column;
     return true;
 }
 
 bool
 Code::totalSourceLines(JSContext* cx, uint32_t* count)
 {
+    *count = 0;
+    if (!metadata_->debugEnabled)
+        return true;
+
     if (!ensureSourceMap(cx))
         return false;
 
-    if (!maybeSourceMap_)
-        *count = 0;
-    else
+    if (maybeSourceMap_)
         *count = maybeSourceMap_->totalLines() + experimentalWarningLinesCount;
     return true;
 }
 
 bool
 Code::stepModeEnabled(uint32_t funcIndex) const
 {
     return stepModeCounters_.initialized() && stepModeCounters_.lookup(funcIndex);