Bug 1604747 - Error if attempt at encoding and instantiated module. r=iain
authorcaroline <cullen.caroline@gmail.com>
Fri, 20 Dec 2019 16:38:35 +0000
changeset 508036 d4359a64d30fe311f0d3aff7b0e50e57874a0cd2
parent 508035 0480be98e2a9044ba97ede74b9560d71dca83598
child 508037 bf14c11659add201eab127a3ca3492884220770d
push id36936
push usercbrindusan@mozilla.com
push dateFri, 20 Dec 2019 21:54:48 +0000
treeherdermozilla-central@e94a014eb27e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersiain
bugs1604747
milestone73.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 1604747 - Error if attempt at encoding and instantiated module. r=iain Differential Revision: https://phabricator.services.mozilla.com/D57900
js/src/jit-test/tests/xdr/bug-1604747.js
js/src/shell/js.cpp
js/src/vm/Xdr.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/xdr/bug-1604747.js
@@ -0,0 +1,9 @@
+let og = parseModule("1");
+let bc = codeModule(og);
+let m54 = decodeModule(bc);
+m54.declarationInstantiation();
+
+try {
+    bc = codeModule(m54);
+}
+catch {}
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -4796,16 +4796,21 @@ static bool CodeModule(JSContext* cx, un
 
   if (!args[0].isObject() || !args[0].toObject().is<ModuleObject>()) {
     const char* typeName = InformalValueTypeName(args[0]);
     JS_ReportErrorASCII(cx, "expected module object, got %s", typeName);
     return false;
   }
 
   RootedModuleObject modObject(cx, &args[0].toObject().as<ModuleObject>());
+  if (modObject->status() >= MODULE_STATUS_INSTANTIATING) {
+    JS_ReportErrorASCII(cx, "cannot encode module after instantiation.");
+    return false;
+  }
+
   JS::TranscodeBuffer buf;
   XDREncoder xdrEncoder_(cx, buf);
   XDRResult res = xdrEncoder_.codeModuleObject(&modObject);
   if (res.isErr()) {
     return false;
   }
 
   XDRBufferObject* xdrBuf = XDRBufferObject::create(cx, &buf);
--- a/js/src/vm/Xdr.cpp
+++ b/js/src/vm/Xdr.cpp
@@ -223,16 +223,18 @@ static XDRResult VersionCheck(XDRState<m
 template <XDRMode mode>
 XDRResult XDRState<mode>::codeModuleObject(MutableHandleModuleObject modp) {
 #ifdef DEBUG
   auto sanityCheck = mozilla::MakeScopeExit(
       [&] { MOZ_ASSERT(validateResultCode(cx(), resultCode())); });
 #endif
   if (mode == XDR_DECODE) {
     modp.set(nullptr);
+  } else {
+    MOZ_ASSERT(modp->status() < MODULE_STATUS_INSTANTIATING);
   }
 
   MOZ_TRY(XDRModuleObject(this, modp));
   return Ok();
 }
 
 template <XDRMode mode>
 static XDRResult XDRAtomCount(XDRState<mode>* xdr, uint32_t* atomCount) {