WebKit Bugzilla
Attachment 346146 Details for
Bug 188190
: XML Parser should invoke reactions when creating/inserting new custom elements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP Patch
188190.patch (text/plain), 10.18 KB, created by
Frédéric Wang (:fredw)
on 2018-07-31 00:44:43 PDT
(
hide
)
Description:
WIP Patch
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2018-07-31 00:44:43 PDT
Size:
10.18 KB
patch
obsolete
>diff --git a/LayoutTests/TestExpectations b/LayoutTests/TestExpectations >index 2c7f6dc1be9..95657659aa4 100644 >--- a/LayoutTests/TestExpectations >+++ b/LayoutTests/TestExpectations >@@ -570,7 +570,7 @@ imported/w3c/web-platform-tests/html/semantics/document-metadata/the-meta-elemen > > # WPT tests for custom elements > webkit.org/b/187800 imported/w3c/web-platform-tests/custom-elements/Document-createElement-svg.svg [ Skip ] >-webkit.org/b/187802 imported/w3c/web-platform-tests/custom-elements/parser/parser-uses-create-an-element-for-a-token-svg.svg [ Skip ] >+webkit.org/b/187800 imported/w3c/web-platform-tests/custom-elements/parser/parser-uses-create-an-element-for-a-token-svg.svg [ Skip ] > webkit.org/b/187805 imported/w3c/web-platform-tests/custom-elements/reactions/with-exceptions.html [ Skip ] > > # selectors >diff --git a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/parser/parser-sets-attributes-and-children-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/parser/parser-sets-attributes-and-children-expected.txt >index e2317aa63f7..bc0c300e768 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/parser/parser-sets-attributes-and-children-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/parser/parser-sets-attributes-and-children-expected.txt >@@ -3,5 +3,5 @@ PASS HTML parser must set the attributes > PASS HTML parser must append child nodes > PASS HTML parser must set the attributes or append children before calling constructor > FAIL HTML parser should call connectedCallback before appending child nodes. assert_equals: expected 0 but got 2 >-FAIL HTML parser must enqueue attributeChanged reactions assert_equals: attributeChangedCallback should be called before appending a child expected 0 but got 2 >+PASS HTML parser must enqueue attributeChanged reactions > hello world >diff --git a/Source/WebCore/html/parser/HTMLConstructionSite.cpp b/Source/WebCore/html/parser/HTMLConstructionSite.cpp >index 023c8fd7f35..e35311a95d1 100644 >--- a/Source/WebCore/html/parser/HTMLConstructionSite.cpp >+++ b/Source/WebCore/html/parser/HTMLConstructionSite.cpp >@@ -28,6 +28,7 @@ > #include "HTMLTreeBuilder.h" > > #include "Comment.h" >+#include "CustomElementReactionQueue.h" > #include "CustomElementRegistry.h" > #include "DOMWindow.h" > #include "DocumentFragment.h" >@@ -509,9 +510,13 @@ std::unique_ptr<CustomElementConstructionData> HTMLConstructionSite::insertHTMLE > return nullptr; > } > >-void HTMLConstructionSite::insertCustomElement(Ref<Element>&& element, const AtomicString& localName, Vector<Attribute>&& attributes) >+void HTMLConstructionSite::setAttributeOnCustomElement(Ref<Element>&& element, Vector<Attribute>&& attributes) > { > setAttributes(element, attributes, m_parserContentPolicy); >+} >+ >+void HTMLConstructionSite::insertCustomElement(Ref<Element>&& element, const AtomicString& localName, Vector<Attribute>&& attributes) >+{ > attachLater(currentNode(), element.copyRef()); > m_openElements.push(HTMLStackItem::create(WTFMove(element), localName, WTFMove(attributes))); > } >diff --git a/Source/WebCore/html/parser/HTMLConstructionSite.h b/Source/WebCore/html/parser/HTMLConstructionSite.h >index 96e64cfc7a9..f3cd308bbfc 100644 >--- a/Source/WebCore/html/parser/HTMLConstructionSite.h >+++ b/Source/WebCore/html/parser/HTMLConstructionSite.h >@@ -104,6 +104,7 @@ public: > void insertCommentOnHTMLHtmlElement(AtomicHTMLToken&&); > void insertHTMLElement(AtomicHTMLToken&&); > std::unique_ptr<CustomElementConstructionData> insertHTMLElementOrFindCustomElementInterface(AtomicHTMLToken&&); >+ void setAttributeOnCustomElement(Ref<Element>&& element, Vector<Attribute>&& attributes); > void insertCustomElement(Ref<Element>&&, const AtomicString& localName, Vector<Attribute>&&); > void insertSelfClosingHTMLElement(AtomicHTMLToken&&); > void insertFormattingElement(AtomicHTMLToken&&); >diff --git a/Source/WebCore/html/parser/HTMLDocumentParser.cpp b/Source/WebCore/html/parser/HTMLDocumentParser.cpp >index c9cc3ac91e0..1686d350978 100644 >--- a/Source/WebCore/html/parser/HTMLDocumentParser.cpp >+++ b/Source/WebCore/html/parser/HTMLDocumentParser.cpp >@@ -27,6 +27,9 @@ > #include "config.h" > #include "HTMLDocumentParser.h" > >+#include "CustomElementReactionQueue.h" >+#include "CustomElementRegistry.h" >+#include "DOMWindow.h" > #include "DocumentFragment.h" > #include "DocumentLoader.h" > #include "Frame.h" >@@ -207,9 +210,40 @@ void HTMLDocumentParser::runScriptsForPausedTreeBuilder() > if (std::unique_ptr<CustomElementConstructionData> constructionData = m_treeBuilder->takeCustomElementConstructionData()) { > ASSERT(!m_treeBuilder->hasParserBlockingScriptWork()); > >+ // Code below follows steps to create an element for a token. > // https://html.spec.whatwg.org/#create-an-element-for-the-token >+ // Step 5. >+ bool willExecuteScript = false; >+ if (!isParsingFragment()) { >+ if (auto* window = document()->domWindow()) { >+ auto* registry = window->customElementRegistry(); >+ if (UNLIKELY(registry)) >+ willExecuteScript = registry->findInterface(constructionData->name); >+ } >+ } >+ >+ std::optional<CustomElementReactionStack> customElementReactionStack; >+ if (willExecuteScript) { >+ // Step 6. >+ // FIXME(https://webkit.org/b/187319): throw-on-dynamic-markup-insertion should be incremented. >+ // FIXME(https://webkit.org/b/188189): A microstask checkpoint should be performed. >+ customElementReactionStack.emplace(); >+ } >+ >+ // Step 7. >+ // FIXME(https://webkit.org/b/183586): The "synchronous custom element" flag should be set to true when willExecuteScript is true. > auto& elementInterface = constructionData->elementInterface.get(); > auto newElement = elementInterface.constructElementWithFallback(*document(), constructionData->name); >+ >+ // Step 8. >+ m_treeBuilder->setAttributeOnCustomOrFallbackElement(WTFMove(newElement), *constructionData); >+ >+ // Step 9. >+ if (willExecuteScript) { >+ // FIXME(https://webkit.org/b/187319): throw-on-dynamic-markup-insertion should be decremented. >+ customElementReactionStack.reset(); >+ } >+ > m_treeBuilder->didCreateCustomOrFallbackElement(WTFMove(newElement), *constructionData); > return; > } >diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp >index e40f9a886f1..76690d67284 100644 >--- a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp >+++ b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp >@@ -873,6 +873,11 @@ inline void HTMLTreeBuilder::insertGenericHTMLElement(AtomicHTMLToken&& token) > m_customElementToConstruct = m_tree.insertHTMLElementOrFindCustomElementInterface(WTFMove(token)); > } > >+void HTMLTreeBuilder::setAttributeOnCustomOrFallbackElement(Ref<Element>&& element, CustomElementConstructionData& data) >+{ >+ m_tree.setAttributeOnCustomElement(WTFMove(element), WTFMove(data.attributes)); >+} >+ > void HTMLTreeBuilder::didCreateCustomOrFallbackElement(Ref<Element>&& element, CustomElementConstructionData& data) > { > m_tree.insertCustomElement(WTFMove(element), data.name, WTFMove(data.attributes)); >diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.h b/Source/WebCore/html/parser/HTMLTreeBuilder.h >index c563abafa0c..d092e420beb 100644 >--- a/Source/WebCore/html/parser/HTMLTreeBuilder.h >+++ b/Source/WebCore/html/parser/HTMLTreeBuilder.h >@@ -66,6 +66,7 @@ public: > RefPtr<ScriptElement> takeScriptToProcess(TextPosition& scriptStartPosition); > > std::unique_ptr<CustomElementConstructionData> takeCustomElementConstructionData() { return WTFMove(m_customElementToConstruct); } >+ void setAttributeOnCustomOrFallbackElement(Ref<Element>&&, CustomElementConstructionData&); > void didCreateCustomOrFallbackElement(Ref<Element>&&, CustomElementConstructionData&); > > // Done, close any open tags, etc. >diff --git a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp >index 80973e98550..42f2edd33cc 100644 >--- a/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp >+++ b/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp >@@ -31,6 +31,9 @@ > #include "CDATASection.h" > #include "Comment.h" > #include "CachedResourceLoader.h" >+#include "CustomElementReactionQueue.h" >+#include "CustomElementRegistry.h" >+#include "DOMWindow.h" > #include "Document.h" > #include "DocumentFragment.h" > #include "DocumentType.h" >@@ -781,6 +784,28 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha > m_sawFirstElement = true; > > QualifiedName qName(prefix, localName, uri); >+ // Code below follows steps to create an element for a token. >+ // See https://html.spec.whatwg.org/#parsing-xhtml-documents:create-an-element-for-the-token >+ // Step 5. >+ bool willExecuteScript = false; >+ if (!m_parsingFragment) { >+ if (auto* window = m_currentNode->document().domWindow()) { >+ auto* registry = window->customElementRegistry(); >+ if (UNLIKELY(registry)) >+ willExecuteScript = registry->findInterface(qName); >+ } >+ } >+ >+ std::optional<CustomElementReactionStack> customElementReactionStack; >+ if (willExecuteScript) { >+ // Step 6. >+ // FIXME(https://webkit.org/b/187319): throw-on-dynamic-markup-insertion should be incremented. >+ // FIXME(https://webkit.org/b/188189): A microstask checkpoint should be performed. >+ customElementReactionStack.emplace(); >+ } >+ >+ // Step 7 and 8. >+ // FIXME(https://webkit.org/b/183586): The "synchronous custom element" flag should be set to true when willExecuteScript is true. > auto newElement = m_currentNode->document().createElement(qName, true); > > Vector<Attribute> prefixedAttributes; >@@ -797,6 +822,12 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha > return; > } > >+ // Step 9. >+ if (willExecuteScript) { >+ // FIXME(https://webkit.org/b/187319): throw-on-dynamic-markup-insertion should be decremented. >+ customElementReactionStack.reset(); >+ } >+ > newElement->beginParsingChildren(); > > if (isScriptElement(newElement.get()))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188190
:
346146
|
346152
|
346155
|
346156
|
346161
|
346163
|
346166
|
346189
|
461337