# HG changeset patch # User Sam E. Giles # Date 1435397845 -3600 # Sat Jun 27 10:37:25 2015 +0100 # Node ID 692e96936fa52b9cd46b6830eb47c93c0de73e8c # Parent 56e207dbb3bda446e30c8a9fcf16050f35a58fb9 Bug 1177914 - throw a NotSupportedError when running document.importNode on a ShadowRoot or Document diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -6677,18 +6677,27 @@ nsDocument::ImportNode(nsIDOMNode* aImpo } already_AddRefed nsIDocument::ImportNode(nsINode& aNode, bool aDeep, ErrorResult& rv) const { nsINode* imported = &aNode; switch (imported->NodeType()) { + case nsIDOMNode::DOCUMENT_NODE: + { + break; + } + 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; @@ -6698,21 +6707,20 @@ nsIDocument::ImportNode(nsINode& aNode, 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); - } - } - + } + } + + 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/base/test/mochitest.ini b/dom/base/test/mochitest.ini --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -666,16 +666,17 @@ support-files = referrerHelper.js skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || toolkit != 'gtk2' && toolkit != 'gtk3' && toolkit != 'windows' || e10s #b2g-desktop(Bug 931116, b2g desktop specific, initial triage) [test_copypaste.html] skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 904183 # b2g(clipboard undefined) b2g-debug(clipboard undefined) b2g-desktop(clipboard undefined) [test_copypaste.xhtml] skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 904183 # b2g(bug 904183) b2g-debug(bug 904183) b2g-desktop(bug 904183) [test_createHTMLDocument.html] [test_declare_stylesheet_obsolete.html] [test_document_constructor.html] +[test_document_importNode_document.html] [test_domparser_null_char.html] [test_domparsing.html] [test_elementTraversal.html] [test_element_closest.html] [test_encodeToStringWithMaxLength.html] [test_fileapi.html] [test_fileapi_slice.html] skip-if = buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android' || e10s #bug 775227 diff --git a/dom/base/test/test_document_importNode_document.html b/dom/base/test/test_document_importNode_document.html new file mode 100644 --- /dev/null +++ b/dom/base/test/test_document_importNode_document.html @@ -0,0 +1,32 @@ + + + + + Test for Bug 1177914 + + + + + +Mozilla Bug 1177914 +

+ +
+
+
+ + 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 +

+ +
+
+
+ +