Bug 1299363 - Part 5-1: Make the constructor created by document.registerElement() also works with construction stack.

So that the old upgrade can also work with new upgrade steps which will be implemented in part 5-2.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-05 10:32:30 -05:00 committed by Roy Tam
commit b2e0ae6983
2 changed files with 54 additions and 43 deletions

View file

@ -799,40 +799,6 @@ CustomElementRegistry::Upgrade(Element* aElement,
MOZ_ASSERT(aElement->IsHTMLElement(aDefinition->mLocalName));
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
return;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> reflector(cx, aElement->GetWrapper());
if (reflector) {
Maybe<JSAutoCompartment> ac;
JS::Rooted<JSObject*> prototype(cx, aDefinition->mPrototype);
if (aElement->NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(prototype))) {
ac.emplace(cx, reflector);
if (!JS_WrapObject(cx, &prototype) ||
!JS_SetPrototype(cx, reflector, prototype)) {
return;
}
} else {
// We want to set the custom prototype in the compartment where it was
// registered. We store the prototype from define() without unwrapped,
// hence the prototype's compartment is the compartment where it was
// registered.
// In the case that |reflector| and |prototype| are in different
// compartments, this will set the prototype on the |reflector|'s wrapper
// and thus only visible in the wrapper's compartment, since we know
// reflector's principal does not subsume prototype's in this case.
ac.emplace(cx, prototype);
if (!JS_WrapObject(cx, &reflector) ||
!JS_SetPrototype(cx, reflector, prototype)) {
return;
}
}
}
EnqueueLifecycleCallback(nsIDocument::eCreated, aElement, nullptr, aDefinition);
}