Bug 1466118 part 2 - Replace releaseAssertSameCompartment with JSContext::releaseCheck. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 21 Aug 2018 12:07:57 +0200
changeset 831041 5cb4cd7c449ecef9226496dc736d7c7325d37473
parent 831040 3bf5eb6fe16d1fa91924edc63da909f1b96d1307
child 831042 224b09c2e661110abc9d29c7cca417cb5de5d3b4
push id118868
push userbmo:zjz@zjz.name
push dateFri, 24 Aug 2018 07:04:39 +0000
reviewersluke
bugs1466118
milestone63.0a1
Bug 1466118 part 2 - Replace releaseAssertSameCompartment with JSContext::releaseCheck. r=luke
js/src/vm/HelperThreads.cpp
js/src/vm/JSContext-inl.h
js/src/vm/JSContext.h
js/src/vm/JSScript.cpp
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -1660,17 +1660,17 @@ GlobalHelperThreadState::finishParseTask
         return false;
     }
 
     mergeParseTaskRealm(cx, parseTask.get().get(), cx->realm());
 
     bool ok = finishCallback(parseTask.get().get());
 
     for (auto& script : parseTask->scripts)
-        releaseAssertSameCompartment(cx, script);
+        cx->releaseCheck(script);
 
     if (!parseTask->finish(cx) || !ok)
         return false;
 
     // Report out of memory errors eagerly, or errors could be malformed.
     if (parseTask->outOfMemory) {
         ReportOutOfMemory(cx);
         return false;
--- a/js/src/vm/JSContext-inl.h
+++ b/js/src/vm/JSContext-inl.h
@@ -194,22 +194,26 @@ assertSameCompartmentImpl(JSContext* cx,
 template <class... Args> inline void
 assertSameCompartment(JSContext* cx, const Args&... args)
 {
 #ifdef JS_CRASH_DIAGNOSTICS
     assertSameCompartmentImpl(cx, 1, args...);
 #endif
 }
 
+} // namespace js
+
 template <class... Args> inline void
-releaseAssertSameCompartment(JSContext* cx, const Args&... args)
+JSContext::releaseCheck(const Args&... args)
 {
-    assertSameCompartmentImpl(cx, 1, args...);
+    assertSameCompartmentImpl(this, 0, args...);
 }
 
+namespace js {
+
 template <class... Args> inline void
 assertSameCompartmentDebugOnly(JSContext* cx, const Args&... args)
 {
 #if defined(DEBUG) && defined(JS_CRASH_DIAGNOSTICS)
     assertSameCompartmentImpl(cx, 1, args...);
 #endif
 }
 
--- a/js/src/vm/JSContext.h
+++ b/js/src/vm/JSContext.h
@@ -949,16 +949,18 @@ struct JSContext : public JS::RootingCon
     js::ThreadData<JSPromiseRejectionTrackerCallback> promiseRejectionTrackerCallback;
     js::ThreadData<void*> promiseRejectionTrackerCallbackData;
 
     JSObject* getIncumbentGlobal(JSContext* cx);
     bool enqueuePromiseJob(JSContext* cx, js::HandleFunction job, js::HandleObject promise,
                            js::HandleObject incumbentGlobal);
     void addUnhandledRejectedPromise(JSContext* cx, js::HandleObject promise);
     void removeUnhandledRejectedPromise(JSContext* cx, js::HandleObject promise);
+
+    template <class... Args> inline void releaseCheck(const Args&... args);
 }; /* struct JSContext */
 
 inline JS::Result<>
 JSContext::boolToResult(bool ok)
 {
     if (MOZ_LIKELY(ok)) {
         MOZ_ASSERT(!isExceptionPending());
         MOZ_ASSERT(!isPropagatingForcedReturn());
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -1381,17 +1381,17 @@ ScriptSourceObject::create(JSContext* cx
 
     return sourceObject;
 }
 
 /* static */ bool
 ScriptSourceObject::initFromOptions(JSContext* cx, HandleScriptSourceObject source,
                                     const ReadOnlyCompileOptions& options)
 {
-    releaseAssertSameCompartment(cx, source);
+    cx->releaseCheck(source);
     MOZ_ASSERT(source->getReservedSlot(ELEMENT_SLOT).isMagic(JS_GENERIC_MAGIC));
     MOZ_ASSERT(source->getReservedSlot(ELEMENT_PROPERTY_SLOT).isMagic(JS_GENERIC_MAGIC));
     MOZ_ASSERT(source->getReservedSlot(INTRODUCTION_SCRIPT_SLOT).isMagic(JS_GENERIC_MAGIC));
 
     RootedObject element(cx, options.element());
     RootedString elementAttributeName(cx, options.elementAttributeName());
     if (!initElementProperties(cx, source, element, elementAttributeName))
         return false;