Bug 1465081 - Preserve bytecode if there's a module name subsection. r=luke
authorBenjamin Bouvier <benj@benj.me>
Thu, 14 Jun 2018 22:53:11 +0200
changeset 422613 7cd314fe93e3599313c63ebf63029e5f85767fb3
parent 422612 915699f04f0359b1cea589763f429097c5d7adbf
child 422614 63856d422047feeca215129bfc20ed81921de7fb
push id34139
push useraciure@mozilla.com
push dateFri, 15 Jun 2018 09:48:05 +0000
treeherdermozilla-central@dc997a4e045e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1465081
milestone62.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 1465081 - Preserve bytecode if there's a module name subsection. r=luke
js/src/jit-test/tests/wasm/binary.js
js/src/wasm/WasmModule.cpp
--- a/js/src/jit-test/tests/wasm/binary.js
+++ b/js/src/jit-test/tests/wasm/binary.js
@@ -1,14 +1,13 @@
 load(libdir + "wasm-binary.js");
 
 const { extractStackFrameFunction } = WasmHelpers;
 
-const Module = WebAssembly.Module;
-const CompileError = WebAssembly.CompileError;
+const { Module, RuntimeError, CompileError } = WebAssembly;
 
 const magicError = /failed to match magic number/;
 const unknownSection = /expected custom section/;
 
 function sectionError(section) {
     return RegExp(`failed to start ${section} section`);
 }
 
@@ -456,16 +455,25 @@ badNameSec3.body.pop();
 assertWarning(() => wasmEval(moduleWithSections([v2vSigSection, declSec, bodySec, badNameSec3])), nameWarning);
 assertNoWarning(() => wasmEval(moduleWithSections([nameSection([moduleNameSubsection('hi')])])));
 assertWarning(() => wasmEval(moduleWithSections([nameSection([moduleNameSubsection('hi'), moduleNameSubsection('boo')])])), nameWarning);
 // Unknown name subsection
 assertNoWarning(() => wasmEval(moduleWithSections([nameSection([moduleNameSubsection('hi'), [4, 0]])])));
 assertWarning(() => wasmEval(moduleWithSections([nameSection([moduleNameSubsection('hi'), [4, 1]])])), nameWarning);
 assertNoWarning(() => wasmEval(moduleWithSections([nameSection([moduleNameSubsection('hi'), [4, 1, 42]])])));
 
+// Provide a module name but no function names.
+assertErrorMessage(() => wasmEval(moduleWithSections([
+    v2vSigSection,
+    declSection([0]),
+    exportSection([{funcIndex: 0, name: "f"}]),
+    bodySection([funcBody({locals:[], body:[UnreachableCode]})]),
+    nameSection([moduleNameSubsection('hi')])])
+).f(), RuntimeError, /unreachable/);
+
 // Diagnose nonstandard block signature types.
 for (var bad of [0xff, 0, 1, 0x3f])
     assertErrorMessage(() => wasmEval(moduleWithSections([sigSection([v2vSig]), declSection([0]), bodySection([funcBody({locals:[], body:[BlockCode, bad, EndCode]})])])), CompileError, /invalid inline block type/);
 
 // Ensure all invalid opcodes rejected
 for (let i = FirstInvalidOpcode; i <= LastInvalidOpcode; i++) {
     let binary = moduleWithSections([v2vSigSection, declSection([0]), bodySection([funcBody({locals:[], body:[i]})])]);
     assertErrorMessage(() => wasmEval(binary), CompileError, /unrecognized opcode/);
--- a/js/src/wasm/WasmModule.cpp
+++ b/js/src/wasm/WasmModule.cpp
@@ -1264,17 +1264,17 @@ Module::instantiate(JSContext* cx,
     // wastes memory for most users, so we try to only save the source when a
     // developer actually cares: when the realm is debuggable (which is 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->realm()->isDebuggee() || metadata().debugEnabled ||
-        !metadata().funcNames.empty())
+        !metadata().funcNames.empty() || !!metadata().moduleName)
     {
         maybeBytecode = bytecode_.get();
     }
 
     // The debug object must be present even when debugging is not enabled: It
     // provides the lazily created source text for the program, even if that
     // text is a placeholder message when debugging is not enabled.