Changeset 205416 in webkit


Ignore:
Timestamp:
Sep 3, 2016 10:09:28 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

Update the semantics of defined-ness of custom elements per spec changes
https://bugs.webkit.org/show_bug.cgi?id=161570

Reviewed by Darin Adler.

Source/WebCore:

This patch adds the notion of a custom element that failed to construct or upgrade so that :defined
doesn't apply to such an element. We also set the defined flag inside the HTMLElement constructor in
the case of synchronous construction instead of waiting for the custom element constructor to finish.
https://dom.spec.whatwg.org/#concept-create-element

Conceptually, there are four distinct states for an element:

  1. The element is a built-in element
  2. The element is a custom element yet to be defined (an upgrade candidate).
  3. The element is a well-defined custom element (constructed or upgraded).
  4. The element has failed to construct or upgrade as a custom element (because the custom element

constructor threw an exception or returned an unexpected object).

In the latest DOM/HTML specifications, these states are called as 1. "uncustomized", 2. "undefined",

  1. "custom", and 4. "failed": https://dom.spec.whatwg.org/#concept-element-defined

This patch refactors Node flags to introduce these distinct states as the following:

  1. Neither IsCustomElement nor IsEditingTextOrUnresolvedCustomElementFlag is set.
  2. IsCustomElement and IsEditingTextOrUnresolvedCustomElementFlag are set.

isCustomElementUpgradeCandidate() and isUndefinedCustomElement() return true.

  1. IsCustomElement is set and IsEditingTextOrUnresolvedCustomElementFlag is unset.

isDefinedCustomElement() returns true.

  1. IsCustomElement is unset and IsEditingTextOrUnresolvedCustomElementFlag is set.

isFailedCustomElement() and isUndefinedCustomElement() return true.

Per a spec change, this patch also makes :defined applied to a synchronously constructed custom element
immediately after super() call in the constructor. When the constructor throws an exception or fails to
return the right element, the HTML parser marks the fallback element with setIsUndefinedCustomElement.

Tests: fast/custom-elements/defined-pseudo-class.html

fast/custom-elements/defined-rule.html
fast/custom-elements/upgrading/Node-cloneNode.html

  • bindings/js/JSCustomElementInterface.cpp:

(WebCore::JSCustomElementInterface::constructElement): Don't set :defined flag here since that's done
in the HTMLElement constructor now.
(WebCore::JSCustomElementInterface::upgradeElement): Mark the element as failed-to-upgrade as needed.

  • bindings/js/JSElementCustom.cpp:

(WebCore::toJSNewlyCreated):

  • bindings/js/JSHTMLElementCustom.cpp:

(WebCore::constructJSHTMLElement):

  • css/SelectorCheckerTestFunctions.h:

(WebCore::isDefinedElement):

  • dom/CustomElementReactionQueue.cpp:

(WebCore::CustomElementReactionQueue::enqueueElementUpgradeIfDefined): Enqueue custom element reactions
only if the element is well defined (successfully constructed or upgraded).
(WebCore::CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded): Ditto.
(WebCore::CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded): Ditto.
(WebCore::CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded): Ditto.
(WebCore::CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded): Ditto.

  • dom/CustomElementRegistry.cpp:

(WebCore::enqueueUpgradeInShadowIncludingTreeOrder):

  • dom/Document.cpp:

(WebCore::createUpgradeCandidateElement):
(WebCore::createFallbackHTMLElement):

  • dom/Element.cpp:

(WebCore::Element::attributeChanged):
(WebCore::Element::didMoveToNewDocument):
(WebCore::Element::insertedInto):
(WebCore::Element::removedFrom):
(WebCore::Element::setCustomElementIsResolved): Deleted.
(WebCore::Element::setIsDefinedCustomElement): Renamed from setCustomElementIsResolved.
(WebCore::Element::setIsFailedCustomElement): Added.
(WebCore::Element::setIsCustomElementUpgradeCandidate): Added.
(WebCore::Element::customElementInterface):

  • dom/Element.h:
  • dom/Node.h:

(WebCore::Node::setIsCustomElement): Deleted.
(WebCore::Node::isUndefinedCustomElement): Renamed from isUnresolvedCustomElement.
(WebCore::Node::setIsUnresolvedCustomElement): Deleted.
(WebCore::Node::isCustomElementUpgradeCandidate): Added.
(WebCore::Node::isDefinedCustomElement): Renamed from isCustomElement.
(WebCore::Node::isFailedCustomElement): Added.

  • dom/make_names.pl:

(printWrapperFactoryCppFile): Use the HTMLElement wrapper on upgrade candidates. When a custom element
failed to upgrade, the HTMLElement constructor would have created the wrapper so we never run this code.

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): Mark the HTMLUnknownElement created when
the custom element constructor failed to run successfully as a failed custom element so that :define
wouldn't apply to this element.

LayoutTests:

Added a new test cases to defined-pseudo-class.html, defined-rule.html, and Node-cloneNode.html
and rebaselined the tests.

  • fast/custom-elements/defined-pseudo-class-expected.txt:
  • fast/custom-elements/defined-pseudo-class.html:

(MyElement): Made matchInsideConstructor an instance variable so that there won't be inter-test dependency.
Added test cases for :defined not being not applying to a failed-to-upgrade custom element. Finally, updated
test expectation to reflect the fact :defined now applies inside custom element constructors immediately after
super() call.

  • fast/custom-elements/defined-rule.html: Added a test case for :defined not applying to a failed-to-upgrade

custom element. Also adjusted the height of the last box so that the green box is still 100px by 100px.

  • fast/custom-elements/upgrading/Node-cloneNode-expected.txt:
  • fast/custom-elements/upgrading/Node-cloneNode.html: Added a test to make sure we don't try to upgrade

a custom element for the second time when the first attempt resulted in the constructor throwing an exception.

Location:
trunk
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205410 r205416  
     12016-09-03  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Update the semantics of defined-ness of custom elements per spec changes
     4        https://bugs.webkit.org/show_bug.cgi?id=161570
     5
     6        Reviewed by Darin Adler.
     7
     8        Added a new test cases to defined-pseudo-class.html, defined-rule.html, and Node-cloneNode.html
     9        and rebaselined the tests.
     10
     11        * fast/custom-elements/defined-pseudo-class-expected.txt:
     12        * fast/custom-elements/defined-pseudo-class.html:
     13        (MyElement): Made matchInsideConstructor an instance variable so that there won't be inter-test dependency.
     14        Added test cases for :defined not being not applying to a failed-to-upgrade custom element. Finally, updated
     15        test expectation to reflect the fact :defined now applies inside custom element constructors immediately after
     16        super() call.
     17        * fast/custom-elements/defined-rule.html: Added a test case for :defined not applying to a failed-to-upgrade
     18        custom element. Also adjusted the height of the last box so that the green box is still 100px by 100px.
     19        * fast/custom-elements/upgrading/Node-cloneNode-expected.txt:
     20        * fast/custom-elements/upgrading/Node-cloneNode.html: Added a test to make sure we don't try to upgrade
     21        a custom element for the second time when the first attempt resulted in the constructor throwing an exception.
     22
    1232016-09-03  Ryosuke Niwa  <rniwa@webkit.org>
    224
  • trunk/LayoutTests/fast/custom-elements/defined-pseudo-class-expected.txt

    r205386 r205416  
    1 CONSOLE MESSAGE: line 75: TypeError: The result of constructing a custom element must be a HTMLElement
     1CONSOLE MESSAGE: line 79: TypeError: The result of constructing a custom element must be a HTMLElement
    22
    33Harness Error (FAIL), message = TypeError: The result of constructing a custom element must be a HTMLElement
     
    66PASS The defined flag of a custom element must not be set if a custom element has not been upgraded yet even if the element has been defined
    77PASS The defined flag of a custom element must be set when a custom element is successfully upgraded
    8 PASS The defined flag of a custom element must be set if there is a matching definition
     8PASS The defined flag of a custom element must be set inside the HTMLElement constructor
    99PASS The defined flag of an upgraded custom element must be set
    1010PASS The defined flag of a custom element created by HTML parser must be unset if there is no matching definition
    1111PASS The defined flag of a custom element created by HTML parser must be set if there is a matching definition
    12 PASS The defined flag of a custom element created by HTML parser must be set after checking the returned result is an instance of HTMLElement
     12PASS The element inserted by HTML parser must not have the defined flag set if the constructor returns a Text node
    1313PASS The defined flag of a custom element must be set after checking the returned result is an instance of HTMLElement when upgrading a custom element
     14PASS The defined flag of a custom element must be set inside a constructor when constructing a custom element synchronously even if the constructor threw an exception later
     15PASS The defined flag of a custom element must not be set when an upgrade of a custom element fails
    1416
  • trunk/LayoutTests/fast/custom-elements/defined-pseudo-class.html

    r205340 r205416  
    1919}, 'The defined flag of a custom element must not be set if a custom element has not been upgraded yet');
    2020
    21 var matchInsideConstructor;
    2221class MyElement extends HTMLElement {
    2322    constructor() {
    2423        super();
    25         matchInsideConstructor = this.matches(':defined');
     24        this.matchInsideConstructor = this.matches(':defined');
    2625    }
    2726}
     27
    2828customElements.define('my-element', MyElement);
    2929
     
    3535    document.body.appendChild(upgradeCandidate);
    3636    assert_true(upgradeCandidate.matches(':defined'));
    37     assert_false(matchInsideConstructor, 'Upgrading a custom element must set defined flag after invoking the constructor');
     37    assert_false(!!upgradeCandidate.matchInsideConstructor, 'Upgrading a custom element must set defined flag after invoking the constructor');
    3838}, 'The defined flag of a custom element must be set when a custom element is successfully upgraded');
    3939
     
    4141    var definedElement = document.createElement('my-element');
    4242    assert_true(definedElement.matches(':defined'));
    43     assert_false(matchInsideConstructor, 'Creating a custom element must set defined flag after invoking the constructor');
    44 }, 'The defined flag of a custom element must be set if there is a matching definition');
     43    assert_true(!!definedElement.matchInsideConstructor);
     44}, 'The defined flag of a custom element must be set inside the HTMLElement constructor');
    4545
    4646test(function () {
    4747    var upgradedElement = document.createElement('my-element').cloneNode(true);
    4848    assert_true(upgradedElement.matches(':defined'));
    49     assert_false(matchInsideConstructor, 'Creating a custom element must set defined flag after invoking the constructor');
     49    assert_false(!!upgradedElement.matchInsideConstructor, 'Upgrading a custom element must set defined flag after invoking the constructor');
    5050}, 'The defined flag of an upgraded custom element must be set');
    5151
     
    5555    var parserCreatedUnfefinedElement = document.querySelector('my-other-element');
    5656    assert_false(parserCreatedUnfefinedElement.matches(':defined'));
     57    assert_false(!!parserCreatedUnfefinedElement.matchInsideConstructor);
    5758}, 'The defined flag of a custom element created by HTML parser must be unset if there is no matching definition');
    5859
    59 document.write('<my-element></my-element>');
     60document.write('<my-element id="parser-created-defined-element"></my-element>');
    6061
    6162test(function () {
    62     var parserCreatedDefinedElement = document.querySelector('my-element');
     63    var parserCreatedDefinedElement = document.getElementById('parser-created-defined-element');
    6364    assert_true(parserCreatedDefinedElement.matches(':defined'));
     65    assert_true(!!parserCreatedDefinedElement.matchInsideConstructor,
     66        'The defined flag must be set inside HTMLElement constructor when HTMLParser creates a custom element synchronously');
    6467}, 'The defined flag of a custom element created by HTML parser must be set if there is a matching definition');
    6568
     
    6770    constructor() {
    6871        super();
    69         matchInsideConstructor = this.matches(':defined');
     72        this.matchInsideConstructor = this.matches(':defined');
     73        ReturnsAnotherNode.lastInstance = this;
    7074        return document.createTextNode('');
    7175    }
     
    7680
    7781test(function () {
    78     assert_true(document.querySelector('returns-another-node').matches(':defined'));
    79     assert_false(matchInsideConstructor,
    80         'HTML parser must create a custom element with the defined flag initially unset');
    81 }, 'The defined flag of a custom element created by HTML parser must be set after checking the returned result is an instance of HTMLElement');
     82    var instance = document.querySelector('returns-another-node');
     83    assert_not_equals(instance, ReturnsAnotherNode.lastInstance, 'The element inserted by HTML parser must not be the one returned by super() call');
     84    assert_true(instance instanceof HTMLElement, 'The element inserted by HTML parser must be a HTMLElement');
     85    assert_false(instance instanceof ReturnsAnotherNode, 'The element inserted by HTML parser must be a custom element');
     86    assert_false(instance.matches(':defined'), 'The defined flag must not be set on the element inserted by HTML parser');
     87    assert_true(!!ReturnsAnotherNode.lastInstance.matchInsideConstructor,
     88        'The defined flag must be set inside HTMLElement constructor when HTMLParser creates a custom element synchronously');
     89}, 'The element inserted by HTML parser must not have the defined flag set if the constructor returns a Text node');
    8290
    8391test(function () {
     
    8795    } catch (e) { }
    8896    assert_false(instance.matches(':defined'));
    89     assert_false(matchInsideConstructor,
     97    assert_false(!!instance.matchInsideConstructor,
    9098        'Creating a custom element must leave the defined flag unset when synchronous custom elements flag is not set');
    9199}, 'The defined flag of a custom element must be set after checking the returned result is an instance of HTMLElement when upgrading a custom element');
     100
     101test(function () {
     102    var matchInsideConstructor = false;
     103    customElements.define('throws-exception', class extends HTMLElement {
     104        constructor() {
     105            super();
     106            matchInsideConstructor = this.matches(':defined');
     107            throw {name: 'bad'};
     108        }
     109    });
     110    var instance;
     111    assert_throws({name: 'bad'}, function () { instance = document.createElement('throws-exception'); });
     112    assert_true(matchInsideConstructor);
     113}, 'The defined flag of a custom element must be set inside a constructor when constructing a custom element synchronously'
     114    + ' even if the constructor threw an exception later');
     115
     116test(function () {
     117    var instance = document.createElement('throws-exception-2');
     118    document.body.appendChild(instance);
     119    assert_throws({name: 'bad'}, function () {
     120        customElements.define('throws-exception-2', class extends HTMLElement {
     121            constructor() {
     122                throw {name: 'bad'};
     123            }
     124        });
     125    });
     126    assert_false(instance.matches(':defined'));
     127}, 'The defined flag of a custom element must not be set when an upgrade of a custom element fails');
    92128
    93129</script>
  • trunk/LayoutTests/fast/custom-elements/defined-rule.html

    r204367 r205416  
    2222        my-undefined-element:not(:defined) { color: green; }
    2323
    24         div.box { background: green; color: red; height: 50px; }
     24        failed-element { background: green; color: red; }
     25        failed-element:defined { background: red; }
     26        failed-element:not(:defined) { color: green; }
     27
     28        div.box { background: green; color: red; }
    2529        div:defined { color: green; }
    2630        div:not(:defined) { background: red; }
     
    2933    <my-defined-element class="box">FAIL</my-defined-element>
    3034    <my-undefined-element class="box">FAIL</my-undefined-element>
     35    <failed-element class="box">FAIL</failed-element>
    3136    <div class="box"></div>
    3237    <script>
    3338
    3439        customElements.define('my-defined-element', class extends HTMLElement {});
     40        customElements.define('failed-element', class extends HTMLElement {
     41            constructor() { throw 'bad'; }
     42        });
    3543
    3644    </script>
  • trunk/LayoutTests/fast/custom-elements/upgrading/Node-cloneNode-expected.txt

    r197634 r205416  
    77PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call
    88PASS Upgrading a custom element must throw InvalidStateError when the custom element's constructor returns another element
     9PASS Inserting an element must not try to upgrade a custom element when it had already failed to upgrade once
    910
  • trunk/LayoutTests/fast/custom-elements/upgrading/Node-cloneNode.html

    r204367 r205416  
    165165}, 'Upgrading a custom element must throw InvalidStateError when the custom element\'s constructor returns another element');
    166166
     167test(function () {
     168    withNewDocumentWithABrowsingContext(function (contentWindow, contentDocument) {
     169
     170        var instance = contentDocument.createElement('my-custom-element');
     171        contentDocument.body.appendChild(instance);
     172
     173        var calls = [];
     174        class MyCustomElement extends contentWindow.HTMLElement {
     175            constructor() {
     176                super();
     177                calls.push(this);
     178                throw 'bad';
     179            }
     180        }
     181
     182        try {
     183            contentWindow.customElements.define('my-custom-element', MyCustomElement);
     184        } catch (e) { }
     185
     186        assert_array_equals(calls, [instance]);
     187        contentDocument.body.removeChild(instance);
     188        contentDocument.body.appendChild(instance);
     189        assert_array_equals(calls, [instance]);
     190
     191    });
     192}, 'Inserting an element must not try to upgrade a custom element when it had already failed to upgrade once');
     193
    167194</script>
    168195</body>
  • trunk/Source/WebCore/ChangeLog

    r205412 r205416  
     12016-09-03  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Update the semantics of defined-ness of custom elements per spec changes
     4        https://bugs.webkit.org/show_bug.cgi?id=161570
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch adds the notion of a custom element that failed to construct or upgrade so that :defined
     9        doesn't apply to such an element. We also set the defined flag inside the HTMLElement constructor in
     10        the case of synchronous construction instead of waiting for the custom element constructor to finish.
     11        https://dom.spec.whatwg.org/#concept-create-element
     12
     13        Conceptually, there are four distinct states for an element:
     14        1. The element is a built-in element
     15        2. The element is a custom element yet to be defined (an upgrade candidate).
     16        3. The element is a well-defined custom element (constructed or upgraded).
     17        4. The element has failed to construct or upgrade as a custom element (because the custom element
     18        constructor threw an exception or returned an unexpected object).
     19
     20        In the latest DOM/HTML specifications, these states are called as 1. "uncustomized", 2. "undefined",
     21        3. "custom", and 4. "failed": https://dom.spec.whatwg.org/#concept-element-defined
     22
     23        This patch refactors Node flags to introduce these distinct states as the following:
     24        1. Neither IsCustomElement nor IsEditingTextOrUnresolvedCustomElementFlag is set.
     25        2. IsCustomElement and IsEditingTextOrUnresolvedCustomElementFlag are set.
     26        isCustomElementUpgradeCandidate() and isUndefinedCustomElement() return true.
     27        3. IsCustomElement is set and IsEditingTextOrUnresolvedCustomElementFlag is unset.
     28        isDefinedCustomElement() returns true.
     29        4. IsCustomElement is unset and IsEditingTextOrUnresolvedCustomElementFlag is set.
     30        isFailedCustomElement() and isUndefinedCustomElement() return true.
     31
     32        Per a spec change, this patch also makes :defined applied to a synchronously constructed custom element
     33        immediately after super() call in the constructor. When the constructor throws an exception or fails to
     34        return the right element, the HTML parser marks the fallback element with setIsUndefinedCustomElement.
     35
     36        Tests: fast/custom-elements/defined-pseudo-class.html
     37               fast/custom-elements/defined-rule.html
     38               fast/custom-elements/upgrading/Node-cloneNode.html
     39
     40        * bindings/js/JSCustomElementInterface.cpp:
     41        (WebCore::JSCustomElementInterface::constructElement): Don't set :defined flag here since that's done
     42        in the HTMLElement constructor now.
     43        (WebCore::JSCustomElementInterface::upgradeElement): Mark the element as failed-to-upgrade as needed.
     44        * bindings/js/JSElementCustom.cpp:
     45        (WebCore::toJSNewlyCreated):
     46        * bindings/js/JSHTMLElementCustom.cpp:
     47        (WebCore::constructJSHTMLElement):
     48        * css/SelectorCheckerTestFunctions.h:
     49        (WebCore::isDefinedElement):
     50        * dom/CustomElementReactionQueue.cpp:
     51        (WebCore::CustomElementReactionQueue::enqueueElementUpgradeIfDefined): Enqueue custom element reactions
     52        only if the element is well defined (successfully constructed or upgraded).
     53        (WebCore::CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded): Ditto.
     54        (WebCore::CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded): Ditto.
     55        (WebCore::CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded): Ditto.
     56        (WebCore::CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded): Ditto.
     57        * dom/CustomElementRegistry.cpp:
     58        (WebCore::enqueueUpgradeInShadowIncludingTreeOrder):
     59        * dom/Document.cpp:
     60        (WebCore::createUpgradeCandidateElement):
     61        (WebCore::createFallbackHTMLElement):
     62        * dom/Element.cpp:
     63        (WebCore::Element::attributeChanged):
     64        (WebCore::Element::didMoveToNewDocument):
     65        (WebCore::Element::insertedInto):
     66        (WebCore::Element::removedFrom):
     67        (WebCore::Element::setCustomElementIsResolved): Deleted.
     68        (WebCore::Element::setIsDefinedCustomElement): Renamed from setCustomElementIsResolved.
     69        (WebCore::Element::setIsFailedCustomElement): Added.
     70        (WebCore::Element::setIsCustomElementUpgradeCandidate): Added.
     71        (WebCore::Element::customElementInterface):
     72        * dom/Element.h:
     73        * dom/Node.h:
     74        (WebCore::Node::setIsCustomElement): Deleted.
     75        (WebCore::Node::isUndefinedCustomElement): Renamed from isUnresolvedCustomElement.
     76        (WebCore::Node::setIsUnresolvedCustomElement): Deleted.
     77        (WebCore::Node::isCustomElementUpgradeCandidate): Added.
     78        (WebCore::Node::isDefinedCustomElement): Renamed from isCustomElement.
     79        (WebCore::Node::isFailedCustomElement): Added.
     80        * dom/make_names.pl:
     81        (printWrapperFactoryCppFile): Use the HTMLElement wrapper on upgrade candidates. When a custom element
     82        failed to upgrade, the HTMLElement constructor would have created the wrapper so we never run this code.
     83        * html/parser/HTMLConstructionSite.cpp:
     84        (WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):
     85        * html/parser/HTMLDocumentParser.cpp:
     86        (WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder): Mark the HTMLUnknownElement created when
     87        the custom element constructor failed to run successfully as a failed custom element so that :define
     88        wouldn't apply to this element.
     89
    1902016-09-03  Wenson Hsieh  <wenson_hsieh@apple.com>
    291
  • trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp

    r205386 r205416  
    9090    }
    9191
    92     element->setCustomElementIsResolved(*this);
    9392    return element;
    9493}
     
    150149{
    151150    ASSERT(element.tagQName() == name());
    152     ASSERT(element.isUnresolvedCustomElement());
     151    ASSERT(element.isCustomElementUpgradeCandidate());
    153152    if (!canInvokeCallback())
    154153        return;
     
    187186    m_constructionStack.removeLast();
    188187
    189     if (state->hadException())
    190         return;
     188    if (state->hadException()) {
     189        element.setIsFailedCustomElement(*this);
     190        return;
     191    }
    191192
    192193    Element* wrappedElement = JSElement::toWrapped(returnedElement);
    193194    if (!wrappedElement || wrappedElement != &element) {
     195        element.setIsFailedCustomElement(*this);
    194196        throwInvalidStateError(*state, scope, "Custom element constructor failed to upgrade an element");
    195197        return;
    196198    }
    197     wrappedElement->setCustomElementIsResolved(*this);
     199    element.setIsDefinedCustomElement(*this);
    198200}
    199201
  • trunk/Source/WebCore/bindings/js/JSElementCustom.cpp

    r200934 r205416  
    6969{
    7070#if ENABLE(CUSTOM_ELEMENTS)
    71     if (element->isCustomElement())
     71    if (element->isDefinedCustomElement())
    7272        return getCachedWrapper(globalObject->world(), element);
    7373#endif
  • trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp

    r205263 r205416  
    8383
    8484        Ref<HTMLElement> element = HTMLElement::create(elementInterface->name(), document);
    85         element->setIsUnresolvedCustomElement();
     85        element->setIsDefinedCustomElement(*elementInterface);
    8686        auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get());
    8787        cacheWrapper(globalObject->world(), element.ptr(), jsElement);
  • trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h

    r205050 r205416  
    6767ALWAYS_INLINE bool isDefinedElement(const Element& element)
    6868{
    69     return !element.isUnresolvedCustomElement();
     69    return !element.isUndefinedCustomElement();
    7070}
    7171#endif
  • trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp

    r205340 r205416  
    125125{
    126126    ASSERT(element.inDocument());
    127     ASSERT(element.isUnresolvedCustomElement());
     127    ASSERT(element.isCustomElementUpgradeCandidate());
    128128    auto* window = element.document().domWindow();
    129129    if (!window)
     
    143143void CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(Element& element)
    144144{
    145     ASSERT(element.isCustomElement());
     145    ASSERT(element.isDefinedCustomElement());
    146146    auto* elementInterface = element.customElementInterface();
    147147    ASSERT(elementInterface);
     
    155155void CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded(Element& element)
    156156{
    157     ASSERT(element.isCustomElement());
     157    ASSERT(element.isDefinedCustomElement());
    158158    auto* elementInterface = element.customElementInterface();
    159159    ASSERT(elementInterface);
     
    167167void CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(Element& element, Document& oldDocument, Document& newDocument)
    168168{
    169     ASSERT(element.isCustomElement());
     169    ASSERT(element.isDefinedCustomElement());
    170170    auto* elementInterface = element.customElementInterface();
    171171    ASSERT(elementInterface);
     
    179179void CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(Element& element, const QualifiedName& attributeName, const AtomicString& oldValue, const AtomicString& newValue)
    180180{
    181     ASSERT(element.isCustomElement());
     181    ASSERT(element.isDefinedCustomElement());
    182182    auto* elementInterface = element.customElementInterface();
    183183    ASSERT(elementInterface);
  • trunk/Source/WebCore/dom/CustomElementRegistry.cpp

    r205410 r205416  
    6161{
    6262    for (Element* element = ElementTraversal::firstWithin(node); element; element = ElementTraversal::next(*element)) {
    63         if (element->isUnresolvedCustomElement() && element->tagQName() == elementInterface.name())
     63        if (element->isCustomElementUpgradeCandidate() && element->tagQName() == elementInterface.name())
    6464            CustomElementReactionQueue::enqueueElementUpgrade(*element, elementInterface);
    6565        if (auto* shadowRoot = element->shadowRoot()) {
  • trunk/Source/WebCore/dom/Document.cpp

    r205411 r205416  
    891891
    892892    auto element = HTMLElement::create(name, document);
    893     element->setIsUnresolvedCustomElement();
     893    element->setIsCustomElementUpgradeCandidate();
    894894    return WTFMove(element);
    895895}
     
    10921092            if (auto* elementInterface = registry->findInterface(name)) {
    10931093                auto element = HTMLElement::create(name, document);
    1094                 element->setIsUnresolvedCustomElement();
     1094                element->setIsCustomElementUpgradeCandidate();
    10951095                CustomElementReactionQueue::enqueueElementUpgrade(element.get(), *elementInterface);
    10961096                return element;
  • trunk/Source/WebCore/dom/Element.cpp

    r205340 r205416  
    12961296
    12971297#if ENABLE(CUSTOM_ELEMENTS)
    1298     if (UNLIKELY(isCustomElement()))
     1298    if (UNLIKELY(isDefinedCustomElement()))
    12991299        CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(*this, name, oldValue, newValue);
    13001300#endif
     
    14961496
    14971497#if ENABLE(CUSTOM_ELEMENTS)
    1498     if (UNLIKELY(isCustomElement()))
     1498    if (UNLIKELY(isDefinedCustomElement()))
    14991499        CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(*this, *oldDocument, document());
    15001500#endif
     
    16081608#if ENABLE(CUSTOM_ELEMENTS)
    16091609    if (becomeConnected) {
    1610         if (UNLIKELY(isUnresolvedCustomElement()))
     1610        if (UNLIKELY(isCustomElementUpgradeCandidate()))
    16111611            CustomElementReactionQueue::enqueueElementUpgradeIfDefined(*this);
    1612         if (UNLIKELY(isCustomElement()))
     1612        if (UNLIKELY(isDefinedCustomElement()))
    16131613            CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(*this);
    16141614    }
     
    16641664
    16651665#if ENABLE(CUSTOM_ELEMENTS)
    1666         if (becomeDisconnected && UNLIKELY(isCustomElement()))
     1666        if (becomeDisconnected && UNLIKELY(isDefinedCustomElement()))
    16671667            CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded(*this);
    16681668#endif
     
    18371837#if ENABLE(CUSTOM_ELEMENTS)
    18381838
    1839 void Element::setCustomElementIsResolved(JSCustomElementInterface& elementInterface)
    1840 {
    1841     clearFlag(IsEditingTextOrUnresolvedCustomElementFlag);
     1839void Element::setIsDefinedCustomElement(JSCustomElementInterface& elementInterface)
     1840{
     1841    clearFlag(IsEditingTextOrUndefinedCustomElementFlag);
    18421842    setFlag(IsCustomElement);
    18431843    ensureElementRareData().setCustomElementInterface(elementInterface);
    18441844}
    18451845
     1846void Element::setIsFailedCustomElement(JSCustomElementInterface& elementInterface)
     1847{
     1848    ASSERT(isUndefinedCustomElement());
     1849    ASSERT(getFlag(IsEditingTextOrUndefinedCustomElementFlag));
     1850    clearFlag(IsCustomElement);
     1851    ensureElementRareData().setCustomElementInterface(elementInterface);
     1852}
     1853
     1854void Element::setIsCustomElementUpgradeCandidate()
     1855{
     1856    ASSERT(!getFlag(IsCustomElement));
     1857    setFlag(IsCustomElement);
     1858    setFlag(IsEditingTextOrUndefinedCustomElementFlag);
     1859}
     1860
    18461861JSCustomElementInterface* Element::customElementInterface() const
    18471862{
    1848     ASSERT(isCustomElement());
     1863    ASSERT(isDefinedCustomElement());
    18491864    if (!hasRareData())
    18501865        return nullptr;
  • trunk/Source/WebCore/dom/Element.h

    r205249 r205416  
    275275
    276276#if ENABLE(CUSTOM_ELEMENTS)
    277     void setCustomElementIsResolved(JSCustomElementInterface&);
     277    void setIsDefinedCustomElement(JSCustomElementInterface&);
     278    void setIsFailedCustomElement(JSCustomElementInterface&);
     279    void setIsCustomElementUpgradeCandidate();
    278280    JSCustomElementInterface* customElementInterface() const;
    279281#endif
  • trunk/Source/WebCore/dom/Node.h

    r205249 r205416  
    263263
    264264#if ENABLE(CUSTOM_ELEMENTS)
    265     bool isCustomElement() const { return getFlag(IsCustomElement); }
    266     void setIsCustomElement() { setFlag(IsCustomElement); }
    267 
    268     bool isUnresolvedCustomElement() const { return isElementNode() && getFlag(IsEditingTextOrUnresolvedCustomElementFlag); }
    269     void setIsUnresolvedCustomElement() { setFlag(IsEditingTextOrUnresolvedCustomElementFlag); }
     265    bool isUndefinedCustomElement() const { return isElementNode() && getFlag(IsEditingTextOrUndefinedCustomElementFlag); }
     266    bool isCustomElementUpgradeCandidate() const { return getFlag(IsCustomElement) && getFlag(IsEditingTextOrUndefinedCustomElementFlag); }
     267    bool isDefinedCustomElement() const { return getFlag(IsCustomElement) && !getFlag(IsEditingTextOrUndefinedCustomElementFlag); }
     268    bool isFailedCustomElement() const { return isElementNode() && !getFlag(IsCustomElement) && getFlag(IsEditingTextOrUndefinedCustomElementFlag); }
    270269#endif
    271270
     
    322321    bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); }
    323322    bool styleIsAffectedByPreviousSibling() const { return getFlag(StyleIsAffectedByPreviousSibling); }
    324     bool isEditingText() const { return getFlag(IsTextFlag) && getFlag(IsEditingTextOrUnresolvedCustomElementFlag); }
     323    bool isEditingText() const { return getFlag(IsTextFlag) && getFlag(IsEditingTextOrUndefinedCustomElementFlag); }
    325324
    326325    void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
     
    595594
    596595        StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1) | 1 << (nodeStyleChangeShift + 2),
    597         IsEditingTextOrUnresolvedCustomElementFlag = 1 << 17,
     596        IsEditingTextOrUndefinedCustomElementFlag = 1 << 17,
    598597        HasFocusWithin = 1 << 18,
    599598        HasSyntheticAttrChildNodesFlag = 1 << 19,
     
    634633        CreateSVGElement = CreateStyledElement | IsSVGFlag | HasCustomStyleResolveCallbacksFlag,
    635634        CreateDocument = CreateContainer | InDocumentFlag,
    636         CreateEditingText = CreateText | IsEditingTextOrUnresolvedCustomElementFlag,
     635        CreateEditingText = CreateText | IsEditingTextOrUndefinedCustomElementFlag,
    637636        CreateMathMLElement = CreateStyledElement | IsMathMLFlag
    638637    };
  • trunk/Source/WebCore/dom/make_names.pl

    r200934 r205416  
    13241324        print F <<END
    13251325#if ENABLE(CUSTOM_ELEMENTS)
    1326     if (element->isUnresolvedCustomElement())
     1326    if (element->isCustomElementUpgradeCandidate())
    13271327        return CREATE_DOM_WRAPPER(globalObject, $parameters{customElementInterfaceName}, WTFMove(element));
    13281328#endif
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r205340 r205416  
    678678        if (window && Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid) {
    679679            element = HTMLElement::create(qualifiedName, ownerDocument);
    680             element->setIsUnresolvedCustomElement();
     680            element->setIsCustomElementUpgradeCandidate();
    681681        } else
    682682#endif
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r205218 r205416  
    196196        ASSERT(!m_treeBuilder->hasParserBlockingScriptWork());
    197197
    198         RefPtr<Element> newElement = constructionData->elementInterface->constructElement(constructionData->name, JSCustomElementInterface::ShouldClearException::Clear);
     198        // https://html.spec.whatwg.org/#create-an-element-for-the-token
     199        auto& elementInterface = constructionData->elementInterface.get();
     200        RefPtr<Element> newElement = elementInterface.constructElement(constructionData->name, JSCustomElementInterface::ShouldClearException::Clear);
    199201        if (!newElement) {
    200202            ASSERT(!m_treeBuilder->isParsingTemplateContents());
    201203            newElement = HTMLUnknownElement::create(QualifiedName(nullAtom, constructionData->name, xhtmlNamespaceURI), *document());
     204            newElement->setIsCustomElementUpgradeCandidate();
     205            newElement->setIsFailedCustomElement(elementInterface);
    202206        }
    203207
Note: See TracChangeset for help on using the changeset viewer.