Changeset 205416 in webkit
- Timestamp:
- Sep 3, 2016 10:09:28 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r205410 r205416 1 2016-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 1 23 2016-09-03 Ryosuke Niwa <rniwa@webkit.org> 2 24 -
trunk/LayoutTests/fast/custom-elements/defined-pseudo-class-expected.txt
r205386 r205416 1 CONSOLE MESSAGE: line 7 5: TypeError: The result of constructing a custom element must be a HTMLElement1 CONSOLE MESSAGE: line 79: TypeError: The result of constructing a custom element must be a HTMLElement 2 2 3 3 Harness Error (FAIL), message = TypeError: The result of constructing a custom element must be a HTMLElement … … 6 6 PASS 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 7 7 PASS 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 i f there is a matching definition8 PASS The defined flag of a custom element must be set inside the HTMLElement constructor 9 9 PASS The defined flag of an upgraded custom element must be set 10 10 PASS The defined flag of a custom element created by HTML parser must be unset if there is no matching definition 11 11 PASS 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 HTMLElement12 PASS The element inserted by HTML parser must not have the defined flag set if the constructor returns a Text node 13 13 PASS 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 14 PASS 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 15 PASS The defined flag of a custom element must not be set when an upgrade of a custom element fails 14 16 -
trunk/LayoutTests/fast/custom-elements/defined-pseudo-class.html
r205340 r205416 19 19 }, 'The defined flag of a custom element must not be set if a custom element has not been upgraded yet'); 20 20 21 var matchInsideConstructor;22 21 class MyElement extends HTMLElement { 23 22 constructor() { 24 23 super(); 25 matchInsideConstructor = this.matches(':defined');24 this.matchInsideConstructor = this.matches(':defined'); 26 25 } 27 26 } 27 28 28 customElements.define('my-element', MyElement); 29 29 … … 35 35 document.body.appendChild(upgradeCandidate); 36 36 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'); 38 38 }, 'The defined flag of a custom element must be set when a custom element is successfully upgraded'); 39 39 … … 41 41 var definedElement = document.createElement('my-element'); 42 42 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 i f 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'); 45 45 46 46 test(function () { 47 47 var upgradedElement = document.createElement('my-element').cloneNode(true); 48 48 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'); 50 50 }, 'The defined flag of an upgraded custom element must be set'); 51 51 … … 55 55 var parserCreatedUnfefinedElement = document.querySelector('my-other-element'); 56 56 assert_false(parserCreatedUnfefinedElement.matches(':defined')); 57 assert_false(!!parserCreatedUnfefinedElement.matchInsideConstructor); 57 58 }, 'The defined flag of a custom element created by HTML parser must be unset if there is no matching definition'); 58 59 59 document.write('<my-element ></my-element>');60 document.write('<my-element id="parser-created-defined-element"></my-element>'); 60 61 61 62 test(function () { 62 var parserCreatedDefinedElement = document. querySelector('my-element');63 var parserCreatedDefinedElement = document.getElementById('parser-created-defined-element'); 63 64 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'); 64 67 }, 'The defined flag of a custom element created by HTML parser must be set if there is a matching definition'); 65 68 … … 67 70 constructor() { 68 71 super(); 69 matchInsideConstructor = this.matches(':defined'); 72 this.matchInsideConstructor = this.matches(':defined'); 73 ReturnsAnotherNode.lastInstance = this; 70 74 return document.createTextNode(''); 71 75 } … … 76 80 77 81 test(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'); 82 90 83 91 test(function () { … … 87 95 } catch (e) { } 88 96 assert_false(instance.matches(':defined')); 89 assert_false( matchInsideConstructor,97 assert_false(!!instance.matchInsideConstructor, 90 98 'Creating a custom element must leave the defined flag unset when synchronous custom elements flag is not set'); 91 99 }, '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 101 test(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 116 test(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'); 92 128 93 129 </script> -
trunk/LayoutTests/fast/custom-elements/defined-rule.html
r204367 r205416 22 22 my-undefined-element:not(:defined) { color: green; } 23 23 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; } 25 29 div:defined { color: green; } 26 30 div:not(:defined) { background: red; } … … 29 33 <my-defined-element class="box">FAIL</my-defined-element> 30 34 <my-undefined-element class="box">FAIL</my-undefined-element> 35 <failed-element class="box">FAIL</failed-element> 31 36 <div class="box"></div> 32 37 <script> 33 38 34 39 customElements.define('my-defined-element', class extends HTMLElement {}); 40 customElements.define('failed-element', class extends HTMLElement { 41 constructor() { throw 'bad'; } 42 }); 35 43 36 44 </script> -
trunk/LayoutTests/fast/custom-elements/upgrading/Node-cloneNode-expected.txt
r197634 r205416 7 7 PASS 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 8 8 PASS Upgrading a custom element must throw InvalidStateError when the custom element's constructor returns another element 9 PASS Inserting an element must not try to upgrade a custom element when it had already failed to upgrade once 9 10 -
trunk/LayoutTests/fast/custom-elements/upgrading/Node-cloneNode.html
r204367 r205416 165 165 }, 'Upgrading a custom element must throw InvalidStateError when the custom element\'s constructor returns another element'); 166 166 167 test(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 167 194 </script> 168 195 </body> -
trunk/Source/WebCore/ChangeLog
r205412 r205416 1 2016-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 1 90 2016-09-03 Wenson Hsieh <wenson_hsieh@apple.com> 2 91 -
trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp
r205386 r205416 90 90 } 91 91 92 element->setCustomElementIsResolved(*this);93 92 return element; 94 93 } … … 150 149 { 151 150 ASSERT(element.tagQName() == name()); 152 ASSERT(element.is UnresolvedCustomElement());151 ASSERT(element.isCustomElementUpgradeCandidate()); 153 152 if (!canInvokeCallback()) 154 153 return; … … 187 186 m_constructionStack.removeLast(); 188 187 189 if (state->hadException()) 190 return; 188 if (state->hadException()) { 189 element.setIsFailedCustomElement(*this); 190 return; 191 } 191 192 192 193 Element* wrappedElement = JSElement::toWrapped(returnedElement); 193 194 if (!wrappedElement || wrappedElement != &element) { 195 element.setIsFailedCustomElement(*this); 194 196 throwInvalidStateError(*state, scope, "Custom element constructor failed to upgrade an element"); 195 197 return; 196 198 } 197 wrappedElement->setCustomElementIsResolved(*this);199 element.setIsDefinedCustomElement(*this); 198 200 } 199 201 -
trunk/Source/WebCore/bindings/js/JSElementCustom.cpp
r200934 r205416 69 69 { 70 70 #if ENABLE(CUSTOM_ELEMENTS) 71 if (element->is CustomElement())71 if (element->isDefinedCustomElement()) 72 72 return getCachedWrapper(globalObject->world(), element); 73 73 #endif -
trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
r205263 r205416 83 83 84 84 Ref<HTMLElement> element = HTMLElement::create(elementInterface->name(), document); 85 element->setIs UnresolvedCustomElement();85 element->setIsDefinedCustomElement(*elementInterface); 86 86 auto* jsElement = JSHTMLElement::create(newElementStructure, globalObject, element.get()); 87 87 cacheWrapper(globalObject->world(), element.ptr(), jsElement); -
trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h
r205050 r205416 67 67 ALWAYS_INLINE bool isDefinedElement(const Element& element) 68 68 { 69 return !element.isUn resolvedCustomElement();69 return !element.isUndefinedCustomElement(); 70 70 } 71 71 #endif -
trunk/Source/WebCore/dom/CustomElementReactionQueue.cpp
r205340 r205416 125 125 { 126 126 ASSERT(element.inDocument()); 127 ASSERT(element.is UnresolvedCustomElement());127 ASSERT(element.isCustomElementUpgradeCandidate()); 128 128 auto* window = element.document().domWindow(); 129 129 if (!window) … … 143 143 void CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(Element& element) 144 144 { 145 ASSERT(element.is CustomElement());145 ASSERT(element.isDefinedCustomElement()); 146 146 auto* elementInterface = element.customElementInterface(); 147 147 ASSERT(elementInterface); … … 155 155 void CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded(Element& element) 156 156 { 157 ASSERT(element.is CustomElement());157 ASSERT(element.isDefinedCustomElement()); 158 158 auto* elementInterface = element.customElementInterface(); 159 159 ASSERT(elementInterface); … … 167 167 void CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(Element& element, Document& oldDocument, Document& newDocument) 168 168 { 169 ASSERT(element.is CustomElement());169 ASSERT(element.isDefinedCustomElement()); 170 170 auto* elementInterface = element.customElementInterface(); 171 171 ASSERT(elementInterface); … … 179 179 void CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(Element& element, const QualifiedName& attributeName, const AtomicString& oldValue, const AtomicString& newValue) 180 180 { 181 ASSERT(element.is CustomElement());181 ASSERT(element.isDefinedCustomElement()); 182 182 auto* elementInterface = element.customElementInterface(); 183 183 ASSERT(elementInterface); -
trunk/Source/WebCore/dom/CustomElementRegistry.cpp
r205410 r205416 61 61 { 62 62 for (Element* element = ElementTraversal::firstWithin(node); element; element = ElementTraversal::next(*element)) { 63 if (element->is UnresolvedCustomElement() && element->tagQName() == elementInterface.name())63 if (element->isCustomElementUpgradeCandidate() && element->tagQName() == elementInterface.name()) 64 64 CustomElementReactionQueue::enqueueElementUpgrade(*element, elementInterface); 65 65 if (auto* shadowRoot = element->shadowRoot()) { -
trunk/Source/WebCore/dom/Document.cpp
r205411 r205416 891 891 892 892 auto element = HTMLElement::create(name, document); 893 element->setIs UnresolvedCustomElement();893 element->setIsCustomElementUpgradeCandidate(); 894 894 return WTFMove(element); 895 895 } … … 1092 1092 if (auto* elementInterface = registry->findInterface(name)) { 1093 1093 auto element = HTMLElement::create(name, document); 1094 element->setIs UnresolvedCustomElement();1094 element->setIsCustomElementUpgradeCandidate(); 1095 1095 CustomElementReactionQueue::enqueueElementUpgrade(element.get(), *elementInterface); 1096 1096 return element; -
trunk/Source/WebCore/dom/Element.cpp
r205340 r205416 1296 1296 1297 1297 #if ENABLE(CUSTOM_ELEMENTS) 1298 if (UNLIKELY(is CustomElement()))1298 if (UNLIKELY(isDefinedCustomElement())) 1299 1299 CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded(*this, name, oldValue, newValue); 1300 1300 #endif … … 1496 1496 1497 1497 #if ENABLE(CUSTOM_ELEMENTS) 1498 if (UNLIKELY(is CustomElement()))1498 if (UNLIKELY(isDefinedCustomElement())) 1499 1499 CustomElementReactionQueue::enqueueAdoptedCallbackIfNeeded(*this, *oldDocument, document()); 1500 1500 #endif … … 1608 1608 #if ENABLE(CUSTOM_ELEMENTS) 1609 1609 if (becomeConnected) { 1610 if (UNLIKELY(is UnresolvedCustomElement()))1610 if (UNLIKELY(isCustomElementUpgradeCandidate())) 1611 1611 CustomElementReactionQueue::enqueueElementUpgradeIfDefined(*this); 1612 if (UNLIKELY(is CustomElement()))1612 if (UNLIKELY(isDefinedCustomElement())) 1613 1613 CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded(*this); 1614 1614 } … … 1664 1664 1665 1665 #if ENABLE(CUSTOM_ELEMENTS) 1666 if (becomeDisconnected && UNLIKELY(is CustomElement()))1666 if (becomeDisconnected && UNLIKELY(isDefinedCustomElement())) 1667 1667 CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded(*this); 1668 1668 #endif … … 1837 1837 #if ENABLE(CUSTOM_ELEMENTS) 1838 1838 1839 void Element::set CustomElementIsResolved(JSCustomElementInterface& elementInterface)1840 { 1841 clearFlag(IsEditingTextOrUn resolvedCustomElementFlag);1839 void Element::setIsDefinedCustomElement(JSCustomElementInterface& elementInterface) 1840 { 1841 clearFlag(IsEditingTextOrUndefinedCustomElementFlag); 1842 1842 setFlag(IsCustomElement); 1843 1843 ensureElementRareData().setCustomElementInterface(elementInterface); 1844 1844 } 1845 1845 1846 void Element::setIsFailedCustomElement(JSCustomElementInterface& elementInterface) 1847 { 1848 ASSERT(isUndefinedCustomElement()); 1849 ASSERT(getFlag(IsEditingTextOrUndefinedCustomElementFlag)); 1850 clearFlag(IsCustomElement); 1851 ensureElementRareData().setCustomElementInterface(elementInterface); 1852 } 1853 1854 void Element::setIsCustomElementUpgradeCandidate() 1855 { 1856 ASSERT(!getFlag(IsCustomElement)); 1857 setFlag(IsCustomElement); 1858 setFlag(IsEditingTextOrUndefinedCustomElementFlag); 1859 } 1860 1846 1861 JSCustomElementInterface* Element::customElementInterface() const 1847 1862 { 1848 ASSERT(is CustomElement());1863 ASSERT(isDefinedCustomElement()); 1849 1864 if (!hasRareData()) 1850 1865 return nullptr; -
trunk/Source/WebCore/dom/Element.h
r205249 r205416 275 275 276 276 #if ENABLE(CUSTOM_ELEMENTS) 277 void setCustomElementIsResolved(JSCustomElementInterface&); 277 void setIsDefinedCustomElement(JSCustomElementInterface&); 278 void setIsFailedCustomElement(JSCustomElementInterface&); 279 void setIsCustomElementUpgradeCandidate(); 278 280 JSCustomElementInterface* customElementInterface() const; 279 281 #endif -
trunk/Source/WebCore/dom/Node.h
r205249 r205416 263 263 264 264 #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); } 270 269 #endif 271 270 … … 322 321 bool childNeedsStyleRecalc() const { return getFlag(ChildNeedsStyleRecalcFlag); } 323 322 bool styleIsAffectedByPreviousSibling() const { return getFlag(StyleIsAffectedByPreviousSibling); } 324 bool isEditingText() const { return getFlag(IsTextFlag) && getFlag(IsEditingTextOrUn resolvedCustomElementFlag); }323 bool isEditingText() const { return getFlag(IsTextFlag) && getFlag(IsEditingTextOrUndefinedCustomElementFlag); } 325 324 326 325 void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); } … … 595 594 596 595 StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1) | 1 << (nodeStyleChangeShift + 2), 597 IsEditingTextOrUn resolvedCustomElementFlag = 1 << 17,596 IsEditingTextOrUndefinedCustomElementFlag = 1 << 17, 598 597 HasFocusWithin = 1 << 18, 599 598 HasSyntheticAttrChildNodesFlag = 1 << 19, … … 634 633 CreateSVGElement = CreateStyledElement | IsSVGFlag | HasCustomStyleResolveCallbacksFlag, 635 634 CreateDocument = CreateContainer | InDocumentFlag, 636 CreateEditingText = CreateText | IsEditingTextOrUn resolvedCustomElementFlag,635 CreateEditingText = CreateText | IsEditingTextOrUndefinedCustomElementFlag, 637 636 CreateMathMLElement = CreateStyledElement | IsMathMLFlag 638 637 }; -
trunk/Source/WebCore/dom/make_names.pl
r200934 r205416 1324 1324 print F <<END 1325 1325 #if ENABLE(CUSTOM_ELEMENTS) 1326 if (element->is UnresolvedCustomElement())1326 if (element->isCustomElementUpgradeCandidate()) 1327 1327 return CREATE_DOM_WRAPPER(globalObject, $parameters{customElementInterfaceName}, WTFMove(element)); 1328 1328 #endif -
trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp
r205340 r205416 678 678 if (window && Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid) { 679 679 element = HTMLElement::create(qualifiedName, ownerDocument); 680 element->setIs UnresolvedCustomElement();680 element->setIsCustomElementUpgradeCandidate(); 681 681 } else 682 682 #endif -
trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp
r205218 r205416 196 196 ASSERT(!m_treeBuilder->hasParserBlockingScriptWork()); 197 197 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); 199 201 if (!newElement) { 200 202 ASSERT(!m_treeBuilder->isParsingTemplateContents()); 201 203 newElement = HTMLUnknownElement::create(QualifiedName(nullAtom, constructionData->name, xhtmlNamespaceURI), *document()); 204 newElement->setIsCustomElementUpgradeCandidate(); 205 newElement->setIsFailedCustomElement(elementInterface); 202 206 } 203 207
Note: See TracChangeset
for help on using the changeset viewer.