Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions packages/ui/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,30 @@ export class DOMImplementation {
this.#notify = notify;
}

createDocument(): Document {
return new Document(this.#notify);
// oxlint-disable-next-line bombshell-dev/max-params -- DOMImplementation.createDocument uses three positional arguments.
createDocument(
namespace: string | null,
qualifiedName: string | null,
doctype: DocumentType | null = null,
): XMLDocument {
if (arguments.length < 2) {
throw new TypeError('createDocument requires a namespace and qualified name');
}
const namespaceURI = namespace == null ? null : `${namespace}` || null;
const name = qualifiedName === null ? '' : `${qualifiedName}`;
if (doctype !== null && !(doctype instanceof DocumentType)) {
throw new TypeError('createDocument requires a DocumentType or null for its doctype');
}

const document = new XMLDocument(this.#notify);
const element = name === '' ? null : document.createElementNS(namespaceURI, name);
if (doctype !== null) {
document.appendChild(doctype);
}
if (element !== null) {
document.appendChild(element);
}
return document;
}

createHTMLDocument(title?: string): HTMLDocument {
Expand Down Expand Up @@ -730,3 +752,7 @@ export class HTMLBodyElement extends HTMLElement {}
export class HTMLSpanElement extends HTMLElement {}

export class HTMLUnknownElement extends HTMLElement {}

/** XML */

export class XMLDocument extends Document {}
16 changes: 15 additions & 1 deletion packages/ui/test/wpt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
HTMLUnknownElement,
Node,
Text,
XMLDocument,
} from '../src/dom.ts';
import { NamedNodeMap } from '../src/named-node-map.ts';

Expand Down Expand Up @@ -42,6 +43,7 @@ const config: WPTConfig = {
Node,
Text,
TypeError: globalThis.TypeError,
XMLDocument,
},
include: {
'dom/events/Event-constructors.any.js': true,
Expand All @@ -61,6 +63,18 @@ const config: WPTConfig = {
'dom/nodes/Document-createElement.html': true,
'dom/nodes/Document-createElementNS.html': true,
'dom/nodes/Document-createComment.html': true,
'dom/nodes/DOMImplementation-createDocument.html': [
'createDocument row 0', // null qualified name: no root.
'createDocument row 1', // undefined qualified name: an "undefined" root.
'createDocument row 2', // A root without a namespace.
'createDocument row 3', // Invalid qualified name.
'createDocument row 23', // A prefix requires a namespace.
'createDocument row 63', // A root with a namespace and prefix.
'createDocument row 182', // A non-DocumentType doctype argument.
'createDocument row 183', // Empty qualified name: no root.
'createDocument row 185', // Explicit undefined arguments.
'createDocument with missing arguments',
],
'dom/nodes/DOMImplementation-createHTMLDocument.html': [
'createHTMLDocument()',
'createHTMLDocument(null)',
Expand All @@ -72,7 +86,7 @@ const config: WPTConfig = {
'createHTMLDocument(foo\r\rbar baz)',
'Missing title argument',
],
// XML factory cases require DOMImplementation.createDocument.
// XML cases also require createAttribute() to preserve name casing.
'dom/nodes/Document-createAttribute.html': [/^HTML document\.createAttribute\(/],
'dom/nodes/CharacterData-data.html': true,
'dom/nodes/CharacterData-remove.html': true,
Expand Down
Loading