- Revision
- 206308
- Author
- [email protected]
- Date
- 2016-09-23 09:24:35 -0700 (Fri, 23 Sep 2016)
Log Message
Align Element.insertAdjacentHTML() with the specification
https://bugs.webkit.org/show_bug.cgi?id=162479
Reviewed by Sam Weinig.
LayoutTests/imported/w3c:
Rebaseline W3C test now that one more check is passing.
* web-platform-tests/domparsing/insert_adjacent_html-expected.txt:
Source/WebCore:
Align Element.insertAdjacentHTML() with the specification:
- https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml (steps 1 & 2)
In particular, the following changes issues are now fixed:
- Calling insertAdjacentHTML() on an element whose parent is a
DocumentFragment now works insteas of throwing a
NO_MODIFICATION_ALLOWED_ERR.
- Calling insertAdjacentHTML() on child of the <html> element
no longer creates duplicate body / head elements.
Firefox agrees with the specification.
Test: fast/dom/insertAdjacentHTML-DocumentFragment-parent.html
* dom/Element.cpp:
(WebCore::contextNodeForInsertion):
(WebCore::Element::insertAdjacentHTML):
LayoutTests:
Add layout test coverage for calling insertAdjacentHTML on an element
whose parent is a DocumentFragment. I have verified that this test is
passing in Firefox.
* fast/dom/insertAdjacentHTML-DocumentFragment-crash-expected.txt:
* fast/dom/insertAdjacentHTML-DocumentFragment-parent-expected.txt: Added.
* fast/dom/insertAdjacentHTML-DocumentFragment-parent.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (206307 => 206308)
--- trunk/LayoutTests/ChangeLog 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/LayoutTests/ChangeLog 2016-09-23 16:24:35 UTC (rev 206308)
@@ -1,3 +1,18 @@
+2016-09-23 Chris Dumez <[email protected]>
+
+ Align Element.insertAdjacentHTML() with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=162479
+
+ Reviewed by Sam Weinig.
+
+ Add layout test coverage for calling insertAdjacentHTML on an element
+ whose parent is a DocumentFragment. I have verified that this test is
+ passing in Firefox.
+
+ * fast/dom/insertAdjacentHTML-DocumentFragment-crash-expected.txt:
+ * fast/dom/insertAdjacentHTML-DocumentFragment-parent-expected.txt: Added.
+ * fast/dom/insertAdjacentHTML-DocumentFragment-parent.html: Added.
+
2016-09-23 Commit Queue <[email protected]>
Unreviewed, rolling out r206165.
Modified: trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-crash-expected.txt (206307 => 206308)
--- trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-crash-expected.txt 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-crash-expected.txt 2016-09-23 16:24:35 UTC (rev 206308)
@@ -1,2 +1 @@
-CONSOLE MESSAGE: line 9: NoModificationAllowedError (DOM Exception 7): The object can not be modified.
This test passes if it doesn't crash (or ASSERT).
Added: trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent-expected.txt (0 => 206308)
--- trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent-expected.txt 2016-09-23 16:24:35 UTC (rev 206308)
@@ -0,0 +1,12 @@
+Tests that insertAdjacentHTML() works if the element's parent is a DocumentFragment.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS div.insertAdjacentHTML('beforebegin', '<a>test</a>') did not throw exception.
+PASS fragment.firstChild.tagName is "A"
+PASS fragment.firstChild.nextSibling.tagName is "DIV"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent.html (0 => 206308)
--- trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent.html (rev 0)
+++ trunk/LayoutTests/fast/dom/insertAdjacentHTML-DocumentFragment-parent.html 2016-09-23 16:24:35 UTC (rev 206308)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests that insertAdjacentHTML() works if the element's parent is a DocumentFragment.");
+
+var fragment = new DocumentFragment();
+var div = document.createElement("div");
+fragment.appendChild(div);
+
+shouldNotThrow("div.insertAdjacentHTML('beforebegin', '<a>test</a>')");
+shouldBeEqualToString("fragment.firstChild.tagName", "A");
+shouldBeEqualToString("fragment.firstChild.nextSibling.tagName", "DIV");
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206307 => 206308)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-23 16:24:35 UTC (rev 206308)
@@ -1,3 +1,14 @@
+2016-09-23 Chris Dumez <[email protected]>
+
+ Align Element.insertAdjacentHTML() with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=162479
+
+ Reviewed by Sam Weinig.
+
+ Rebaseline W3C test now that one more check is passing.
+
+ * web-platform-tests/domparsing/insert_adjacent_html-expected.txt:
+
2016-09-23 Commit Queue <[email protected]>
Unreviewed, rolling out r206165.
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/insert_adjacent_html-expected.txt (206307 => 206308)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/insert_adjacent_html-expected.txt 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/domparsing/insert_adjacent_html-expected.txt 2016-09-23 16:24:35 UTC (rev 206308)
@@ -28,5 +28,5 @@
PASS Afterbegin content2 test again, now that there's a next sibling
PASS BeforeEnd content2 test again, now that there's a next sibling
PASS afterend content2 test again, now that there's a next sibling
-FAIL Inserting kids of the <html> element should not do weird things with implied <body>/<head> tags assert_equals: Should still have one head expected 1 but got 3
+PASS Inserting kids of the <html> element should not do weird things with implied <body>/<head> tags
Modified: trunk/Source/WebCore/ChangeLog (206307 => 206308)
--- trunk/Source/WebCore/ChangeLog 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/Source/WebCore/ChangeLog 2016-09-23 16:24:35 UTC (rev 206308)
@@ -1,3 +1,28 @@
+2016-09-23 Chris Dumez <[email protected]>
+
+ Align Element.insertAdjacentHTML() with the specification
+ https://bugs.webkit.org/show_bug.cgi?id=162479
+
+ Reviewed by Sam Weinig.
+
+ Align Element.insertAdjacentHTML() with the specification:
+ - https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml (steps 1 & 2)
+
+ In particular, the following changes issues are now fixed:
+ - Calling insertAdjacentHTML() on an element whose parent is a
+ DocumentFragment now works insteas of throwing a
+ NO_MODIFICATION_ALLOWED_ERR.
+ - Calling insertAdjacentHTML() on child of the <html> element
+ no longer creates duplicate body / head elements.
+
+ Firefox agrees with the specification.
+
+ Test: fast/dom/insertAdjacentHTML-DocumentFragment-parent.html
+
+ * dom/Element.cpp:
+ (WebCore::contextNodeForInsertion):
+ (WebCore::Element::insertAdjacentHTML):
+
2016-09-23 Commit Queue <[email protected]>
Unreviewed, rolling out r206165.
Modified: trunk/Source/WebCore/dom/Element.cpp (206307 => 206308)
--- trunk/Source/WebCore/dom/Element.cpp 2016-09-23 16:21:19 UTC (rev 206307)
+++ trunk/Source/WebCore/dom/Element.cpp 2016-09-23 16:24:35 UTC (rev 206308)
@@ -53,6 +53,7 @@
#include "FocusEvent.h"
#include "FrameSelection.h"
#include "FrameView.h"
+#include "HTMLBodyElement.h"
#include "HTMLCanvasElement.h"
#include "HTMLCollection.h"
#include "HTMLDocument.h"
@@ -3669,11 +3670,11 @@
}
// Step 1 of https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml.
-static Element* contextElementForInsertion(const String& where, Element* element, ExceptionCode& ec)
+static ContainerNode* contextNodeForInsertion(const String& where, Element* element, ExceptionCode& ec)
{
if (equalLettersIgnoringASCIICase(where, "beforebegin") || equalLettersIgnoringASCIICase(where, "afterend")) {
- auto* parent = element->parentElement();
- if (!parent) {
+ auto* parent = element->parentNode();
+ if (!parent || is<Document>(*parent)) {
ec = NO_MODIFICATION_ALLOWED_ERR;
return nullptr;
}
@@ -3685,14 +3686,25 @@
return nullptr;
}
+// https://w3c.github.io/DOM-Parsing/#dom-element-insertadjacenthtml
void Element::insertAdjacentHTML(const String& where, const String& markup, ExceptionCode& ec)
{
- Element* contextElement = contextElementForInsertion(where, this, ec);
- if (!contextElement)
+ // Step 1.
+ auto* contextNode = contextNodeForInsertion(where, this, ec);
+ if (!contextNode)
return;
+ RefPtr<Element> contextElement;
+ // Step 2.
+ if (!is<Element>(*contextNode)
+ || (contextNode->document().isHTMLDocument() && is<HTMLHtmlElement>(*contextNode))) {
+ contextElement = HTMLBodyElement::create(contextNode->document());
+ } else
+ contextElement = downcast<Element>(contextNode);
+ // Step 3.
RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(*contextElement, markup, AllowScriptingContent, ec);
if (!fragment)
return;
+ // Step 4.
insertAdjacent(where, fragment.releaseNonNull(), ec);
}