mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1288791 part 2. Rename WrapNativeParent to FindAssociatedGlobal and update it to actually do that. r=bkelly
This commit is contained in:
parent
8e34004cf1
commit
5b840d9b96
@ -1603,52 +1603,54 @@ struct WrapNativeParentHelper<T, false>
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapping of our native parent.
|
||||
// Finding the associated global for an object.
|
||||
template<typename T>
|
||||
static inline JSObject*
|
||||
WrapNativeParent(JSContext* cx, T* p, nsWrapperCache* cache,
|
||||
bool useXBLScope = false)
|
||||
FindAssociatedGlobal(JSContext* cx, T* p, nsWrapperCache* cache,
|
||||
bool useXBLScope = false)
|
||||
{
|
||||
if (!p) {
|
||||
return JS::CurrentGlobalOrNull(cx);
|
||||
}
|
||||
|
||||
JSObject* parent = WrapNativeParentHelper<T>::Wrap(cx, p, cache);
|
||||
if (!parent || !useXBLScope) {
|
||||
return parent;
|
||||
JSObject* obj = WrapNativeParentHelper<T>::Wrap(cx, p, cache);
|
||||
if (!obj) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obj = js::GetGlobalForObjectCrossCompartment(obj);
|
||||
|
||||
if (!useXBLScope) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
// If useXBLScope is true, it means that the canonical reflector for this
|
||||
// native object should live in the content XBL scope. Note that we never put
|
||||
// anonymous content inside an add-on scope.
|
||||
if (xpc::IsInContentXBLScope(parent)) {
|
||||
return parent;
|
||||
if (xpc::IsInContentXBLScope(obj)) {
|
||||
return obj;
|
||||
}
|
||||
JS::Rooted<JSObject*> rootedParent(cx, parent);
|
||||
JS::Rooted<JSObject*> xblScope(cx, xpc::GetXBLScope(cx, rootedParent));
|
||||
NS_ENSURE_TRUE(xblScope, nullptr);
|
||||
JSAutoCompartment ac(cx, xblScope);
|
||||
if (NS_WARN_IF(!JS_WrapObject(cx, &rootedParent))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rootedParent;
|
||||
JS::Rooted<JSObject*> rootedObj(cx, obj);
|
||||
JSObject* xblScope = xpc::GetXBLScope(cx, rootedObj);
|
||||
MOZ_ASSERT_IF(xblScope, JS_IsGlobalObject(xblScope));
|
||||
MOZ_ASSERT_IF(xblScope, !JS::ObjectIsMarkedGray(xblScope));
|
||||
return xblScope;
|
||||
}
|
||||
|
||||
// Wrapping of our native parent, when we don't want to explicitly pass in
|
||||
// things like the nsWrapperCache for it.
|
||||
// Finding of the associated global for an object, when we don't want to
|
||||
// explicitly pass in things like the nsWrapperCache for it.
|
||||
template<typename T>
|
||||
static inline JSObject*
|
||||
WrapNativeParent(JSContext* cx, const T& p)
|
||||
FindAssociatedGlobal(JSContext* cx, const T& p)
|
||||
{
|
||||
return WrapNativeParent(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
|
||||
return FindAssociatedGlobal(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
|
||||
}
|
||||
|
||||
// Specialization for the case of nsIGlobalObject, since in that case
|
||||
// we can just get the JSObject* directly.
|
||||
template<>
|
||||
inline JSObject*
|
||||
WrapNativeParent(JSContext* cx, nsIGlobalObject* const& p)
|
||||
FindAssociatedGlobal(JSContext* cx, nsIGlobalObject* const& p)
|
||||
{
|
||||
return p ? p->GetGlobalJSObject() : JS::CurrentGlobalOrNull(cx);
|
||||
}
|
||||
@ -1661,8 +1663,7 @@ struct FindAssociatedGlobalForNative
|
||||
{
|
||||
MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
|
||||
T* native = UnwrapDOMObject<T>(obj);
|
||||
JSObject* wrappedParent = WrapNativeParent(cx, native->GetParentObject());
|
||||
return wrappedParent ? js::GetGlobalForObjectCrossCompartment(wrappedParent) : nullptr;
|
||||
return FindAssociatedGlobal(cx, native->GetParentObject());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -3582,10 +3582,11 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
|
||||
"nsISupports must be on our primary inheritance chain");
|
||||
|
||||
JS::Rooted<JSObject*> parent(aCx, WrapNativeParent(aCx, aObject->GetParentObject()));
|
||||
if (!parent) {
|
||||
JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
|
||||
if (!global) {
|
||||
return false;
|
||||
}
|
||||
MOZ_ASSERT(JS_IsGlobalObject(global));
|
||||
|
||||
// That might have ended up wrapping us already, due to the wonders
|
||||
// of XBL. Check for that, and bail out as needed.
|
||||
@ -3597,8 +3598,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
|
||||
return true;
|
||||
}
|
||||
|
||||
JSAutoCompartment ac(aCx, parent);
|
||||
JS::Rooted<JSObject*> global(aCx, js::GetGlobalForObjectCrossCompartment(parent));
|
||||
JSAutoCompartment ac(aCx, global);
|
||||
$*{declareProto}
|
||||
|
||||
$*{createObject}
|
||||
|
@ -2235,8 +2235,6 @@ nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> val(cx);
|
||||
// XXXbz Should we call the (slightly misnamed, really) WrapNativeParent
|
||||
// here?
|
||||
if (!dom::WrapObject(cx, supp, cache, nullptr, &val)) {
|
||||
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return;
|
||||
|
@ -23,6 +23,9 @@ function doTest() {
|
||||
// First, the crashtest becomes non-deterministics if we morph |form| before
|
||||
// getting to scope 3 (as explained below). This means that we can't trigger
|
||||
// the PreCreate hook for |input|, because that will call WrapNativeParent
|
||||
// (Well... No, it won't: there is no WrapNativeParent, but there are also no
|
||||
// more pre-create hooks, slimwrappers, parenting to the form, or any of the
|
||||
// stuff this test is trying to test.)
|
||||
// on the form, which will end up making a cross-compartment wrapper, which
|
||||
// will morph form. But this puts us in a pickle, because appendChild returns
|
||||
// the apppended child, which will trigger the PreCreate hook in
|
||||
|
Loading…
Reference in New Issue
Block a user