diff --git a/src/dom/document.zig b/src/dom/document.zig index 23609600..b889169b 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -36,6 +36,11 @@ pub const Document = struct { return Element.toInterface(e); } + pub fn _createElementNS(self: *parser.Document, ns: []const u8, tag_name: []const u8) ElementUnion { + const e = parser.documentCreateElementNS(self, ns, tag_name); + return Element.toInterface(e); + } + // We can't simply use libdom dom_document_get_elements_by_tag_name here. // Indeed, netsurf implemented a previous dom spec when // getElementsByTagName returned a NodeList. diff --git a/src/netsurf.zig b/src/netsurf.zig index 24bb1771..7052a0ac 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -752,6 +752,12 @@ pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Eleme return elem.?; } +pub inline fn documentCreateElementNS(doc: *Document, ns: []const u8, tag_name: []const u8) *Element { + var elem: ?*Element = undefined; + _ = documentVtable(doc).dom_document_create_element_ns.?(doc, stringFromData(ns), stringFromData(tag_name), &elem); + return elem.?; +} + // DocumentHTML pub const DocumentHTML = c.dom_html_document; diff --git a/tests/wpt/dom/nodes/Document-createElementNS.html b/tests/wpt/dom/nodes/Document-createElementNS.html new file mode 100644 index 00000000..5ad81043 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createElementNS.html @@ -0,0 +1,224 @@ + + +Document.createElementNS + + + + +
+ + + diff --git a/tests/wpt/dom/nodes/Document-createElementNS.js b/tests/wpt/dom/nodes/Document-createElementNS.js new file mode 100644 index 00000000..2cf29485 --- /dev/null +++ b/tests/wpt/dom/nodes/Document-createElementNS.js @@ -0,0 +1,189 @@ +var createElementNS_tests = [ + /* Arrays with three elements: + * the namespace argument + * the qualifiedName argument + * the expected exception, or null if none + */ + [null, null, null], + [null, undefined, null], + [null, "foo", null], + [null, "1foo", "INVALID_CHARACTER_ERR"], + [null, "f1oo", null], + [null, "foo1", null], + [null, "\u0BC6foo", null], + [null, "\u037Efoo", "INVALID_CHARACTER_ERR"], + [null, "}foo", "INVALID_CHARACTER_ERR"], + [null, "f}oo", "INVALID_CHARACTER_ERR"], + [null, "foo}", "INVALID_CHARACTER_ERR"], + [null, "\uFFFFfoo", "INVALID_CHARACTER_ERR"], + [null, "f\uFFFFoo", "INVALID_CHARACTER_ERR"], + [null, "foo\uFFFF", "INVALID_CHARACTER_ERR"], + [null, "", "INVALID_CHARACTER_ERR"], + [null, "", "INVALID_CHARACTER_ERR"], + [null, "f", "INVALID_CHARACTER_ERR"], + ["http://example.com/", "fo", "INVALID_CHARACTER_ERR"], + ["http://example.com/", "namespaceURI:,", "INVALID_CHARACTER_ERR"], + ["http://example.com/", "namespaceURI:a ", "INVALID_CHARACTER_ERR"], + ["http://example.com/", "namespaceURI:\"", "INVALID_CHARACTER_ERR"], + ["/", "foo", null], + ["/", "1foo", "INVALID_CHARACTER_ERR"], + ["/", "f1oo", null], + ["/", "foo1", null], + ["/", ":foo", "INVALID_CHARACTER_ERR"], + ["/", "f:oo", null], + ["/", "foo:", "INVALID_CHARACTER_ERR"], + ["/", "xml", null], + ["/", "xmlns", "NAMESPACE_ERR"], + ["/", "xmlfoo", null], + ["/", "xml:foo", "NAMESPACE_ERR"], + ["/", "xmlns:foo", "NAMESPACE_ERR"], + ["/", "xmlfoo:bar", null], + ["http://www.w3.org/XML/1998/namespace", "foo", null], + ["http://www.w3.org/XML/1998/namespace", "1foo", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/XML/1998/namespace", "f1oo", null], + ["http://www.w3.org/XML/1998/namespace", "foo1", null], + ["http://www.w3.org/XML/1998/namespace", ":foo", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/XML/1998/namespace", "f:oo", null], + ["http://www.w3.org/XML/1998/namespace", "foo:", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/XML/1998/namespace", "xml", null], + ["http://www.w3.org/XML/1998/namespace", "xmlns", "NAMESPACE_ERR"], + ["http://www.w3.org/XML/1998/namespace", "xmlfoo", null], + ["http://www.w3.org/XML/1998/namespace", "xml:foo", null], + ["http://www.w3.org/XML/1998/namespace", "xmlns:foo", "NAMESPACE_ERR"], + ["http://www.w3.org/XML/1998/namespace", "xmlfoo:bar", null], + ["http://www.w3.org/XML/1998/namespaces", "xml:foo", "NAMESPACE_ERR"], + ["http://www.w3.org/xml/1998/namespace", "xml:foo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "foo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "1foo", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/2000/xmlns/", "f1oo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "foo1", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", ":foo", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/2000/xmlns/", "f:oo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "foo:", "INVALID_CHARACTER_ERR"], + ["http://www.w3.org/2000/xmlns/", "xml", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "xmlns", null], + ["http://www.w3.org/2000/xmlns/", "xmlfoo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "xml:foo", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "xmlns:foo", null], + ["http://www.w3.org/2000/xmlns/", "xmlfoo:bar", "NAMESPACE_ERR"], + ["http://www.w3.org/2000/xmlns/", "foo:xmlns", "NAMESPACE_ERR"], + ["foo:", "foo", null], + ["foo:", "1foo", "INVALID_CHARACTER_ERR"], + ["foo:", "f1oo", null], + ["foo:", "foo1", null], + ["foo:", ":foo", "INVALID_CHARACTER_ERR"], + ["foo:", "f:oo", null], + ["foo:", "foo:", "INVALID_CHARACTER_ERR"], + ["foo:", "xml", null], + ["foo:", "xmlns", "NAMESPACE_ERR"], + ["foo:", "xmlfoo", null], + ["foo:", "xml:foo", "NAMESPACE_ERR"], + ["foo:", "xmlns:foo", "NAMESPACE_ERR"], + ["foo:", "xmlfoo:bar", null], +]