Changeset 207710 in webkit


Ignore:
Timestamp:
Oct 22, 2016 1:15:52 AM (8 years ago)
Author:
rniwa@webkit.org
Message:

Upgrading custom element should enqueue attributeChanged and connected callbacks
https://bugs.webkit.org/show_bug.cgi?id=163840

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaselined the tests as more test cases are passing now.

  • web-platform-tests/custom-elements/reactions/Node-expected.txt:
  • web-platform-tests/custom-elements/reactions/Range-expected.txt:

Source/WebCore:

When upgrading a custom element, enqueue attributeChanged and connectedCallbacks as needed as specified
in step 3 and 4 of: https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element

Test: fast/custom-elements/upgrading-enqueue-reactions.html

  • bindings/js/JSCustomElementInterface.cpp:

(WebCore::JSCustomElementInterface::upgradeElement): Enqueue

  • dom/CustomElementReactionQueue.cpp:

(WebCore::CustomElementReactionQueueItem::invoke): Don't invoke callbacks when the custom element had
failed to upgrade.
(WebCore::CustomElementReactionQueue::enqueuePostUpgradeReactions): Added.
(WebCore::CustomElementReactionQueue::invokeAll): Upgrading a custom element may enqueue more reactions.
Keep invoking reactions until the queue becomes empty.

  • dom/CustomElementReactionQueue.h:
  • dom/Range.idl: Added a forgotten CEReactions here.

LayoutTests:

Added a W3C style testharness.js test for making sure upgrading custom custom elements
would enqueue attributedChanged and connected reactions.

  • fast/custom-elements/upgrading-enqueue-reactions-expected.txt: Added.
  • fast/custom-elements/upgrading-enqueue-reactions.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r207703 r207710  
     12016-10-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Upgrading custom element should enqueue attributeChanged and connected callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=163840
     5
     6        Reviewed by Darin Adler.
     7
     8        Added a W3C style testharness.js test for making sure upgrading custom custom elements
     9        would enqueue attributedChanged and connected reactions.
     10
     11        * fast/custom-elements/upgrading-enqueue-reactions-expected.txt: Added.
     12        * fast/custom-elements/upgrading-enqueue-reactions.html: Added.
     13
    1142016-10-21  Ryosuke Niwa  <rniwa@webkit.org>
    215
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r207703 r207710  
     12016-10-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Upgrading custom element should enqueue attributeChanged and connected callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=163840
     5
     6        Reviewed by Darin Adler.
     7
     8        Rebaselined the tests as more test cases are passing now.
     9
     10        * web-platform-tests/custom-elements/reactions/Node-expected.txt:
     11        * web-platform-tests/custom-elements/reactions/Range-expected.txt:
     12
    1132016-10-21  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/Node-expected.txt

    r207170 r207710  
    44FAIL textContent on Node must enqueue an attributeChanged reaction when replacing an existing attribute assert_array_equals: lengths differ, expected 1 got 2
    55PASS textContent on Node must not enqueue an attributeChanged reaction when replacing an existing unobserved attribute
    6 FAIL cloneNode on Node must enqueue an attributeChanged reaction when cloning an element with an observed attribute assert_array_equals: lengths differ, expected 2 got 1
     6PASS cloneNode on Node must enqueue an attributeChanged reaction when cloning an element with an observed attribute
    77PASS cloneNode on Node must not enqueue an attributeChanged reaction when cloning an element with an unobserved attribute
    8 FAIL cloneNode on Node must enqueue an attributeChanged reaction when cloning an element only for observed attributes assert_array_equals: lengths differ, expected 3 got 1
     8PASS cloneNode on Node must enqueue an attributeChanged reaction when cloning an element only for observed attributes
    99PASS insertBefore on ChildNode must enqueue a connected reaction
    1010PASS insertBefore on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/reactions/Range-expected.txt

    r207703 r207710  
    22PASS deleteContents on Range must enqueue a disconnected reaction
    33PASS extractContents on Range must enqueue a disconnected reaction
    4 FAIL cloneContents on Range must enqueue an attributeChanged reaction when cloning an element with an observed attribute assert_array_equals: lengths differ, expected 2 got 1
     4PASS cloneContents on Range must enqueue an attributeChanged reaction when cloning an element with an observed attribute
    55PASS cloneContents on Range must not enqueue an attributeChanged reaction when cloning an element with an unobserved attribute
    6 FAIL cloneContents on Range must enqueue an attributeChanged reaction when cloning an element only for observed attributes assert_array_equals: lengths differ, expected 3 got 1
     6PASS cloneContents on Range must enqueue an attributeChanged reaction when cloning an element only for observed attributes
    77PASS insertNode on Range must enqueue a connected reaction
    88PASS insertNode on Range must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document
    99PASS surroundContents on Range must enqueue a connected reaction
    1010PASS surroundContents on Range must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document
    11 FAIL createContextualFragment on Range must construct a custom element assert_array_equals: lengths differ, expected 2 got 1
     11PASS createContextualFragment on Range must construct a custom element
    1212
  • trunk/Source/WebCore/ChangeLog

    r207708 r207710  
     12016-10-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Upgrading custom element should enqueue attributeChanged and connected callbacks
     4        https://bugs.webkit.org/show_bug.cgi?id=163840
     5
     6        Reviewed by Darin Adler.
     7
     8        When upgrading a custom element, enqueue attributeChanged and connectedCallbacks as needed as specified
     9        in step 3 and 4 of: https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element
     10
     11        Test: fast/custom-elements/upgrading-enqueue-reactions.html
     12
     13        * bindings/js/JSCustomElementInterface.cpp:
     14        (WebCore::JSCustomElementInterface::upgradeElement): Enqueue
     15        * dom/CustomElementReactionQueue.cpp:
     16        (WebCore::CustomElementReactionQueueItem::invoke): Don't invoke callbacks when the custom element had
     17        failed to upgrade.
     18        (WebCore::CustomElementReactionQueue::enqueuePostUpgradeReactions): Added.
     19        (WebCore::CustomElementReactionQueue::invokeAll): Upgrading a custom element may enqueue more reactions.
     20        Keep invoking reactions until the queue becomes empty.
     21        * dom/CustomElementReactionQueue.h:
     22        * dom/Range.idl: Added a forgotten CEReactions here.
     23
    1242016-10-21  David Kilzer  <ddkilzer@apple.com>
    225
  • trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp

    r206960 r207710  
    183183    }
    184184
     185    CustomElementReactionQueue::enqueuePostUpgradeReactions(element, *this);
     186
    185187    m_constructionStack.append(&element);
    186188
  • trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp

    r205416 r207710  
    7676    void invoke()
    7777    {
     78        if (m_element->isFailedCustomElement())
     79            return;
    7880        switch (m_type) {
    7981        case Type::ElementUpgrade:
     
    189191}
    190192
     193void CustomElementReactionQueue::enqueuePostUpgradeReactions(Element& element, JSCustomElementInterface& elementInterface)
     194{
     195    if (!element.hasAttributes() && !element.inDocument())
     196        return;
     197
     198    auto* queue = CustomElementReactionStack::ensureCurrentQueue();
     199    if (!queue)
     200        return;
     201
     202    if (element.hasAttributes()) {
     203        for (auto& attribute : element.attributesIterator()) {
     204            if (elementInterface.observesAttribute(attribute.localName()))
     205                queue->m_items.append({element, elementInterface, attribute.name(), nullAtom, attribute.value()});
     206        }
     207    }
     208
     209    if (element.inDocument() && elementInterface.hasConnectedCallback())
     210        queue->m_items.append({CustomElementReactionQueueItem::Type::Connected, element, elementInterface});
     211}
     212
    191213void CustomElementReactionQueue::invokeAll()
    192214{
    193     Vector<CustomElementReactionQueueItem> items;
    194     items.swap(m_items);
    195     for (auto& item : items)
    196         item.invoke();
     215    // FIXME: This queue needs to be per element.
     216    while (!m_items.isEmpty()) {
     217        Vector<CustomElementReactionQueueItem> items = WTFMove(m_items);
     218        for (auto& item : items)
     219            item.invoke();
     220    }
    197221}
    198222
  • trunk/Source/WebCore/dom/CustomElementReactionQueue.h

    r205340 r207710  
    5252    static void enqueueAdoptedCallbackIfNeeded(Element&, Document& oldDocument, Document& newDocument);
    5353    static void enqueueAttributeChangedCallbackIfNeeded(Element&, const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
     54    static void enqueuePostUpgradeReactions(Element&, JSCustomElementInterface&);
    5455
    5556    void invokeAll();
  • trunk/Source/WebCore/dom/Range.idl

    r207170 r207710  
    6868    ClientRect getBoundingClientRect();
    6969
    70     [MayThrowLegacyException, NewObject] DocumentFragment createContextualFragment(DOMString html);
     70    [CEReactions, MayThrowLegacyException, NewObject] DocumentFragment createContextualFragment(DOMString html);
    7171
    7272    [MayThrowLegacyException] short compareNode(Node refNode);
Note: See TracChangeset for help on using the changeset viewer.