Bug 1330491 - Always provide wasm bytecode for debuggable instance. r?luke draft
authorYury Delendik <ydelendik@mozilla.com>
Thu, 12 Jan 2017 10:16:41 -0600
changeset 460656 efb689173ba83f5077ada37b31da447f3fa956c4
parent 460618 91f5293e9a89056565493ed5073c3842b0ee9fdc
child 542099 43a7d8a661aa55716575b0d3c1b325be3e7d4778
push id41446
push userydelendik@mozilla.com
push dateFri, 13 Jan 2017 14:00:34 +0000
reviewersluke
bugs1330491
milestone53.0a1
Bug 1330491 - Always provide wasm bytecode for debuggable instance. r?luke MozReview-Commit-ID: 4QTn0giN0wb
js/src/jit-test/tests/debug/bug1330491.js
js/src/wasm/WasmModule.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/bug1330491.js
@@ -0,0 +1,21 @@
+// |jit-test| test-also-wasm-baseline; error: TestComplete
+
+if (!wasmIsSupported())
+     throw "TestComplete";
+
+(function createShortLivedDebugger() {
+    var g = newGlobal();
+    g.debuggeeGlobal = this;
+    g.eval("(" + function () {
+        dbg = new Debugger(debuggeeGlobal);
+    } + ")();");
+})();
+
+let module = new WebAssembly.Module(wasmTextToBinary('(module (func))'));
+new WebAssembly.Instance(module);
+
+gcslice(1000000);
+
+new WebAssembly.Instance(module);
+
+throw "TestComplete";
\ No newline at end of file
--- a/js/src/wasm/WasmModule.cpp
+++ b/js/src/wasm/WasmModule.cpp
@@ -888,22 +888,26 @@ Module::instantiate(JSContext* cx,
     SharedTableVector tables;
     if (!instantiateTable(cx, &table, &tables))
         return false;
 
     // To support viewing the source of an instance (Instance::createText), the
     // instance must hold onto a ref of the bytecode (keeping it alive). This
     // wastes memory for most users, so we try to only save the source when a
     // developer actually cares: when the compartment is debuggable (which is
-    // true when the web console is open) or a names section is present (since
-    // this going to be stripped for non-developer builds).
+    // true when the web console is open), has code compiled with debug flag
+    // enabled or a names section is present (since this going to be stripped
+    // for non-developer builds).
 
     const ShareableBytes* maybeBytecode = nullptr;
-    if (cx->compartment()->isDebuggee() || !metadata_->funcNames.empty())
+    if (cx->compartment()->isDebuggee() || metadata_->debugEnabled ||
+        !metadata_->funcNames.empty())
+    {
         maybeBytecode = bytecode_.get();
+    }
 
     auto codeSegment = CodeSegment::create(cx, code_, linkData_, *metadata_, memory);
     if (!codeSegment)
         return false;
 
     auto code = cx->make_unique<Code>(Move(codeSegment), *metadata_, maybeBytecode);
     if (!code)
         return false;