Skip to content

Commit

Permalink
createElement()/createElementNS() dictionary argument can be a string
Browse files Browse the repository at this point in the history
Helps with whatwg/dom#572.
  • Loading branch information
annevk committed Feb 26, 2018
1 parent 66be7d2 commit 2a181b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
15 changes: 15 additions & 0 deletions custom-elements/Document-createElement.html
Expand Up @@ -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; }
Expand Down
15 changes: 15 additions & 0 deletions custom-elements/Document-createElementNS.html
Expand Up @@ -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");
</script>
</body>
4 changes: 2 additions & 2 deletions interfaces/dom.idl
Expand Up @@ -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);
Expand Down

0 comments on commit 2a181b3

Please sign in to comment.