Changeset 234507 in webkit


Ignore:
Timestamp:
Aug 2, 2018 12:25:23 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Implement customElements.upgrade()
https://bugs.webkit.org/show_bug.cgi?id=183397

Reviewed by Frédéric Wang.

LayoutTests/imported/w3c:

Rebaseline the test now that we're passing.

  • web-platform-tests/custom-elements/custom-element-registry/upgrade-expected.txt:

Source/WebCore:

Added the support to upgrade custom elements directly. Ordinarily, custom elements get upgraded as they are
inserted / connected into a document but some script libraries and authors want to be able to upgrade them before that.
Also see https://github.com/w3c/webcomponents/issues/710

Implemented the method as specified at:
https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-upgrade

When invoked, the upgrade(root) method must run these steps:

  1. Let candidates be a list of all of root's shadow-including inclusive descendant elements, in shadow-including tree order.
  2. For each candidate of candidates, try to upgrade candidate.

Tests: imported/w3c/web-platform-tests/custom-elements/custom-element-registry/upgrade.html

  • dom/CustomElementReactionQueue.cpp:

(WebCore::CustomElementReactionQueue::enqueueElementUpgradeIfDefined): Removed the assertion that the upgraded element
is connected since the whole point of this API is to upgrade a disconnected element.

  • dom/CustomElementRegistry.cpp:

(WebCore::upgradeElementsInShadowIncludingdescendants): Added.
(WebCore::CustomElementRegistry::upgrade): Added.

  • dom/CustomElementRegistry.h: Forward declare DeferredPromise instead of unnecessarily including JSDOMPromiseDeferred.h.
  • dom/CustomElementRegistry.idl:
  • dom/Element.cpp:

(WebCore::Element::insertedIntoAncestor): Moved the assertion here.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r234131 r234507  
     12018-08-01  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Implement customElements.upgrade()
     4        https://bugs.webkit.org/show_bug.cgi?id=183397
     5
     6        Reviewed by Frédéric Wang.
     7
     8        Rebaseline the test now that we're passing.
     9
     10        * web-platform-tests/custom-elements/custom-element-registry/upgrade-expected.txt:
     11
    1122018-07-23  Manuel Rego Casasnovas  <rego@igalia.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/custom-element-registry/upgrade-expected.txt

    r234039 r234507  
    11
    2 FAIL Upgrading an element directly (example from the spec) customElements.upgrade is not a function. (In 'customElements.upgrade(el)', 'customElements.upgrade' is undefined)
    3 FAIL Two elements as children of the upgraded node customElements.upgrade is not a function. (In 'customElements.upgrade(container)', 'customElements.upgrade' is undefined)
    4 FAIL Two elements as descendants of the upgraded node customElements.upgrade is not a function. (In 'customElements.upgrade(container)', 'customElements.upgrade' is undefined)
    5 FAIL Two elements as shadow-including descendants (and not descendants) of the upgraded node customElements.upgrade is not a function. (In 'customElements.upgrade(container)', 'customElements.upgrade' is undefined)
    6 FAIL Elements inside a template contents DocumentFragment node customElements.upgrade is not a function. (In 'customElements.upgrade(template)', 'customElements.upgrade' is undefined)
     2PASS Upgrading an element directly (example from the spec)
     3PASS Two elements as children of the upgraded node
     4PASS Two elements as descendants of the upgraded node
     5PASS Two elements as shadow-including descendants (and not descendants) of the upgraded node
     6PASS Elements inside a template contents DocumentFragment node
    77
  • trunk/Source/WebCore/ChangeLog

    r234506 r234507  
     12018-08-01  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Implement customElements.upgrade()
     4        https://bugs.webkit.org/show_bug.cgi?id=183397
     5
     6        Reviewed by Frédéric Wang.
     7
     8        Added the support to upgrade custom elements directly. Ordinarily, custom elements get upgraded as they are
     9        inserted / connected into a document but some script libraries and authors want to be able to upgrade them before that.
     10        Also see https://github.com/w3c/webcomponents/issues/710
     11
     12        Implemented the method as specified at:
     13        https://html.spec.whatwg.org/multipage/custom-elements.html#dom-customelementregistry-upgrade
     14
     15            When invoked, the upgrade(root) method must run these steps:
     16            1. Let candidates be a list of all of root's shadow-including inclusive descendant elements,
     17               in shadow-including tree order.
     18            2. For each candidate of candidates, try to upgrade candidate.
     19
     20        Tests: imported/w3c/web-platform-tests/custom-elements/custom-element-registry/upgrade.html
     21
     22        * dom/CustomElementReactionQueue.cpp:
     23        (WebCore::CustomElementReactionQueue::enqueueElementUpgradeIfDefined): Removed the assertion that the upgraded element
     24        is connected since the whole point of this API is to upgrade a disconnected element.
     25        * dom/CustomElementRegistry.cpp:
     26        (WebCore::upgradeElementsInShadowIncludingdescendants): Added.
     27        (WebCore::CustomElementRegistry::upgrade): Added.
     28        * dom/CustomElementRegistry.h: Forward declare DeferredPromise instead of unnecessarily including JSDOMPromiseDeferred.h.
     29        * dom/CustomElementRegistry.idl:
     30        * dom/Element.cpp:
     31        (WebCore::Element::insertedIntoAncestor): Moved the assertion here.
     32
    1332018-08-02  Simon Fraser  <simon.fraser@apple.com>
    234
  • trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp

    r228218 r234507  
    123123void CustomElementReactionQueue::enqueueElementUpgradeIfDefined(Element& element)
    124124{
    125     ASSERT(element.isConnected());
    126125    ASSERT(element.isCustomElementUpgradeCandidate());
    127126    auto* window = element.document().domWindow();
  • trunk/Source/WebCore/dom/CustomElementRegistry.cpp

    r228218 r234507  
    3636#include "QualifiedName.h"
    3737#include "ShadowRoot.h"
     38#include "TypedElementDescendantIterator.h"
    3839#include <JavaScriptCore/JSCJSValueInlines.h>
    3940#include <wtf/text/AtomicString.h>
     
    114115}
    115116
     117static void upgradeElementsInShadowIncludingDescendants(ContainerNode& root)
     118{
     119    for (auto& element : descendantsOfType<Element>(root)) {
     120        if (element.isCustomElementUpgradeCandidate())
     121            CustomElementReactionQueue::enqueueElementUpgradeIfDefined(element);
     122        if (auto* shadowRoot = element.shadowRoot())
     123            upgradeElementsInShadowIncludingDescendants(*shadowRoot);
     124    }
    116125}
     126
     127void CustomElementRegistry::upgrade(Node& root)
     128{
     129    if (!is<ContainerNode>(root))
     130        return;
     131
     132    if (is<Element>(root) && downcast<Element>(root).isCustomElementUpgradeCandidate())
     133        CustomElementReactionQueue::enqueueElementUpgradeIfDefined(downcast<Element>(root));
     134
     135    upgradeElementsInShadowIncludingDescendants(downcast<ContainerNode>(root));
     136}
     137
     138}
  • trunk/Source/WebCore/dom/CustomElementRegistry.h

    r218593 r234507  
    2626#pragma once
    2727
    28 #include "JSDOMPromiseDeferred.h"
    2928#include "QualifiedName.h"
    3029#include <wtf/HashMap.h>
     
    4342class CustomElementRegistry;
    4443class DOMWindow;
     44class DeferredPromise;
    4545class Element;
    4646class JSCustomElementInterface;
     47class Node;
    4748class QualifiedName;
    4849
     
    6364
    6465    JSC::JSValue get(const AtomicString&);
     66    void upgrade(Node& root);
    6567
    6668    HashMap<AtomicString, Ref<DeferredPromise>>& promiseMap() { return m_promiseMap; }
  • trunk/Source/WebCore/dom/CustomElementRegistry.idl

    r217433 r234507  
    3232    any get(DOMString name);
    3333    [Custom, MayThrowException, ReturnsOwnPromise] Promise<void> whenDefined(DOMString name);
     34    [CEReactions] void upgrade(Node root);
    3435};
  • trunk/Source/WebCore/dom/Element.cpp

    r234109 r234507  
    17481748
    17491749    if (becomeConnected) {
    1750         if (UNLIKELY(isCustomElementUpgradeCandidate()))
     1750        if (UNLIKELY(isCustomElementUpgradeCandidate())) {
     1751            ASSERT(isConnected());
    17511752            CustomElementReactionQueue::enqueueElementUpgradeIfDefined(*this);
     1753        }
    17521754        if (UNLIKELY(isDefinedCustomElement()))
    17531755            CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(*this);
Note: See TracChangeset for help on using the changeset viewer.