LibWeb: Add simple implementation of Document.createElementNS

This commit is contained in:
Luke 2021-01-28 20:15:04 +00:00 committed by Andreas Kling
parent affb4ef01b
commit 449c6c5604
Notes: sideshowbarker 2024-07-18 22:47:09 +09:00
4 changed files with 14 additions and 3 deletions

View file

@ -56,7 +56,7 @@ static String snake_name(const StringView& title_name)
static String make_input_acceptable_cpp(const String& input)
{
if (input.is_one_of("class", "template", "for", "default", "char")) {
if (input.is_one_of("class", "template", "for", "default", "char", "namespace")) {
StringBuilder builder;
builder.append(input);
builder.append('_');
@ -1031,7 +1031,7 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob
auto generate_to_cpp = [&](auto& parameter, auto& js_name, const auto& js_suffix, auto cpp_name, bool return_void = false, bool legacy_null_to_empty_string = false, bool optional = false) {
auto scoped_generator = generator.fork();
scoped_generator.set("cpp_name", cpp_name);
scoped_generator.set("cpp_name", make_input_acceptable_cpp(cpp_name));
scoped_generator.set("js_name", js_name);
scoped_generator.set("js_suffix", js_suffix);
scoped_generator.set("legacy_null_to_empty_string", legacy_null_to_empty_string ? "true" : "false");
@ -1109,7 +1109,7 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob
Vector<String> parameter_names;
size_t argument_index = 0;
for (auto& parameter : parameters) {
parameter_names.append(snake_name(parameter.name));
parameter_names.append(make_input_acceptable_cpp(snake_name(parameter.name)));
arguments_generator.set("argument.index", String::number(argument_index));
arguments_generator.append(R"~~~(

View file

@ -566,12 +566,21 @@ JS::Value Document::run_javascript(const StringView& source)
return result;
}
// https://dom.spec.whatwg.org/#dom-document-createelement
// FIXME: This only implements step 6 of the algorithm and does not take in options.
NonnullRefPtr<Element> Document::create_element(const String& tag_name)
{
// FIXME: Let namespace be the HTML namespace, if this is an HTML document or thiss content type is "application/xhtml+xml", and null otherwise.
return DOM::create_element(*this, tag_name, Namespace::HTML);
}
// https://dom.spec.whatwg.org/#internal-createelementns-steps
// FIXME: This only implements step 4 of the algorithm and does not take in options.
NonnullRefPtr<Element> Document::create_element_ns(const String& namespace_, const String& qualified_name)
{
return DOM::create_element(*this, qualified_name, namespace_);
}
NonnullRefPtr<DocumentFragment> Document::create_document_fragment()
{
return adopt(*new DocumentFragment(*this));

View file

@ -146,6 +146,7 @@ public:
JS::Value run_javascript(const StringView&);
NonnullRefPtr<Element> create_element(const String& tag_name);
NonnullRefPtr<Element> create_element_ns(const String& namespace_, const String& qualifed_name);
NonnullRefPtr<DocumentFragment> create_document_fragment();
NonnullRefPtr<Text> create_text_node(const String& data);
NonnullRefPtr<Comment> create_comment(const String& data);

View file

@ -19,6 +19,7 @@ interface Document : Node {
ArrayFromVector querySelectorAll(DOMString selectors);
Element createElement(DOMString tagName);
Element createElementNS(DOMString? namespace, DOMString qualifiedName);
DocumentFragment createDocumentFragment();
Text createTextNode(DOMString data);
Comment createComment(DOMString data);