# HG changeset patch # User Sam E. Giles # Date 1435397845 -3600 # Sat Jun 27 10:37:25 2015 +0100 # Node ID 8db1eb99366b537acf2f5e15850ff0df5529387b # Parent 56e207dbb3bda446e30c8a9fcf16050f35a58fb9 Bug 1177914 - throw a NotSupportedError when running document.importNode on a ShadowRoot diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6677,42 +6677,44 @@ nsDocument::ImportNode(nsIDOMNode* aImpo } already_AddRefed nsIDocument::ImportNode(nsINode& aNode, bool aDeep, ErrorResult& rv) const { nsINode* imported = &aNode; switch (imported->NodeType()) { + case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: + { + if (ShadowRoot::FromNode(imported)) { + break; + } + } case nsIDOMNode::ATTRIBUTE_NODE: - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: case nsIDOMNode::ELEMENT_NODE: case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: case nsIDOMNode::TEXT_NODE: case nsIDOMNode::CDATA_SECTION_NODE: case nsIDOMNode::COMMENT_NODE: case nsIDOMNode::DOCUMENT_TYPE_NODE: { nsCOMPtr newNode; nsCOMArray nodesWithProperties; rv = nsNodeUtils::Clone(imported, aDeep, mNodeInfoManager, nodesWithProperties, getter_AddRefs(newNode)); if (rv.Failed()) { return nullptr; } return newNode.forget(); } - default: - { - NS_WARNING("Don't know how to clone this nodetype for importNode."); - - rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - } - } - + } + + NS_WARNING("Don't know how to clone this nodetype for importNode."); + + rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } NS_IMETHODIMP nsDocument::LoadBindingDocument(const nsAString& aURI) { ErrorResult rv; nsIDocument::LoadBindingDocument(aURI, rv); diff --git a/dom/tests/mochitest/webcomponents/mochitest.ini b/dom/tests/mochitest/webcomponents/mochitest.ini --- a/dom/tests/mochitest/webcomponents/mochitest.ini +++ b/dom/tests/mochitest/webcomponents/mochitest.ini @@ -12,16 +12,17 @@ support-files = [test_custom_element_import_node_created_callback.html] [test_custom_element_in_shadow.html] [test_nested_content_element.html] [test_dest_insertion_points.html] [test_dest_insertion_points_shadow.html] [test_fallback_dest_insertion_points.html] [test_detached_style.html] [test_dynamic_content_element_matching.html] +[test_document_importnode.html] [test_document_register.html] [test_document_register_base_queue.html] [test_document_register_lifecycle.html] [test_document_register_parser.html] [test_document_register_stack.html] [test_document_shared_registry.html] [test_event_dispatch.html] [test_event_retarget.html] diff --git a/dom/tests/mochitest/webcomponents/test_document_importnode.html b/dom/tests/mochitest/webcomponents/test_document_importnode.html new file mode 100644 --- /dev/null +++ b/dom/tests/mochitest/webcomponents/test_document_importnode.html @@ -0,0 +1,37 @@ + + + + + Test for Bug 1177914 + + + + + +Mozilla Bug 1177914 +

+ +
+
+
+ +