Bug 1288791 part 1. Rename the GetParentObject template bits to make it clearer what they're really doing: finding the associated global for an object's native. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 27 Jul 2016 11:05:36 -0400
changeset 349001 d1188f77967db7e9c98010620850ac066172b778
parent 349000 2bf4894c52c903f96d10f534108ed9ebe43b47ba
child 349002 45010c0db1c5ea9bf0c9e059d6fc8f00a9fb5d49
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1288791 part 1. Rename the GetParentObject template bits to make it clearer what they're really doing: finding the associated global for an object's native. r=bkelly
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2020,18 +2020,19 @@ ReparentWrapper(JSContext* aCx, JS::Hand
   JS::Rooted<JSObject*> aObj(aCx, aObjArg);
   const DOMJSClass* domClass = GetDOMClass(aObj);
   // DOM things are always parented to globals.
   JS::Rooted<JSObject*> oldParent(aCx,
   MOZ_ASSERT(js::GetGlobalForObjectCrossCompartment(oldParent) == oldParent);
-  JS::Rooted<JSObject*> newParent(aCx, domClass->mGetParent(aCx, aObj));
-  MOZ_ASSERT(js::GetGlobalForObjectCrossCompartment(newParent) == newParent);
+  JS::Rooted<JSObject*> newParent(aCx,
+                                  domClass->mGetAssociatedGlobal(aCx, aObj));
+  MOZ_ASSERT(JS_IsGlobalObject(newParent));
   JSAutoCompartment oldAc(aCx, oldParent);
   JSCompartment* oldCompartment = js::GetObjectCompartment(oldParent);
   JSCompartment* newCompartment = js::GetObjectCompartment(newParent);
   if (oldCompartment == newCompartment) {
     MOZ_ASSERT(oldParent == newParent);
     return NS_OK;
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -1648,30 +1648,31 @@ WrapNativeParent(JSContext* cx, const T&
 // we can just get the JSObject* directly.
 inline JSObject*
 WrapNativeParent(JSContext* cx, nsIGlobalObject* const& p)
   return p ? p->GetGlobalJSObject() : JS::CurrentGlobalOrNull(cx);
-template<typename T, bool WrapperCached=NativeHasMember<T>::GetParentObject>
-struct GetParentObject
+template<typename T,
+         bool hasAssociatedGlobal=NativeHasMember<T>::GetParentObject>
+struct FindAssociatedGlobalForNative
   static JSObject* Get(JSContext* cx, JS::Handle<JSObject*> obj)
     MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
     T* native = UnwrapDOMObject<T>(obj);
     JSObject* wrappedParent = WrapNativeParent(cx, native->GetParentObject());
     return wrappedParent ? js::GetGlobalForObjectCrossCompartment(wrappedParent) : nullptr;
 template<typename T>
-struct GetParentObject<T, false>
+struct FindAssociatedGlobalForNative<T, false>
   static JSObject* Get(JSContext* cx, JS::Handle<JSObject*> obj)
     return nullptr;
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -385,17 +385,17 @@ def DOMClass(descriptor):
     # padding.
     protoList.extend(['prototypes::id::_ID_Count'] * (descriptor.config.maxProtoChainLength - len(protoList)))
     return fill(
           { ${protoChain} },
           IsBaseOf<nsISupports, ${nativeType} >::value,
-          GetParentObject<${nativeType}>::Get,
+          FindAssociatedGlobalForNative<${nativeType}>::Get,
         protoChain=', '.join(protoList),
--- a/dom/bindings/DOMJSClass.h
+++ b/dom/bindings/DOMJSClass.h
@@ -313,17 +313,18 @@ IsInstance(DOMObjectType type)
 IsInterfacePrototype(DOMObjectType type)
   return type == eInterfacePrototype || type == eGlobalInterfacePrototype;
-typedef JSObject* (*ParentGetter)(JSContext* aCx, JS::Handle<JSObject*> aObj);
+typedef JSObject* (*AssociatedGlobalGetter)(JSContext* aCx,
+                                            JS::Handle<JSObject*> aObj);
 typedef JSObject* (*ProtoGetter)(JSContext* aCx);
  * Returns a handle to the relevant WebIDL prototype object for the current
  * compartment global (which may be a handle to null on out of memory).  Once
  * allocated, the prototype object is guaranteed to exist as long as the global
  * does, since the global traces its array of WebIDL prototypes and
@@ -346,17 +347,20 @@ struct DOMJSClass
   // We store the DOM object in reserved slot with index DOM_OBJECT_SLOT or in
   // the proxy private if we use a proxy object.
   // Sometimes it's an nsISupports and sometimes it's not; this class tells
   // us which it is.
   const bool mDOMObjectIsISupports;
   const NativePropertyHooks* mNativeHooks;
-  ParentGetter mGetParent;
+  // A callback to find the associated global for our C++ object.  Note that
+  // this is used in cases when that global is _changing_, so it will not match
+  // the global of the JSObject* passed in to this function!
+  AssociatedGlobalGetter mGetAssociatedGlobal;
   ProtoHandleGetter mGetProto;
   // This stores the CC participant for the native, null if this class does not
   // implement cycle collection or if it inherits from nsISupports (we can get
   // the CC participant by QI'ing in that case).
   nsCycleCollectionParticipant* mParticipant;
   static const DOMJSClass* FromJSClass(const JSClass* base) {