зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1514251 part 2. Update naming in ReparentWrapper to reflect reality. r=peterv
We're not changing parents; we're changing globals. Let's be clear about that.
This commit is contained in:
Родитель
00a507f332
Коммит
829ee4b10c
|
@ -1740,7 +1740,7 @@ void nsFrameLoader::SetOwnerContent(Element* aContent) {
|
|||
if (wrapper) {
|
||||
JSAutoRealm ar(jsapi.cx(), wrapper);
|
||||
IgnoredErrorResult rv;
|
||||
ReparentWrapper(jsapi.cx(), wrapper, rv);
|
||||
UpdateReflectorGlobal(jsapi.cx(), wrapper, rv);
|
||||
Unused << NS_WARN_IF(rv.Failed());
|
||||
}
|
||||
|
||||
|
|
|
@ -1189,12 +1189,12 @@ static void CheckForOutdatedParent(nsINode* aParent, nsINode* aNode,
|
|||
|
||||
if (JS::GetNonCCWObjectGlobal(existingObj) != global->GetGlobalJSObject()) {
|
||||
JSAutoRealm ar(cx, existingObj);
|
||||
ReparentWrapper(cx, existingObj, aError);
|
||||
UpdateReflectorGlobal(cx, existingObj, aError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static nsresult ReparentWrappersInSubtree(nsIContent* aRoot) {
|
||||
static nsresult UpdateGlobalsInSubtree(nsIContent* aRoot) {
|
||||
MOZ_ASSERT(ShouldUseXBLScope(aRoot));
|
||||
// Start off with no global so we don't fire any error events on failure.
|
||||
AutoJSAPI jsapi;
|
||||
|
@ -1207,7 +1207,7 @@ static nsresult ReparentWrappersInSubtree(nsIContent* aRoot) {
|
|||
for (nsIContent* cur = aRoot; cur; cur = cur->GetNextNode(aRoot)) {
|
||||
if ((reflector = cur->GetWrapper())) {
|
||||
JSAutoRealm ar(cx, reflector);
|
||||
ReparentWrapper(cx, reflector, rv);
|
||||
UpdateReflectorGlobal(cx, reflector, rv);
|
||||
rv.WouldReportJSException();
|
||||
if (rv.Failed()) {
|
||||
// We _could_ consider BlastSubtreeToPieces here, but it's not really
|
||||
|
@ -1279,7 +1279,7 @@ nsresult nsINode::InsertChildBefore(nsIContent* aKid,
|
|||
if (NS_SUCCEEDED(rv) && !wasInXBLScope && ShouldUseXBLScope(aKid)) {
|
||||
MOZ_ASSERT(ShouldUseXBLScope(this),
|
||||
"Why does the kid need to use an XBL scope?");
|
||||
rv = ReparentWrappersInSubtree(aKid);
|
||||
rv = UpdateGlobalsInSubtree(aKid);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
DisconnectChild(aKid);
|
||||
|
|
|
@ -516,7 +516,7 @@ already_AddRefed<nsINode> nsNodeUtils::CloneAndAdopt(
|
|||
if ((wrapper = aNode->GetWrapper())) {
|
||||
MOZ_ASSERT(IsDOMObject(wrapper));
|
||||
JSAutoRealm ar(cx, wrapper);
|
||||
ReparentWrapper(cx, wrapper, aError);
|
||||
UpdateReflectorGlobal(cx, wrapper, aError);
|
||||
if (aError.Failed()) {
|
||||
if (wasRegistered) {
|
||||
aNode->OwnerDoc()->UnregisterActivityObserver(aNode->AsElement());
|
||||
|
|
|
@ -2123,8 +2123,8 @@ bool DictionaryBase::AppendJSONToString(const char16_t* aJSONData,
|
|||
return true;
|
||||
}
|
||||
|
||||
void ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg,
|
||||
ErrorResult& aError) {
|
||||
void UpdateReflectorGlobal(JSContext* aCx, JS::Handle<JSObject*> aObjArg,
|
||||
ErrorResult& aError) {
|
||||
js::AssertSameCompartment(aCx, aObjArg);
|
||||
|
||||
aError.MightThrowJSException();
|
||||
|
@ -2139,19 +2139,20 @@ void ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg,
|
|||
}
|
||||
|
||||
JS::Rooted<JSObject*> aObj(aCx, aObjArg);
|
||||
MOZ_ASSERT(IsDOMObject(aObj));
|
||||
|
||||
const DOMJSClass* domClass = GetDOMClass(aObj);
|
||||
|
||||
// DOM things are always parented to globals.
|
||||
JS::Rooted<JSObject*> oldParent(aCx, JS::GetNonCCWObjectGlobal(aObj));
|
||||
MOZ_ASSERT(JS_IsGlobalObject(oldParent));
|
||||
JS::Rooted<JSObject*> oldGlobal(aCx, JS::GetNonCCWObjectGlobal(aObj));
|
||||
MOZ_ASSERT(JS_IsGlobalObject(oldGlobal));
|
||||
|
||||
JS::Rooted<JSObject*> newParent(aCx,
|
||||
JS::Rooted<JSObject*> newGlobal(aCx,
|
||||
domClass->mGetAssociatedGlobal(aCx, aObj));
|
||||
MOZ_ASSERT(JS_IsGlobalObject(newParent));
|
||||
MOZ_ASSERT(JS_IsGlobalObject(newGlobal));
|
||||
|
||||
JSAutoRealm oldAr(aCx, oldParent);
|
||||
JSAutoRealm oldAr(aCx, oldGlobal);
|
||||
|
||||
if (oldParent == newParent) {
|
||||
if (oldGlobal == newGlobal) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2166,7 +2167,7 @@ void ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObjArg,
|
|||
expandoObject = DOMProxyHandler::GetAndClearExpandoObject(aObj);
|
||||
}
|
||||
|
||||
JSAutoRealm newAr(aCx, newParent);
|
||||
JSAutoRealm newAr(aCx, newGlobal);
|
||||
|
||||
// First we clone the reflector. We get a copy of its properties and clone its
|
||||
// expando chain.
|
||||
|
|
|
@ -2326,10 +2326,16 @@ const nsAString& NonNullHelper(const binding_detail::FakeString& aArg) {
|
|||
return aArg;
|
||||
}
|
||||
|
||||
// Reparent the wrapper of aObj to whatever its native now thinks its
|
||||
// parent should be.
|
||||
void ReparentWrapper(JSContext* aCx, JS::Handle<JSObject*> aObj,
|
||||
ErrorResult& aError);
|
||||
// Given a DOM reflector aObj, give its underlying DOM object a reflector in
|
||||
// whatever global that underlying DOM object now thinks it should be in. If
|
||||
// this is in a different compartment from aObj, aObj will become a
|
||||
// cross-compatment wrapper for the new object. Otherwise, aObj will become the
|
||||
// new object (via a brain transplant). If the new global is the same as the
|
||||
// old global, we just keep using the same object.
|
||||
//
|
||||
// On entry to this method, aCx and aObj must be same-compartment.
|
||||
void UpdateReflectorGlobal(JSContext* aCx, JS::Handle<JSObject*> aObj,
|
||||
ErrorResult& aError);
|
||||
|
||||
/**
|
||||
* Used to implement the Symbol.hasInstance property of an interface object.
|
||||
|
|
|
@ -1449,7 +1449,7 @@ already_AddRefed<nsIDocument> nsHTMLDocument::Open(
|
|||
JS::Rooted<JSObject*> wrapper(cx, GetWrapper());
|
||||
if (oldScope && newScope != oldScope && wrapper) {
|
||||
JSAutoRealm ar(cx, wrapper);
|
||||
mozilla::dom::ReparentWrapper(cx, wrapper, aError);
|
||||
UpdateReflectorGlobal(cx, wrapper, aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1460,7 +1460,7 @@ already_AddRefed<nsIDocument> nsHTMLDocument::Open(
|
|||
JS::Rooted<JSObject*> contentsOwnerWrapper(
|
||||
cx, mTemplateContentsOwner->GetWrapper());
|
||||
if (contentsOwnerWrapper) {
|
||||
mozilla::dom::ReparentWrapper(cx, contentsOwnerWrapper, aError);
|
||||
UpdateReflectorGlobal(cx, contentsOwnerWrapper, aError);
|
||||
if (aError.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче