Bug 991742 part 3. Remove the "scope" argument of WrapNativeParent(). r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 08 Apr 2014 18:27:15 -0400
changeset 178028 37213b9688f46b2dafd0bed3c3acc42757d4a620
parent 178027 34f9e715f4245417737658e1fdbf84408d05c374
child 178029 c86f1317b99ccd78c6edb9c0ee0d0a96e8592643
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbholley
bugs991742
milestone31.0a1
Bug 991742 part 3. Remove the "scope" argument of WrapNativeParent(). r=bholley
dom/bindings/BindingUtils.h
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -1351,22 +1351,21 @@ struct WrapNativeParentHelper<T, false >
 
     return WrapNativeISupportsParent(cx, parent, cache);
   }
 };
 
 // Wrapping of our native parent.
 template<typename T>
 static inline JSObject*
-WrapNativeParent(JSContext* cx, JS::Handle<JSObject*> scope, T* p,
-                 nsWrapperCache* cache, bool useXBLScope = false)
+WrapNativeParent(JSContext* cx, T* p, nsWrapperCache* cache,
+                 bool useXBLScope = false)
 {
-  MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx));
   if (!p) {
-    return scope;
+    return JS::CurrentGlobalOrNull(cx);
   }
 
   JSObject* parent = WrapNativeParentHelper<T>::Wrap(cx, p, cache);
   if (!useXBLScope) {
     return parent;
   }
 
   // If useXBLScope is true, it means that the canonical reflector for this
@@ -1383,19 +1382,19 @@ WrapNativeParent(JSContext* cx, JS::Hand
 
   return rootedParent;
 }
 
 // Wrapping of our native parent, when we don't want to explicitly pass in
 // things like the nsWrapperCache for it.
 template<typename T>
 static inline JSObject*
-WrapNativeParent(JSContext* cx, JS::Handle<JSObject*> scope, const T& p)
+WrapNativeParent(JSContext* cx, const T& p)
 {
-  return WrapNativeParent(cx, scope, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
+  return WrapNativeParent(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
 }
 
 // A way to differentiate between nodes, which use the parent object
 // returned by native->GetParentObject(), and all other objects, which
 // just use the parent's global.
 static inline JSObject*
 GetRealParentObject(void* aParent, JSObject* aParentObject)
 {
@@ -1411,20 +1410,21 @@ GetRealParentObject(Element* aParent, JS
 
 HAS_MEMBER(GetParentObject)
 
 template<typename T, bool WrapperCached=HasGetParentObjectMember<T>::Value>
 struct GetParentObject
 {
   static JSObject* Get(JSContext* cx, JS::Handle<JSObject*> obj)
   {
+    MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
     T* native = UnwrapDOMObject<T>(obj);
     return
       GetRealParentObject(native,
-                          WrapNativeParent(cx, obj, native->GetParentObject()));
+                          WrapNativeParent(cx, native->GetParentObject()));
   }
 };
 
 template<typename T>
 struct GetParentObject<T, false>
 {
   static JSObject* Get(JSContext* cx, JS::Handle<JSObject*> obj)
   {
@@ -1451,17 +1451,18 @@ WrapCallThisObject(JSContext* cx, JS::Ha
 {
   // Callbacks are nsISupports, so WrapNativeParent will just happily wrap them
   // up as an nsISupports XPCWrappedNative... which is not at all what we want.
   // So we need to special-case them.
   JS::Rooted<JSObject*> obj(cx, GetJSObjectFromCallback(p));
   if (!obj) {
     // WrapNativeParent is a bit of a Swiss army knife that will
     // wrap anything for us.
-    obj = WrapNativeParent(cx, scope, p);
+    MOZ_ASSERT(js::IsObjectInContextCompartment(scope, cx));
+    obj = WrapNativeParent(cx, p);
     if (!obj) {
       return nullptr;
     }
   }
 
   // But all that won't necessarily put things in the compartment of cx.
   if (!JS_WrapObject(cx, &obj)) {
     return nullptr;
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2700,19 +2700,20 @@ class CGWrapWithCacheMethod(CGAbstractMe
         self.properties = properties
 
     def definition_body(self):
         assertISupportsInheritance = (
             '  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),\n'
             '             "nsISupports must be on our primary inheritance chain");\n')
         return """%s
 %s
+  MOZ_ASSERT(js::IsObjectInContextCompartment(aScope, aCx));
   JS::Rooted<JSObject*> parent(aCx,
     GetRealParentObject(aObject,
-                        WrapNativeParent(aCx, aScope, aObject->GetParentObject())));
+                        WrapNativeParent(aCx, aObject->GetParentObject())));
   if (!parent) {
     return nullptr;
   }
 
   // That might have ended up wrapping us already, due to the wonders
   // of XBL.  Check for that, and bail out as needed.  Scope so we don't
   // collide with the "obj" we declare in CreateBindingJSObject.
   {