Bug 1330491 - Always provide wasm bytecode for debuggable instance. r?luke
MozReview-Commit-ID: 4QTn0giN0wb
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;