diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index daef382f909..ff558a7572a 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1111,6 +1111,22 @@ WrapNativeParent(JSContext* cx, JS::Handle scope, const T& p) return WrapNativeParent(cx, scope, GetParentPointer(p), GetWrapperCache(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) +{ + return aParentObject ? + js::GetGlobalForObjectCrossCompartment(aParentObject) : nullptr; +} + +static inline JSObject* +GetRealParentObject(Element* aParent, JSObject* aParentObject) +{ + return aParentObject; +} + HAS_MEMBER(GetParentObject) template::Value> @@ -1119,7 +1135,9 @@ struct GetParentObject static JSObject* Get(JSContext* cx, JS::Handle obj) { T* native = UnwrapDOMObject(obj); - return WrapNativeParent(cx, obj, native->GetParentObject()); + return + GetRealParentObject(native, + WrapNativeParent(cx, obj, native->GetParentObject())); } }; diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 0c88a7208a6..d3791b1d5db 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -2046,7 +2046,8 @@ class CGWrapWithCacheMethod(CGAbstractMethod): return """%s %s JS::Rooted parent(aCx, - WrapNativeParent(aCx, aScope, aObject->GetParentObject())); + GetRealParentObject(aObject, + WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); if (!parent) { return NULL; }