Skip to content

Commit

Permalink
custom-elements: Element created by createElement(name, options) with…
Browse files Browse the repository at this point in the history
… valid custom element name and options set to undefined should be upgraded

createElement('my-element', undefined) was not being upgraded, though both
createElement('my-element') and createElement('my-element', {}) were.

Bug: 841725
Change-Id: Id43b21f8e1cad10745dedf3699691da7ad85cf03
Reviewed-on: https://chromium-review.googlesource.com/1084007
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564352}
  • Loading branch information
justinribeiro authored and Commit Bot committed Jun 5, 2018
1 parent 7caf0ad commit 5b75317
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ JungJik Lee <jungjik.lee@samsung.com>
Jungkee Song <jungkee.song@samsung.com>
Junmin Zhu <junmin.zhu@intel.com>
Justin Okamoto <justmoto@amazon.com>
Justin Ribeiro <justin@justinribeiro.com>
Jüri Valdmann <juri.valdmann@qt.io>
Kai Jiang <jiangkai@gmail.com>
Kai Köhne <kai.koehne@qt.io>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,19 @@
document.body.appendChild(div);
assert_true(div instanceof MyElement, 'Undefined element is upgraded on connecting to a document');
}, 'document.createElement with unknown "is" value should create "undefined" state element');

test(() => {
class MyElement extends HTMLElement {
constructor() {
super();
this.foo = true;
}
}
customElements.define("my-element", MyElement);

const instance = document.createElement('my-element', undefined);
assert_true(instance.foo);
}, 'document.createElement with undefined options value should be upgraded.');
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ Element* Document::CreateElementForBinding(
const AtomicString& local_name,
const StringOrDictionary& string_or_options,
ExceptionState& exception_state) {
if (string_or_options.IsNull()) {
return CreateElementForBinding(local_name, exception_state);
}

// 1. If localName does not match Name production, throw InvalidCharacterError
if (!IsValidElementName(this, local_name)) {
exception_state.ThrowDOMException(
Expand Down

0 comments on commit 5b75317

Please sign in to comment.