mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 03:55:06 +00:00
LibWeb: Expose Node.appendChild() to the web
This is a very barebones implementation of appendChild() that doesn't take any of the idiosyncratic DOM behaviors into account yet. Also teach the wrapper generator how to turn an Interpreter argument into a Node&.
This commit is contained in:
parent
faff557400
commit
bc4fa7a3c9
4 changed files with 16 additions and 0 deletions
|
@ -473,6 +473,13 @@ void generate_implementation(const IDL::Interface& interface)
|
||||||
out() << " auto " << snake_name(parameter.name) << " = interpreter.argument(" << argument_index << ").to_string(interpreter);";
|
out() << " auto " << snake_name(parameter.name) << " = interpreter.argument(" << argument_index << ").to_string(interpreter);";
|
||||||
out() << " if (interpreter.exception())";
|
out() << " if (interpreter.exception())";
|
||||||
out() << " return {};";
|
out() << " return {};";
|
||||||
|
} else if (parameter.type.name == "Node") {
|
||||||
|
out() << " auto " << snake_name(parameter.name) << "_object = interpreter.argument(" << argument_index << ").to_object(interpreter, global_object);";
|
||||||
|
out() << " if (interpreter.exception())";
|
||||||
|
out() << " return {};";
|
||||||
|
out() << " if (!" << snake_name(parameter.name) << "_object->is_web_wrapper() || !static_cast<Wrapper*>(" << snake_name(parameter.name) << "_object)->is_node_wrapper())";
|
||||||
|
out() << " return interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, \"" << parameter.type.name << "\");";
|
||||||
|
out() << " auto& " << snake_name(parameter.name) << " = static_cast<" << wrapper_class << "*>(" << snake_name(parameter.name) << "_object)->impl();";
|
||||||
}
|
}
|
||||||
++argument_index;
|
++argument_index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,4 +193,10 @@ const Element* Node::parent_element() const
|
||||||
return to<Element>(parent());
|
return to<Element>(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<Node> Node::append_child(NonnullRefPtr<Node> node, bool notify)
|
||||||
|
{
|
||||||
|
TreeNode<Node>::append_child(node, notify);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,8 @@ public:
|
||||||
bool is_document_fragment() const { return type() == NodeType::DOCUMENT_FRAGMENT_NODE; }
|
bool is_document_fragment() const { return type() == NodeType::DOCUMENT_FRAGMENT_NODE; }
|
||||||
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
|
bool is_parent_node() const { return is_element() || is_document() || is_document_fragment(); }
|
||||||
|
|
||||||
|
RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true);
|
||||||
|
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
|
||||||
|
|
||||||
virtual FlyString node_name() const = 0;
|
virtual FlyString node_name() const = 0;
|
||||||
|
|
|
@ -8,5 +8,6 @@ interface Node : EventTarget {
|
||||||
readonly attribute Node? parentNode;
|
readonly attribute Node? parentNode;
|
||||||
readonly attribute Element? parentElement;
|
readonly attribute Element? parentElement;
|
||||||
|
|
||||||
|
Node appendChild(Node node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue