Node.appendChild(null) / replaceChild(null, null) / removeChild(null) / insertBefore(null, ref) should throw a TypeError
https://bugs.webkit.org/show_bug.cgi?id=148971
<rdar://problem/22560883>
<rdar://problem/22559225>
Reviewed by Ryosuke Niwa.
LayoutTests/imported/w3c:
Rebaseline W3C tests now that more checks are passing.
* web-platform-tests/dom/interfaces-expected.txt:
* web-platform-tests/dom/nodes/Node-appendChild-expected.txt:
* web-platform-tests/dom/nodes/Node-insertBefore-expected.txt:
* web-platform-tests/dom/nodes/Node-removeChild-expected.txt:
* web-platform-tests/dom/nodes/Node-replaceChild-expected.txt:
* web-platform-tests/html/dom/interfaces-expected.txt:
Source/WebCore:
Node.appendChild(null) / replaceChild(null, null) / removeChild(null)
and insertBefore(null, ref) should throw a TypeError instead of a
NotFoundError, as per the specification:
https://dom.spec.whatwg.org/#node
The parameters are not nullable so the Web IDL specification says
we should throw a TypeError in this case.
This patch moves the null-checking from ContainerNode to the methods
on Node. The null-checking is supposed to be done by the bindings code
but our generator currently does not support this so we do the null
checking as close to the bindings as possible. The bindings code is
calling the methods on Node. This also makes sure we throw a TypeError
for null-argument when the Node is not a ContainerNode. For e.g.
Text.appendChild(null) should throw a TypeError too.
The methods on ContainerNode now take references insteaad of pointer
parameters now that the null-checking is done at the call site in
Node. This lead to a lot of code update as those methods are used
a lot throughout the code base.
No new tests, already covered by pre-existing layout tests.
Source/WebKit/mac:
ContainerNode::appendChild() now takes a Ref<Node>&& parameter so we
need to update the call site.
* WebView/WebFrame.mm:
(-[WebFrame _documentFragmentWithNodesAsParagraphs:]):
Source/WebKit2:
ContainerNode::appendChild() now takes a Ref<Node>&& parameter so we
need to update the call sites.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::PDFPlugin):
* WebProcess/Plugins/PDF/PDFPluginAnnotation.mm:
(WebKit::PDFPluginAnnotation::attach):
(WebKit::PDFPluginAnnotation::~PDFPluginAnnotation):
* WebProcess/Plugins/PDF/PDFPluginChoiceAnnotation.mm:
(WebKit::PDFPluginChoiceAnnotation::createAnnotationElement):
LayoutTests:
Update / rebaseline tests now that we throw a different exception type.
* fast/dom/Document/replaceChild-null-oldChild-expected.txt:
* fast/dom/Document/script-tests/replaceChild-null-oldChild.js:
* fast/dom/Node/fragment-mutation-expected.txt:
* fast/dom/Node/fragment-mutation.html:
* fast/dom/incompatible-operations-expected.txt:
* fast/dom/incompatible-operations.html:
* fast/dom/move-nodes-across-documents.html:
* fast/dom/processing-instruction-appendChild-exceptions-expected.txt:
* fast/dom/processing-instruction-appendChild-exceptions.xhtml:
* fast/dom/setter-type-enforcement-expected.txt:
* fast/dom/timer-clear-interval-in-handler-and-generate-error-expected.txt:
* fast/inspector-support/uncaught-dom8-exception.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@189576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/AppendNodeCommand.cpp b/Source/WebCore/editing/AppendNodeCommand.cpp
index 6a8d9e9..b935312 100644
--- a/Source/WebCore/editing/AppendNodeCommand.cpp
+++ b/Source/WebCore/editing/AppendNodeCommand.cpp
@@ -35,13 +35,12 @@
namespace WebCore {
-AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, PassRefPtr<Node> node, EditAction editingAction)
+AppendNodeCommand::AppendNodeCommand(PassRefPtr<ContainerNode> parent, Ref<Node>&& node, EditAction editingAction)
: SimpleEditCommand(parent->document(), editingAction)
, m_parent(parent)
- , m_node(node)
+ , m_node(WTF::move(node))
{
ASSERT(m_parent);
- ASSERT(m_node);
ASSERT(!m_node->parentNode());
ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer());
@@ -68,10 +67,10 @@
if (!m_parent->hasEditableStyle() && m_parent->renderer())
return;
- m_parent->appendChild(m_node.get(), IGNORE_EXCEPTION);
+ m_parent->appendChild(m_node.copyRef(), IGNORE_EXCEPTION);
if (shouldPostAccessibilityNotification())
- sendAXTextChangedIgnoringLineBreaks(m_node.get(), applyEditType());
+ sendAXTextChangedIgnoringLineBreaks(m_node.ptr(), applyEditType());
}
void AppendNodeCommand::doUnapply()
@@ -81,7 +80,7 @@
// Need to notify this before actually deleting the text
if (shouldPostAccessibilityNotification())
- sendAXTextChangedIgnoringLineBreaks(m_node.get(), unapplyEditType());
+ sendAXTextChangedIgnoringLineBreaks(m_node.ptr(), unapplyEditType());
m_node->remove(IGNORE_EXCEPTION);
}
@@ -90,7 +89,7 @@
void AppendNodeCommand::getNodesInCommand(HashSet<Node*>& nodes)
{
addNodeAndDescendants(m_parent.get(), nodes);
- addNodeAndDescendants(m_node.get(), nodes);
+ addNodeAndDescendants(m_node.ptr(), nodes);
}
#endif