LibWeb: Implement Document.importNode

This commit is contained in:
Luke Wilde 2021-09-26 17:41:51 +01:00 committed by Andreas Kling
parent 3252d984ae
commit 27dfd0170e
Notes: sideshowbarker 2024-07-18 03:26:03 +09:00
3 changed files with 13 additions and 0 deletions

View file

@ -814,6 +814,17 @@ NonnullRefPtrVector<HTML::HTMLScriptElement> Document::take_scripts_to_execute_a
return move(m_scripts_to_execute_as_soon_as_possible); return move(m_scripts_to_execute_as_soon_as_possible);
} }
// https://dom.spec.whatwg.org/#dom-document-importnode
ExceptionOr<NonnullRefPtr<Node>> Document::import_node(NonnullRefPtr<Node> node, bool deep)
{
// 1. If node is a document or shadow root, then throw a "NotSupportedError" DOMException.
if (is<Document>(*node) || is<ShadowRoot>(*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 // https://dom.spec.whatwg.org/#concept-node-adopt
void Document::adopt_node(Node& node) void Document::adopt_node(Node& node)
{ {

View file

@ -202,6 +202,7 @@ public:
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; } bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; } void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
ExceptionOr<NonnullRefPtr<Node>> import_node(NonnullRefPtr<Node> node, bool deep);
void adopt_node(Node&); void adopt_node(Node&);
ExceptionOr<NonnullRefPtr<Node>> adopt_node_binding(NonnullRefPtr<Node>); ExceptionOr<NonnullRefPtr<Node>> adopt_node_binding(NonnullRefPtr<Node>);

View file

@ -41,6 +41,7 @@ interface Document : Node {
Range createRange(); Range createRange();
Event createEvent(DOMString interface); Event createEvent(DOMString interface);
[CEReactions, NewObject] Node importNode(Node node, optional boolean deep = false);
[CEReactions, ImplementedAs=adopt_node_binding] Node adoptNode(Node node); [CEReactions, ImplementedAs=adopt_node_binding] Node adoptNode(Node node);
[ImplementedAs=style_sheets_for_bindings] readonly attribute StyleSheetList styleSheets; [ImplementedAs=style_sheets_for_bindings] readonly attribute StyleSheetList styleSheets;