Issue #1375 - Implement customElements.upgrade.

Backported from Mozilla bug 1443722.
This commit is contained in:
Job Bautista 2022-10-09 10:33:50 +08:00 committed by roytam1
commit bc36c607a9
3 changed files with 42 additions and 0 deletions

View file

@ -791,6 +791,45 @@ CustomElementRegistry::Define(const nsAString& aName,
}
static void
TryUpgrade(nsINode& aNode)
{
Element* element = aNode.IsElement() ? aNode.AsElement() : nullptr;
if (element) {
CustomElementData* ceData = element->GetCustomElementData();
if (ceData) {
NodeInfo* nodeInfo = element->NodeInfo();
nsAtom* typeAtom = ceData->GetCustomElementType();
CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->NameAtom(),
nodeInfo->NamespaceID(),
typeAtom);
if (definition) {
nsContentUtils::EnqueueUpgradeReaction(element, definition);
}
}
if (ShadowRoot* root = element->GetShadowRoot()) {
for (Element* child = root->GetFirstElementChild(); child;
child = child->GetNextElementSibling()) {
TryUpgrade(*child);
}
}
}
for (Element* child = aNode.GetFirstElementChild(); child;
child = child->GetNextElementSibling()) {
TryUpgrade(*child);
}
}
void
CustomElementRegistry::Upgrade(nsINode& aRoot)
{
TryUpgrade(aRoot);
}
void
CustomElementRegistry::Get(JSContext* aCx, const nsAString& aName,
JS::MutableHandle<JS::Value> aRetVal)