diff --git a/custom-elements/Document-createElement.html b/custom-elements/Document-createElement.html index 21f024c5735bae..ad29b91d88da8c 100644 --- a/custom-elements/Document-createElement.html +++ b/custom-elements/Document-createElement.html @@ -50,6 +50,21 @@ assert_true(instance2 instanceof DefinedLater); }, 'document.createElement must create an instance of autonomous custom elements when it has is attribute'); +test(() => { + class SuperP extends HTMLParagraphElement {} + customElements.define("super-p", SuperP, { extends: "p" }); + + const superP = document.createElement("p", { is: "super-p" }); + assert_true(superP instanceof HTMLParagraphElement); + assert_true(superP instanceof SuperP); + assert_equals(superP.localName, "p"); + + const notSuperP = document.createElement("p", "super-p"); + assert_true(notSuperP instanceof HTMLParagraphElement); + assert_false(notSuperP instanceof SuperP); + assert_equals(notSuperP.localName, "p"); +}, "document.createElement()'s second argument is to be ignored when it's a string"); + function assert_reports(expected, testFunction, message) { var uncaughtError = null; window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; } diff --git a/custom-elements/Document-createElementNS.html b/custom-elements/Document-createElementNS.html index 4cc4561f54cf59..6377ba63fca15a 100644 --- a/custom-elements/Document-createElementNS.html +++ b/custom-elements/Document-createElementNS.html @@ -49,5 +49,20 @@ assert_false(element instanceof MyBuiltinElement2); assert_false(element.hasAttribute('is')); }, 'builtin: document.createElementNS should check namespaces.'); + +test(() => { + class SuperP extends HTMLParagraphElement {} + customElements.define("super-p", SuperP, { extends: "p" }); + + const superP = document.createElementNS("http://www.w3.org/1999/xhtml", "p", { is: "super-p" }); + assert_true(superP instanceof HTMLParagraphElement); + assert_true(superP instanceof SuperP); + assert_equals(superP.localName, "p"); + + const notSuperP = document.createElementNS("http://www.w3.org/1999/xhtml", "p", "super-p"); + assert_true(notSuperP instanceof HTMLParagraphElement); + assert_false(notSuperP instanceof SuperP); + assert_equals(notSuperP.localName, "p"); +}, "document.createElementNS()'s third argument is to be ignored when it's a string"); diff --git a/interfaces/dom.idl b/interfaces/dom.idl index 90419f083f8959..e97f803f82105e 100644 --- a/interfaces/dom.idl +++ b/interfaces/dom.idl @@ -266,8 +266,8 @@ interface Document : Node { HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName); HTMLCollection getElementsByClassName(DOMString classNames); - [NewObject] Element createElement(DOMString localName, optional ElementCreationOptions options); - [NewObject] Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options); + [NewObject] Element createElement(DOMString localName, optional (DOMString or ElementCreationOptions) options); + [NewObject] Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional (DOMString or ElementCreationOptions) options); [NewObject] DocumentFragment createDocumentFragment(); [NewObject] Text createTextNode(DOMString data); [NewObject] CDATASection createCDATASection(DOMString data);