- Revision
- 202893
- Author
- cdu...@apple.com
- Date
- 2016-07-06 21:14:28 -0700 (Wed, 06 Jul 2016)
Log Message
Align Document.body setter with the HTML specification
https://bugs.webkit.org/show_bug.cgi?id=159490
Reviewed by Alex Christensen.
LayoutTests/imported/w3c:
Rebaseline existing W3C test now that one more check is passing.
* web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt:
Source/WebCore:
Align Document.body setter with the HTML specification:
- https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
In particular, the following web-exposed changes were made:
- It is now possible to set document.body to a frameset element.
- We no longer call importNode() on the passed in body. Therefore,
if the body comes from another document, its will be adopted /
transferred rather than cloned.
Both changes match the behavior of Firefox and Chrome.
No new tests, updated / rebaselined existing tests.
* dom/Document.cpp:
(WebCore::Document::setBodyOrFrameset):
LayoutTests:
Update existing test that was setting a document's body to another frame's body
as it was expecting the body element to get cloned rather than adopted / transferred.
* fast/dom/document-set-body-expected.txt:
* fast/dom/document-set-body.html:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (202892 => 202893)
--- trunk/LayoutTests/ChangeLog 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/LayoutTests/ChangeLog 2016-07-07 04:14:28 UTC (rev 202893)
@@ -1,3 +1,16 @@
+2016-07-06 Chris Dumez <cdu...@apple.com>
+
+ Align Document.body setter with the HTML specification
+ https://bugs.webkit.org/show_bug.cgi?id=159490
+
+ Reviewed by Alex Christensen.
+
+ Update existing test that was setting a document's body to another frame's body
+ as it was expecting the body element to get cloned rather than adopted / transferred.
+
+ * fast/dom/document-set-body-expected.txt:
+ * fast/dom/document-set-body.html:
+
2016-07-06 Brent Fulgham <bfulg...@apple.com>
Return values of JSArray::createUninitialized (and related) are not consistently checked for nullptr
Modified: trunk/LayoutTests/fast/dom/document-set-body-expected.txt (202892 => 202893)
--- trunk/LayoutTests/fast/dom/document-set-body-expected.txt 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/LayoutTests/fast/dom/document-set-body-expected.txt 2016-07-07 04:14:28 UTC (rev 202893)
@@ -1,14 +1,14 @@
-Tests setting document.body
+Tests setting document.body to another frame's body
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-PASS document1.body = iframe1 threw exception Error: HierarchyRequestError: DOM Exception 3.
-PASS iframe1.parentNode is document.body
-PASS document1.body = document1.createElement('iframe') threw exception Error: HierarchyRequestError: DOM Exception 3.
-PASS document1.body != document.body is true
-PASS document1.body is body1
+PASS document1.body is not null
+PASS document2.body is null
+PASS document2.body = document1.body did not throw exception.
+PASS document2.body is not null
+PASS document1.body is null
PASS successfullyParsed is true
TEST COMPLETE
-
+
Added: trunk/LayoutTests/fast/dom/document-set-body-null-expected.txt (0 => 202893)
--- trunk/LayoutTests/fast/dom/document-set-body-null-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/document-set-body-null-expected.txt 2016-07-07 04:14:28 UTC (rev 202893)
@@ -0,0 +1,10 @@
+Tests setting document.body to null
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testDocument.body = null threw exception Error: HierarchyRequestError: DOM Exception 3.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/document-set-body-null.html (0 => 202893)
--- trunk/LayoutTests/fast/dom/document-set-body-null.html (rev 0)
+++ trunk/LayoutTests/fast/dom/document-set-body-null.html 2016-07-07 04:14:28 UTC (rev 202893)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<iframe id="testFrame" srcdoc="<html><body></body></html>"></iframe>
+<script>
+description("Tests setting document.body to null");
+
+var testDocument = document.getElementById("testFrame").contentDocument;
+shouldThrow("testDocument.body = null", "'Error: HierarchyRequestError: DOM Exception 3'");
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/fast/dom/document-set-body.html (202892 => 202893)
--- trunk/LayoutTests/fast/dom/document-set-body.html 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/LayoutTests/fast/dom/document-set-body.html 2016-07-07 04:14:28 UTC (rev 202893)
@@ -1,27 +1,27 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<!DOCTYPE html>
<html>
<head>
<script src=""
</head>
<body>
+<iframe id="testFrame1" srcdoc="<html><body></body></html>"></iframe>
+<iframe id="testFrame2" srcdoc="<html></html>"></iframe>
<script>
-description("Tests setting document.body");
+description("Tests setting document.body to another frame's body");
-iframe1 = document.createElement('iframe');
-document.body.appendChild(iframe1);
-document1 = iframe1.contentDocument.implementation.createHTMLDocument("document");
+var document1 = document.getElementById("testFrame1").contentDocument;
+var document2 = document.getElementById("testFrame2").contentDocument;
+if (document2.body)
+ document2.documentElement.removeChild(document2.body);
-shouldThrow("document1.body = iframe1", "'Error: HierarchyRequestError: DOM Exception 3'");
-shouldBe("iframe1.parentNode", "document.body");
+shouldNotBe("document1.body", "null");
+shouldBeNull("document2.body");
-shouldThrow("document1.body = document1.createElement('iframe')", "'Error: HierarchyRequestError: DOM Exception 3'");
+shouldNotThrow("document2.body = document1.body");
-document1.body = document.body;
-shouldBeTrue("document1.body != document.body");
+shouldNotBe("document2.body", "null");
+shouldBeNull("document1.body");
-body1 = document1.createElement('body');
-document1.body = body1;
-shouldBe("document1.body", "body1")
</script>
<script src=""
</body>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (202892 => 202893)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-07-07 04:14:28 UTC (rev 202893)
@@ -1,5 +1,16 @@
2016-07-06 Chris Dumez <cdu...@apple.com>
+ Align Document.body setter with the HTML specification
+ https://bugs.webkit.org/show_bug.cgi?id=159490
+
+ Reviewed by Alex Christensen.
+
+ Rebaseline existing W3C test now that one more check is passing.
+
+ * web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt:
+
+2016-07-06 Chris Dumez <cdu...@apple.com>
+
Document.body should return the first child of the html element that is either a body / frameset element
https://bugs.webkit.org/show_bug.cgi?id=159488
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt (202892 => 202893)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.body-expected.txt 2016-07-07 04:14:28 UTC (rev 202893)
@@ -20,5 +20,5 @@
PASS Setting document.body to a div element.
PASS Setting document.body when there's no root element.
PASS Setting document.body to a new body element.
-FAIL Setting document.body to a new frameset element. HierarchyRequestError: DOM Exception 3
+PASS Setting document.body to a new frameset element.
Modified: trunk/Source/WebCore/ChangeLog (202892 => 202893)
--- trunk/Source/WebCore/ChangeLog 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/Source/WebCore/ChangeLog 2016-07-07 04:14:28 UTC (rev 202893)
@@ -1,3 +1,26 @@
+2016-07-06 Chris Dumez <cdu...@apple.com>
+
+ Align Document.body setter with the HTML specification
+ https://bugs.webkit.org/show_bug.cgi?id=159490
+
+ Reviewed by Alex Christensen.
+
+ Align Document.body setter with the HTML specification:
+ - https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
+
+ In particular, the following web-exposed changes were made:
+ - It is now possible to set document.body to a frameset element.
+ - We no longer call importNode() on the passed in body. Therefore,
+ if the body comes from another document, its will be adopted /
+ transferred rather than cloned.
+
+ Both changes match the behavior of Firefox and Chrome.
+
+ No new tests, updated / rebaselined existing tests.
+
+ * dom/Document.cpp:
+ (WebCore::Document::setBodyOrFrameset):
+
2016-07-06 Brady Eidson <beid...@apple.com>
Fix my bogus json I landed earlier today.
Modified: trunk/Source/WebCore/dom/Document.cpp (202892 => 202893)
--- trunk/Source/WebCore/dom/Document.cpp 2016-07-07 03:38:48 UTC (rev 202892)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-07-07 04:14:28 UTC (rev 202893)
@@ -2624,27 +2624,26 @@
void Document::setBodyOrFrameset(RefPtr<HTMLElement>&& newBody, ExceptionCode& ec)
{
- // FIXME: This does not support setting a <frameset> Element, only a <body>. This does
- // not match the HTML specification:
- // https://html.spec.whatwg.org/multipage/dom.html#dom-document-body
- if (!newBody || !documentElement() || !newBody->hasTagName(bodyTag)) {
+ if (!is<HTMLBodyElement>(newBody.get()) && !is<HTMLFrameSetElement>(newBody.get())) {
ec = HIERARCHY_REQUEST_ERR;
return;
}
- if (&newBody->document() != this) {
- ec = 0;
- RefPtr<Node> node = importNode(*newBody, true, ec);
- if (ec)
- return;
-
- newBody = downcast<HTMLElement>(node.get());
+ auto* currentBody = bodyOrFrameset();
+ if (newBody == currentBody)
+ return;
+
+ if (currentBody) {
+ documentElement()->replaceChild(*newBody, *currentBody, ec);
+ return;
}
- if (auto* body = bodyOrFrameset())
- documentElement()->replaceChild(*newBody, *body, ec);
- else
- documentElement()->appendChild(*newBody, ec);
+ if (!documentElement()) {
+ ec = HIERARCHY_REQUEST_ERR;
+ return;
+ }
+
+ documentElement()->appendChild(*newBody, ec);
}
Location* Document::location() const