Commit d9efd422 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

custom-elements: Implement customElements.upgrade().

Intent-to-implement-and-ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/zCQe7UkR07w

Bug: 819482
Change-Id: I5645d5711d7fe1323992533e6c73593ba59d1bca
Reviewed-on: https://chromium-review.googlesource.com/1009450Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550513}
parent 5cf8deb5
This is a testharness.js-based test.
FAIL Upgrading an element directly (example from the spec) customElements.upgrade is not a function
FAIL Two elements as children of the upgraded node customElements.upgrade is not a function
FAIL Two elements as descendants of the upgraded node customElements.upgrade is not a function
FAIL Two elements as shadow-including descendants (and not descendants) of the upgraded node customElements.upgrade is not a function
FAIL Elements inside a template contents DocumentFragment node customElements.upgrade is not a function
Harness: the test ran to completion.
......@@ -5456,6 +5456,8 @@ PASS CustomElementRegistry interface: operation get(DOMString)
PASS Unscopable handled correctly for get(DOMString) on CustomElementRegistry
PASS CustomElementRegistry interface: operation whenDefined(DOMString)
PASS Unscopable handled correctly for whenDefined(DOMString) on CustomElementRegistry
PASS CustomElementRegistry interface: operation upgrade(Node)
PASS Unscopable handled correctly for upgrade(Node) on CustomElementRegistry
PASS DataTransfer interface: existence and properties of interface object
PASS DataTransfer interface object length
PASS DataTransfer interface object name
......
......@@ -1437,6 +1437,7 @@ interface CustomElementRegistry {
[CEReactions] void define(DOMString name, Function constructor, optional ElementDefinitionOptions options);
any get(DOMString name);
Promise<void> whenDefined(DOMString name);
[CEReactions] void upgrade(Node root);
};
dictionary ElementDefinitionOptions {
......
......@@ -843,6 +843,7 @@ interface CustomElementRegistry
method constructor
method define
method get
method upgrade
method whenDefined
interface CustomEvent : Event
attribute @@toStringTag
......
......@@ -1135,6 +1135,7 @@ interface CustomElementRegistry
method constructor
method define
method get
method upgrade
method whenDefined
interface CustomEvent : Event
attribute @@toStringTag
......
......@@ -11,7 +11,9 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_definition_options.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/exception_code.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/custom/ce_reactions_scope.h"
#include "third_party/blink/renderer/core/html/custom/custom_element.h"
......@@ -30,6 +32,25 @@
namespace blink {
namespace {
void CollectUpgradeCandidateInNode(Node& root,
HeapVector<Member<Element>>& candidates) {
if (root.IsElementNode()) {
Element& root_element = ToElement(root);
if (root_element.GetCustomElementState() == CustomElementState::kUndefined)
candidates.push_back(root_element);
if (auto* shadow_root = root_element.GetShadowRoot()) {
if (shadow_root->GetType() != ShadowRootType::kUserAgent)
CollectUpgradeCandidateInNode(*shadow_root, candidates);
}
}
for (auto& element : Traversal<HTMLElement>::ChildrenOf(root))
CollectUpgradeCandidateInNode(element, candidates);
}
} // anonymous namespace
// Returns true if |name| is invalid.
static bool ThrowIfInvalidName(const AtomicString& name,
ExceptionState& exception_state) {
......@@ -337,4 +358,19 @@ void CustomElementRegistry::CollectCandidates(
sorter.Sorted(elements, document);
}
// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-upgrade
void CustomElementRegistry::upgrade(Node* root) {
DCHECK(root);
// 1. Let candidates be a list of all of root's shadow-including
// inclusive descendant elements, in tree order.
HeapVector<Member<Element>> candidates;
CollectUpgradeCandidateInNode(*root, candidates);
// 2. For each candidate of candidates, try to upgrade candidate.
for (auto& candidate : candidates) {
CustomElement::TryToUpgrade(candidate);
}
}
} // namespace blink
......@@ -64,6 +64,7 @@ class CORE_EXPORT CustomElementRegistry final : public ScriptWrappable {
ScriptPromise whenDefined(ScriptState*,
const AtomicString& name,
ExceptionState&);
void upgrade(Node* root);
void Entangle(V0CustomElementRegistrationContext*);
......
......@@ -6,4 +6,5 @@ interface CustomElementRegistry {
[CallWith=ScriptState, CEReactions, CustomElementCallbacks, RaisesException, MeasureAs=CustomElementRegistryDefine] void define(DOMString name, Function constructor, optional ElementDefinitionOptions options);
any get(DOMString name);
[CallWith=ScriptState,RaisesException] Promise<void> whenDefined(DOMString name);
[CEReactions] void upgrade(Node root);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment