| <!DOCTYPE html> |
| <title>Custom Elements: Custom Element State "Failed" in Upgrades</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script src="resources/custom-elements-helpers.js"></script> |
| <body> |
| <script> |
| 'use strict'; |
| |
| // Custom Element State |
| // https://dom.spec.whatwg.org/#concept-element-custom-element-state |
| |
| test_with_window(w => { |
| let document = w.document; |
| let element = document.createElement('a-a'); |
| |
| let constructorCount = 0; |
| w.customElements.define('a-a', class extends w.HTMLElement { |
| constructor() { |
| constructorCount++; |
| throw new Error(); |
| } |
| connectedCallback() { |
| assert_unreached('connectedCallback should not be invoked if constructor threw'); |
| } |
| }); |
| |
| // Upgrade calls the constructor. |
| // 9. If constructResult is an abrupt completion, then |
| // Set element's custom element state to "failed". |
| // https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
| let container = document.body; |
| container.appendChild(element); |
| assert_equals(constructorCount, 1, 'constructor should be invoked once'); |
| |
| // "failed" is not "defined" |
| // https://dom.spec.whatwg.org/#concept-element-defined |
| assert_false(element.matches(':defined')); |
| }); |
| </script> |
| </body> |