Bug 1154923 - Add a version of assertSameCompartment that works in all versions. r=terrence
authorAndrew McCreight <continuation@gmail.com>
Mon, 27 Jun 2016 16:06:30 +0200
changeset 381515 88213a36d165b095738bfff456433f74760f33fa
parent 381514 7b0517746549ee534f6e8021c2d87b6672a2acfa
child 381516 118345cddce056e901a7107b25b04bfc696ce5e6
push id21504
push userbmo:npang@mozilla.com
push dateMon, 27 Jun 2016 18:10:09 +0000
reviewersterrence
bugs1154923
milestone50.0a1
Bug 1154923 - Add a version of assertSameCompartment that works in all versions. r=terrence Use it in initFromOptions and finishParseTask.
js/src/jscntxtinlines.h
js/src/jsscript.cpp
js/src/vm/HelperThreads.cpp
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -16,17 +16,16 @@
 #include "jit/JitFrames.h"
 #include "vm/HelperThreads.h"
 #include "vm/Interpreter.h"
 #include "vm/ProxyObject.h"
 #include "vm/Symbol.h"
 
 namespace js {
 
-#ifdef JS_CRASH_DIAGNOSTICS
 class CompartmentChecker
 {
     JSCompartment* compartment;
 
   public:
     explicit CompartmentChecker(ExclusiveContext* cx)
       : compartment(cx->compartment())
     {
@@ -130,28 +129,34 @@ class CompartmentChecker
         check(desc.object());
         if (desc.hasGetterObject())
             check(desc.getterObject());
         if (desc.hasSetterObject())
             check(desc.setterObject());
         check(desc.value());
     }
 };
-#endif /* JS_CRASH_DIAGNOSTICS */
 
 /*
  * Don't perform these checks when called from a finalizer. The checking
  * depends on other objects not having been swept yet.
  */
 #define START_ASSERT_SAME_COMPARTMENT()                                       \
     if (cx->isJSContext() && cx->asJSContext()->runtime()->isHeapBusy())      \
         return;                                                               \
     CompartmentChecker c(cx)
 
 template <class T1> inline void
+releaseAssertSameCompartment(ExclusiveContext* cx, const T1& t1)
+{
+    START_ASSERT_SAME_COMPARTMENT();
+    c.check(t1);
+}
+
+template <class T1> inline void
 assertSameCompartment(ExclusiveContext* cx, const T1& t1)
 {
 #ifdef JS_CRASH_DIAGNOSTICS
     START_ASSERT_SAME_COMPARTMENT();
     c.check(t1);
 #endif
 }
 
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1679,17 +1679,17 @@ ScriptSourceObject::create(ExclusiveCont
 
     return sourceObject;
 }
 
 /* static */ bool
 ScriptSourceObject::initFromOptions(JSContext* cx, HandleScriptSource source,
                                     const ReadOnlyCompileOptions& options)
 {
-    assertSameCompartment(cx, source);
+    releaseAssertSameCompartment(cx, 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));
 
     RootedValue element(cx, ObjectOrNullValue(options.element()));
     if (!cx->compartment()->wrap(cx, &element))
         return false;
     source->setReservedSlot(ELEMENT_SLOT, element);
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -1166,17 +1166,17 @@ GlobalHelperThreadState::finishParseTask
     }
 
     mergeParseTaskCompartment(rt, parseTask, global, cx->compartment());
 
     if (!parseTask->finish(cx))
         return nullptr;
 
     RootedScript script(rt, parseTask->script);
-    assertSameCompartment(cx, script);
+    releaseAssertSameCompartment(cx, script);
 
     // Report out of memory errors eagerly, or errors could be malformed.
     if (parseTask->outOfMemory) {
         ReportOutOfMemory(cx);
         return nullptr;
     }
 
     // Report any error or warnings generated during the parse, and inform the