Bug 1477921 part 2 - Remove now unused JSAutoRealmAllowCCW. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 29 Aug 2018 10:23:49 +0200
changeset 491699 a7eeb1ba63b4aaffe98c42ef6228be40af3949b8
parent 491698 9dc02964e87ff7141a091d77201728dffa96d5d2
child 491700 a6e752d996557df8cd1782c52751edde538bb9ab
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1477921
milestone63.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 1477921 part 2 - Remove now unused JSAutoRealmAllowCCW. r=luke Differential Revision: https://phabricator.services.mozilla.com/D4519
js/rust/build.rs
js/rust/src/ar.rs
js/rust/src/rust.rs
js/src/devtools/rootAnalysis/annotations.js
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/rust/build.rs
+++ b/js/rust/build.rs
@@ -165,17 +165,17 @@ const WHITELIST_TYPES: &'static [&'stati
     "JS::Handle",
     "JS::HandleFunction",
     "JS::HandleId",
     "JS::HandleObject",
     "JS::HandleString",
     "JS::HandleValue",
     "JS::HandleValueArray",
     "JS::IsAcceptableThis",
-    "JSAutoRealmAllowCCW",
+    "JSAutoRealm",
     "JSAutoStructuredCloneBuffer",
     "JSClass",
     "JSClassOps",
     "JSContext",
     "JSErrNum",
     "JSErrorCallback",
     "JSErrorFormatString",
     "JSErrorReport",
--- a/js/rust/src/ar.rs
+++ b/js/rust/src/ar.rs
@@ -1,56 +1,56 @@
 use jsapi::root::*;
 #[cfg(feature = "debugmozjs")]
 use std::ptr;
 
 #[derive(Debug)]
-pub struct AutoRealm(JSAutoRealmAllowCCW);
+pub struct AutoRealm(JSAutoRealm);
 
 impl AutoRealm {
     #[cfg(feature = "debugmozjs")]
     pub unsafe fn with_obj(cx: *mut JSContext,
                            target: *mut JSObject)
                            -> AutoRealm
     {
         let mut notifier = mozilla::detail::GuardObjectNotifier {
             mStatementDone: ptr::null_mut(),
         };
 
         AutoRealm(
-            JSAutoRealmAllowCCW::new(
+            JSAutoRealm::new(
                 cx,
                 target,
                 &mut notifier as *mut _))
     }
 
     #[cfg(not(feature = "debugmozjs"))]
     pub unsafe fn with_obj(cx: *mut JSContext,
                            target: *mut JSObject)
                            -> AutoRealm
     {
-        AutoRealm(JSAutoRealmAllowCCW::new(cx, target))
+        AutoRealm(JSAutoRealm::new(cx, target))
     }
 
     #[cfg(feature = "debugmozjs")]
     pub unsafe fn with_script(cx: *mut JSContext,
                               target: *mut JSScript)
                               -> AutoRealm
     {
         let mut notifier = mozilla::detail::GuardObjectNotifier {
             mStatementDone: ptr::null_mut(),
         };
 
         AutoRealm(
-            JSAutoRealmAllowCCW::new1(
+            JSAutoRealm::new1(
                 cx,
                 target,
                 &mut notifier as *mut _))
     }
 
     #[cfg(not(feature = "debugmozjs"))]
     pub unsafe fn with_script(cx: *mut JSContext,
                               target: *mut JSScript)
                               -> AutoRealm
     {
-        AutoRealm(JSAutoRealmAllowCCW::new1(cx, target))
+        AutoRealm(JSAutoRealm::new1(cx, target))
     }
 }
--- a/js/rust/src/rust.rs
+++ b/js/rust/src/rust.rs
@@ -615,17 +615,17 @@ impl GCMethods for JS::Value {
     unsafe fn post_barrier(v: *mut JS::Value, prev: JS::Value, next: JS::Value) {
         JS::HeapValuePostBarrier(v, &prev, &next);
     }
 }
 
 // ___________________________________________________________________________
 // Implementations for various things in jsapi.rs
 
-impl Drop for JSAutoRealmAllowCCW {
+impl Drop for JSAutoRealm {
     fn drop(&mut self) {
         unsafe { JS::LeaveRealm(self.cx_, self.oldRealm_); }
     }
 }
 
 impl JSJitMethodCallArgs {
     #[inline]
     pub fn get(&self, i: u32) -> JS::HandleValue {
--- a/js/src/devtools/rootAnalysis/annotations.js
+++ b/js/src/devtools/rootAnalysis/annotations.js
@@ -193,21 +193,16 @@ var ignoreFunctions = {
     "NS_LogCtor": true,
     "NS_LogDtor": true,
     "NS_LogCOMPtrAddRef": true,
     "NS_LogCOMPtrRelease": true,
 
     // FIXME!
     "NS_DebugBreak": true,
 
-    // These are a little overzealous -- these destructors *can* GC if they end
-    // up wrapping a pending exception. See bug 898815 for the heavyweight fix.
-    "void js::AutoRealm::~AutoRealm(int32)" : true,
-    "void JSAutoRealmAllowCCW::~JSAutoRealmAllowCCW(int32)" : true,
-
     // Similar to heap snapshot mock classes, and GTests below. This posts a
     // synchronous runnable when a GTest fails, and we are pretty sure that the
     // particular runnable it posts can't even GC, but the analysis isn't
     // currently smart enough to determine that. In either case, this is (a)
     // only in GTests, and (b) only when the Gtest has already failed. We have
     // static and dynamic checks for no GC in the non-test code, and in the test
     // code we fall back to only the dynamic checks.
     "void test::RingbufferDumper::OnTestPartResult(testing::TestPartResult*)" : true,
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -686,81 +686,71 @@ JS_SetExternalStringSizeofCallback(JSCon
 }
 
 JS_PUBLIC_API(Realm*)
 JS::EnterRealm(JSContext* cx, JSObject* target)
 {
     AssertHeapIsIdle();
     CHECK_REQUEST(cx);
 
+    MOZ_DIAGNOSTIC_ASSERT(!js::IsCrossCompartmentWrapper(target));
+
     Realm* oldRealm = cx->realm();
     cx->enterRealmOf(target);
     return oldRealm;
 }
 
 JS_PUBLIC_API(void)
 JS::LeaveRealm(JSContext* cx, JS::Realm* oldRealm)
 {
     AssertHeapIsIdle();
     CHECK_REQUEST(cx);
     cx->leaveRealm(oldRealm);
 }
 
-JSAutoRealmAllowCCW::JSAutoRealmAllowCCW(JSContext* cx, JSObject* target
-                                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
-  : cx_(cx),
-    oldRealm_(cx->realm())
-{
-    AssertHeapIsIdleOrIterating();
-    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-    cx_->enterRealmOf(target);
-}
-
-JSAutoRealmAllowCCW::JSAutoRealmAllowCCW(JSContext* cx, JSScript* target
-                                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
+JSAutoRealm::JSAutoRealm(JSContext* cx, JSObject* target
+                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
   : cx_(cx),
     oldRealm_(cx->realm())
 {
-    AssertHeapIsIdleOrIterating();
-    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-    cx_->enterRealmOf(target);
-}
-
-JSAutoRealmAllowCCW::~JSAutoRealmAllowCCW()
-{
-    cx_->leaveRealm(oldRealm_);
-}
-
-JSAutoRealm::JSAutoRealm(JSContext* cx, JSObject* target
-                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
-  : JSAutoRealmAllowCCW(cx, target)
-{
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     MOZ_DIAGNOSTIC_ASSERT(!js::IsCrossCompartmentWrapper(target));
+    AssertHeapIsIdleOrIterating();
+    cx_->enterRealmOf(target);
 }
 
 JSAutoRealm::JSAutoRealm(JSContext* cx, JSScript* target
                          MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
-  : JSAutoRealmAllowCCW(cx, target)
+  : cx_(cx),
+    oldRealm_(cx->realm())
 {
     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
+    AssertHeapIsIdleOrIterating();
+    cx_->enterRealmOf(target);
+}
+
+JSAutoRealm::~JSAutoRealm()
+{
+    cx_->leaveRealm(oldRealm_);
 }
 
 JSAutoNullableRealm::JSAutoNullableRealm(JSContext* cx,
                                          JSObject* targetOrNull
                                          MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
   : cx_(cx),
     oldRealm_(cx->realm())
 {
+    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     AssertHeapIsIdleOrIterating();
-    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-    if (targetOrNull)
+    if (targetOrNull) {
+        MOZ_DIAGNOSTIC_ASSERT(!js::IsCrossCompartmentWrapper(targetOrNull));
         cx_->enterRealmOf(targetOrNull);
-    else
+    } else {
         cx_->enterNullRealm();
+    }
 }
 
 JSAutoNullableRealm::~JSAutoNullableRealm()
 {
     cx_->leaveRealm(oldRealm_);
 }
 
 JS_PUBLIC_API(void)
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -853,20 +853,23 @@ JS_RefreshCrossCompartmentWrappers(JSCon
  * The current realm of a context may be changed. The preferred way to do
  * this is with JSAutoRealm:
  *
  *   void foo(JSContext* cx, JSObject* obj) {
  *     // in some realm 'r'
  *     {
  *       JSAutoRealm ar(cx, obj);  // constructor enters
  *       // in the realm of 'obj'
- *     }                                 // destructor leaves
+ *     }                           // destructor leaves
  *     // back in realm 'r'
  *   }
  *
+ * The object passed to JSAutoRealm must *not* be a cross-compartment wrapper,
+ * because CCWs are not associated with a single realm.
+ *
  * For more complicated uses that don't neatly fit in a C++ stack frame, the
  * realm can be entered and left using separate function calls:
  *
  *   void foo(JSContext* cx, JSObject* obj) {
  *     // in 'oldRealm'
  *     JS::Realm* oldRealm = JS::EnterRealm(cx, obj);
  *     // in the realm of 'obj'
  *     JS::LeaveRealm(cx, oldRealm);
@@ -877,37 +880,24 @@ JS_RefreshCrossCompartmentWrappers(JSCon
  * enter/leave calls on the context. Furthermore, only the return value of a
  * JS::EnterRealm call may be passed as the 'oldRealm' argument of
  * the corresponding JS::LeaveRealm call.
  *
  * Entering a realm roots the realm and its global object for the lifetime of
  * the JSAutoRealm.
  */
 
-// JSAutoRealmAllowCCW is deprecated and will be removed soon, because entering
-// the realm of a CCW doesn't make sense when CCWs are shared by all realms in
-// the compartment. New code should prefer JSAutoRealm below instead (it asserts
-// the object is not a CCW).
-class MOZ_RAII JS_PUBLIC_API(JSAutoRealmAllowCCW)
+class MOZ_RAII JS_PUBLIC_API(JSAutoRealm)
 {
     JSContext* cx_;
     JS::Realm* oldRealm_;
   public:
-    JSAutoRealmAllowCCW(JSContext* cx, JSObject* target MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
-    JSAutoRealmAllowCCW(JSContext* cx, JSScript* target MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
-    ~JSAutoRealmAllowCCW();
-
-    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
-};
-
-class MOZ_RAII JS_PUBLIC_API(JSAutoRealm) : public JSAutoRealmAllowCCW
-{
-  public:
     JSAutoRealm(JSContext* cx, JSObject* target MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
     JSAutoRealm(JSContext* cx, JSScript* target MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
+    ~JSAutoRealm();
 
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 class MOZ_RAII JS_PUBLIC_API(JSAutoNullableRealm)
 {
     JSContext* cx_;
     JS::Realm* oldRealm_;
@@ -918,16 +908,19 @@ class MOZ_RAII JS_PUBLIC_API(JSAutoNulla
 
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 namespace JS {
 
 /** NB: This API is infallible; a nullptr return value does not indicate error.
  *
+ * |target| must not be a cross-compartment wrapper because CCWs are not
+ * associated with a single realm.
+ *
  * Entering a realm roots the realm and its global object until the matching
  * JS::LeaveRealm() call.
  */
 extern JS_PUBLIC_API(JS::Realm*)
 EnterRealm(JSContext* cx, JSObject* target);
 
 extern JS_PUBLIC_API(void)
 LeaveRealm(JSContext* cx, JS::Realm* oldRealm);