From 27dfd0170ed67896bb0dcf18a60bfab36a05f680 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sun, 26 Sep 2021 17:41:51 +0100 Subject: [PATCH] LibWeb: Implement Document.importNode --- Userland/Libraries/LibWeb/DOM/Document.cpp | 11 +++++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 1 + Userland/Libraries/LibWeb/DOM/Document.idl | 1 + 3 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index ebf5b5b8775..3c1dd8a4640 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -814,6 +814,17 @@ NonnullRefPtrVector Document::take_scripts_to_execute_a return move(m_scripts_to_execute_as_soon_as_possible); } +// https://dom.spec.whatwg.org/#dom-document-importnode +ExceptionOr> Document::import_node(NonnullRefPtr node, bool deep) +{ + // 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException. + if (is(*node) || is(*node)) + return DOM::NotSupportedError::create("Cannot import a document or shadow root."); + + // 2. Return a clone of node, with this and the clone children flag set if deep is true. + return node->clone_node(this, deep); +} + // https://dom.spec.whatwg.org/#concept-node-adopt void Document::adopt_node(Node& node) { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index fe89703d543..27b2f452231 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -202,6 +202,7 @@ public: bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; } void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; } + ExceptionOr> import_node(NonnullRefPtr node, bool deep); void adopt_node(Node&); ExceptionOr> adopt_node_binding(NonnullRefPtr); diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index 1345e41db03..dca0c8cfb7f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -41,6 +41,7 @@ interface Document : Node { Range createRange(); Event createEvent(DOMString interface); + [CEReactions, NewObject] Node importNode(Node node, optional boolean deep = false); [CEReactions, ImplementedAs=adopt_node_binding] Node adoptNode(Node node); [ImplementedAs=style_sheets_for_bindings] readonly attribute StyleSheetList styleSheets;