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
parent 3ea1f776a9
commit bc36c607a9
3 changed files with 42 additions and 0 deletions
+39
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)
+2
View File
@@ -525,6 +525,8 @@ public:
JS::MutableHandle<JS::Value> aRetVal);
already_AddRefed<Promise> WhenDefined(const nsAString& aName, ErrorResult& aRv);
void Upgrade(nsINode& aRoot);
};
class MOZ_RAII AutoCEReaction final {
+1
View File
@@ -11,6 +11,7 @@ interface CustomElementRegistry {
any get(DOMString name);
[Throws]
Promise<void> whenDefined(DOMString name);
[CEReactions] void upgrade(Node root);
};
dictionary ElementDefinitionOptions {