Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting outerHTML on child of DocumentFragment should not throw error #15575

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS document.getElementById('svgElement').innerHTML is "<g></g>"
PASS document.documentElement.outerHTML = '' threw exception NoModificationAllowedError: Cannot set outerHTML on element because its parent is not an Element.
PASS a.parentNode is null
PASS a.outerHTML = '' threw exception NoModificationAllowedError: Cannot set outerHTML on element because it doesn't have a parent.
PASS a.outerHTML = '' did not throw exception.
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
2 changes: 1 addition & 1 deletion LayoutTests/fast/dom/set-outer-html-special-cases.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// say this should be a no-op though.
a = document.createElement("a");
shouldBe("a.parentNode", "null");
shouldThrowErrorName("a.outerHTML = ''", "NoModificationAllowedError");
shouldNotThrow("a.outerHTML = ''");
}
</script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions LayoutTests/fast/dynamic/outerHTML-no-element-expected.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test for 4110775 Crash will occur when double-clicking outerHTML link on W3 DOM test

If the test fails, Safari may crash, or you may see a failure message below. If the test passes, you should see a message with a description of the expected exception.
If the test fails, Safari may crash, or you may see a failure message below. If the test passes, you should see "This test passed!".

This test passed - expected error - NoModificationAllowedError: Cannot set outerHTML on element because it doesn't have a parent
This test passed!
6 changes: 3 additions & 3 deletions LayoutTests/fast/dynamic/outerHTML-no-element.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<html>
<body>
<p>test for <a href="rdar://problem/4110775">4110775</a> Crash will occur when double-clicking outerHTML link on W3 DOM test</p>
<p>If the test fails, Safari may crash, or you may see a failure message below. If the test passes, you should see a message with a description of the expected exception.</p>
<p>If the test fails, Safari may crash, or you may see a failure message below. If the test passes, you should see "This test passed!".</p>
<div id="test">This test failed.</div>

<script type="text/javascript">
if (window.testRunner)
testRunner.dumpAsText();
var t = document.getElementById("test");
var outerStr = "<div id='test2'>This test failed!</div>";
var outerStr = "<div id='test2'>This test passed!</div>";
t.outerHTML = outerStr;
try {
t.outerHTML = "<div id='test2'>This test failed!!</div>"
}catch(e) {
document.getElementById("test2").outerHTML = "<div id='test2'>This test passed - expected error - " + e + "</div>";
document.getElementById("test2").outerHTML = "<div id='test2'>This test failed since threw error - " + e + "</div>";
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3738,11 +3738,11 @@ String Element::outerHTML() const
ExceptionOr<void> Element::setOuterHTML(const String& html)
{
// The specification allows setting outerHTML on an Element whose parent is a DocumentFragment and Gecko supports this.
// However, as of June 2021, Blink matches our behavior and throws a NoModificationAllowedError for non-Element parents.
// https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml
RefPtr parent = parentElement();
if (UNLIKELY(!parent)) {
if (!parentNode())
return Exception { NoModificationAllowedError, "Cannot set outerHTML on element because it doesn't have a parent"_s };
return { };
return Exception { NoModificationAllowedError, "Cannot set outerHTML on element because its parent is not an Element"_s };
}

Expand Down