Commit cae287a3 authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Add testing of :defined prior to call to super()

Per the conversation here [1], there is a desire to add more
testing of the :defined pseudo state, prior to the call to super().
Note that `this` is not accessible prior to super(), so the
instance itself is used. Also note that :defined already does not
match anywhere inside the constructor, for upgrades.

[1] https://github.com/whatwg/dom/pull/894#discussion_r495092027

Bug: 1042130
Change-Id: I2372900981247ea5624e737d2597d004398de477
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431558
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810991}
parent f4692524
...@@ -96,14 +96,17 @@ test(function () { ...@@ -96,14 +96,17 @@ test(function () {
var log = []; var log = [];
var instance = document.createElement('my-custom-element-2'); var instance = document.createElement('my-custom-element-2');
document.body.appendChild(instance); document.body.appendChild(instance);
assert_false(instance.matches(":defined"), "Prior to definition, instance should not match :defined");
customElements.define('my-custom-element-2',class extends HTMLElement { customElements.define('my-custom-element-2',class extends HTMLElement {
constructor() { constructor() {
assert_false(instance.matches(":defined"), "During construction, prior to super(), instance should not match :defined");
super(); super();
log.push([this, 'begin']); log.push([this, 'begin']);
assert_false(this.matches(":defined"), "During construction, this should not match :defined"); assert_false(this.matches(":defined"), "During construction, after super(), this should not match :defined");
log.push([this, 'end']); log.push([this, 'end']);
} }
}); });
assert_true(instance.matches(":defined"), "After construction, instance should match :defined");
assert_equals(log.length, 2); assert_equals(log.length, 2);
assert_array_equals(log[0], [instance, 'begin']); assert_array_equals(log[0], [instance, 'begin']);
assert_array_equals(log[1], [instance, 'end']); assert_array_equals(log[1], [instance, 'end']);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment