mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 14:54:25 +00:00
Issue #1375 - Implement customElements.upgrade.
Backported from Mozilla bug 1443722.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -11,6 +11,7 @@ interface CustomElementRegistry {
|
||||
any get(DOMString name);
|
||||
[Throws]
|
||||
Promise<void> whenDefined(DOMString name);
|
||||
[CEReactions] void upgrade(Node root);
|
||||
};
|
||||
|
||||
dictionary ElementDefinitionOptions {
|
||||
|
||||
Reference in New Issue
Block a user