Changeset 243233 in webkit
- Timestamp:
- Mar 20, 2019, 1:26:18 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/dom/insert-template-parent-into-adopted-content-expected.txt (added)
-
LayoutTests/fast/dom/insert-template-parent-into-adopted-content.html (added)
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/dom/ContainerNode.cpp (modified) (3 diffs)
-
Source/WebCore/dom/Node.cpp (modified) (1 diff)
-
Source/WebCore/dom/Node.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r243228 r243233 1 2019-03-19 Ryosuke Niwa <rniwa@webkit.org> 2 3 appendChild should throw when inserting an ancestor of a template into its content adopted to another document 4 https://bugs.webkit.org/show_bug.cgi?id=195984 5 6 Reviewed by Darin Adler. 7 8 Added a regression test. 9 10 * fast/dom/insert-template-parent-into-adopted-content-expected.txt: Added. 11 * fast/dom/insert-template-parent-into-adopted-content.html: Added. 12 1 13 2019-03-20 Simon Fraser <simon.fraser@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/ChangeLog
r243218 r243233 1 2019-03-19 Ryosuke Niwa <rniwa@webkit.org> 2 3 appendChild should throw when inserting an ancestor of a template into its content adopted to another document 4 https://bugs.webkit.org/show_bug.cgi?id=195984 5 6 Reviewed by Darin Adler. 7 8 Rebaselined the test that is not fully passing. 9 10 * web-platform-tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy-expected.txt: 11 1 12 2019-03-20 Oriol Brufau <obrufau@igalia.com> 2 13 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-element/template-content-hierarcy-expected.txt
r224156 r243233 1 1 2 2 PASS Template content should throw when its ancestor is being appended. 3 FAIL Template content should throw exception when its ancestor in a different document but connected via host is being append. assert_throws: Template content should throw if any of ancestor is being appended. function "() => { 4 tmpl.content.appendChild(parent); 5 }" did not throw 3 PASS Template content should throw exception when its ancestor in a different document but connected via host is being append. 6 4 -
trunk/Source/WebCore/ChangeLog
r243229 r243233 1 2019-03-19 Ryosuke Niwa <rniwa@webkit.org> 2 3 appendChild should throw when inserting an ancestor of a template into its content adopted to another document 4 https://bugs.webkit.org/show_bug.cgi?id=195984 5 6 Reviewed by Darin Adler. 7 8 The WPT test caught a bug that appendChild and other DOM insertion functions were incorrectly assuming that 9 any node that's in a HTML template element has the current document's template document as its owner. 10 The assumption is wrong when the template element's content DocumentFragment is adopted to another document. 11 12 Fixed the bug by always checking the ancestor host elements in checkAcceptChild. Also 13 14 Test: fast/dom/insert-template-parent-into-adopted-content.html 15 16 * dom/ContainerNode.cpp: 17 (WebCore::isInTemplateContent): Deleted. This code is simply wrong. 18 (WebCore::containsConsideringHostElements): Deleted. Call sites are updated to use containsIncludingHostElements. 19 (WebCore::containsIncludingHostElements): Moved from Node.cpp and optimized this code a bit. It's more efficient 20 to get the parent node and check for ShadowRoot and DocumentFragment only when the parent is null than to check 21 for those two node types before getting the parent node. 22 (WebCore::checkAcceptChild): Merged two code paths to call containsIncludingHostElements. The early return for 23 a pseudo element is there only to prevent tree corruption in release build even in the presence of a major bug 24 so it shouldn't be an spec compliance issue. 25 * dom/Node.cpp: 26 (WebCore::Node::containsIncludingHostElements const): Deleted. 27 * dom/Node.h: 28 1 29 2019-03-20 Timothy Hatcher <timothy@apple.com> 2 30 -
trunk/Source/WebCore/dom/ContainerNode.cpp
r243175 r243233 293 293 } 294 294 295 static inline bool isInTemplateContent(const Node* node) 296 { 297 Document& document = node->document(); 298 return &document == document.templateDocument(); 299 } 300 301 static inline bool containsConsideringHostElements(const Node& newChild, const Node& newParent) 302 { 303 return (newParent.isInShadowTree() || isInTemplateContent(&newParent)) 304 ? newChild.containsIncludingHostElements(&newParent) 305 : newChild.contains(&newParent); 295 static bool containsIncludingHostElements(const Node& possibleAncestor, const Node& node) 296 { 297 const Node* currentNode = &node; 298 do { 299 if (currentNode == &possibleAncestor) 300 return true; 301 const ContainerNode* parent = currentNode->parentNode(); 302 if (!parent) { 303 if (is<ShadowRoot>(currentNode)) 304 parent = downcast<ShadowRoot>(currentNode)->host(); 305 else if (is<DocumentFragment>(*currentNode) && downcast<DocumentFragment>(*currentNode).isTemplateContent()) 306 parent = static_cast<const TemplateContentDocumentFragment*>(currentNode)->host(); 307 } 308 currentNode = parent; 309 } while (currentNode); 310 311 return false; 306 312 } 307 313 308 314 static inline ExceptionOr<void> checkAcceptChild(ContainerNode& newParent, Node& newChild, const Node* refChild, Document::AcceptChildOperation operation) 309 315 { 316 if (containsIncludingHostElements(newChild, newParent)) 317 return Exception { HierarchyRequestError }; 318 310 319 // Use common case fast path if possible. 311 320 if ((newChild.isElementNode() || newChild.isTextNode()) && newParent.isElementNode()) { 312 321 ASSERT(!newParent.isDocumentTypeNode()); 313 322 ASSERT(isChildTypeAllowed(newParent, newChild)); 314 if (containsConsideringHostElements(newChild, newParent))315 return Exception { HierarchyRequestError };316 323 if (operation == Document::AcceptChildOperation::InsertOrAdd && refChild && refChild->parentNode() != &newParent) 317 324 return Exception { NotFoundError }; … … 322 329 ASSERT(!newChild.isPseudoElement()); 323 330 if (newChild.isPseudoElement()) 324 return Exception { HierarchyRequestError };325 326 if (containsConsideringHostElements(newChild, newParent))327 331 return Exception { HierarchyRequestError }; 328 332 … … 343 347 ASSERT(!newParent.isDocumentTypeNode()); 344 348 ASSERT(isChildTypeAllowed(newParent, newChild)); 345 if (contains ConsideringHostElements(newChild, newParent))349 if (containsIncludingHostElements(newChild, newParent)) 346 350 return Exception { HierarchyRequestError }; 347 351 return { }; -
trunk/Source/WebCore/dom/Node.cpp
r243122 r243233 1030 1030 } 1031 1031 1032 bool Node::containsIncludingHostElements(const Node* node) const1033 {1034 while (node) {1035 if (node == this)1036 return true;1037 if (is<DocumentFragment>(*node) && downcast<DocumentFragment>(*node).isTemplateContent())1038 node = static_cast<const TemplateContentDocumentFragment*>(node)->host();1039 else1040 node = node->parentOrShadowHostNode();1041 }1042 return false;1043 }1044 1045 1032 Node* Node::pseudoAwarePreviousSibling() const 1046 1033 { -
trunk/Source/WebCore/dom/Node.h
r243122 r243233 393 393 WEBCORE_EXPORT bool contains(const Node*) const; 394 394 bool containsIncludingShadowDOM(const Node*) const; 395 bool containsIncludingHostElements(const Node*) const;396 395 397 396 // Number of DOM 16-bit units contained in node. Note that rendered text length can be different - e.g. because of
Note:
See TracChangeset
for help on using the changeset viewer.