| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: Constructor Tests</title> | 2 <title>Custom Elements: Constructor Tests</title> |
| 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements-
in-the-dom"> | 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements-
in-the-dom"> |
| 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> | 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="resources/custom-elements-helpers.js"></script> | 7 <script src="resources/custom-elements-helpers.js"></script> |
| 8 <body> | 8 <body> |
| 9 <script> | 9 <script> |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 'entry should throw a TypeError'); | 71 'entry should throw a TypeError'); |
| 72 | 72 |
| 73 assert_throws(TypeError.prototype, () => { | 73 assert_throws(TypeError.prototype, () => { |
| 74 Reflect.construct(C, [], 42); | 74 Reflect.construct(C, [], 42); |
| 75 }, 'constructing a custom element with a non-object new.target should ' + | 75 }, 'constructing a custom element with a non-object new.target should ' + |
| 76 'throw a TypeError'); | 76 'throw a TypeError'); |
| 77 }, 'Custom element constructor, construct invalid new.target'); | 77 }, 'Custom element constructor, construct invalid new.target'); |
| 78 | 78 |
| 79 test_with_window((w) => { | 79 test_with_window((w) => { |
| 80 w.customElements.define('a-a', w.HTMLButtonElement); | 80 w.customElements.define('a-a', w.HTMLButtonElement); |
| 81 assert_throws(TypeError.prototype, () => { | 81 assert_reports(w, TypeError.prototype, () => { |
| 82 w.document.createElement('a-a'); | 82 w.document.createElement('a-a'); |
| 83 }, 'If NewTarget is equal to active function object, TypeError should be throw
n'); | 83 }, 'If NewTarget is equal to active function object, TypeError should be ' + |
| 84 'reported'); |
| 84 }, 'Custom element constructor, NewTarget is equal to active function object'); | 85 }, 'Custom element constructor, NewTarget is equal to active function object'); |
| 85 | 86 |
| 86 test_with_window((w) => { | 87 test_with_window((w) => { |
| 87 w.customElements.define('a-a', class extends w.HTMLButtonElement {} ); | 88 w.customElements.define('a-a', class extends w.HTMLButtonElement {} ); |
| 88 assert_throws(TypeError.prototype, () => { | 89 assert_reports(w, TypeError.prototype, () => { |
| 89 w.document.createElement('a-a'); | 90 w.document.createElement('a-a'); |
| 90 }, 'If NewTarget is equal to active function object, TypeError should be throw
n'); | 91 }, 'If NewTarget is equal to active function object, TypeError should be ' + |
| 92 'reported'); |
| 91 }, 'Custom element constructor, active function object is not equal to HTMLEleme
nt'); | 93 }, 'Custom element constructor, active function object is not equal to HTMLEleme
nt'); |
| 92 | 94 |
| 93 test_with_window((w) => { | 95 test_with_window((w) => { |
| 94 let flag = true; | 96 let flag = true; |
| 95 class A extends w.HTMLElement { | 97 class A extends w.HTMLElement { |
| 96 constructor() { | 98 constructor() { |
| 97 if (flag) { | 99 if (flag) { |
| 98 flag = false; | 100 flag = false; |
| 99 new A(); | 101 new A(); |
| 100 } | 102 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 class A extends w.HTMLElement { | 115 class A extends w.HTMLElement { |
| 114 constructor() { | 116 constructor() { |
| 115 if (flag) { | 117 if (flag) { |
| 116 flag = false; | 118 flag = false; |
| 117 new A(); | 119 new A(); |
| 118 } | 120 } |
| 119 super(); | 121 super(); |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 w.customElements.define('a-a', A); | 124 w.customElements.define('a-a', A); |
| 123 assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => { | 125 assert_reports(w, 'INVALID_STATE_ERR', () => { |
| 124 w.document.createElement('a-a'); | 126 w.document.createElement('a-a'); |
| 125 }, 'Creating an element that is already constructed marker should throw Invali
dStateError'); | 127 }, 'Creating an element that is already constructed marker should report ' + |
| 128 'InvalidStateError'); |
| 126 }, 'Already constructed marker, create element'); | 129 }, 'Already constructed marker, create element'); |
| 127 | 130 |
| 128 test_with_window((w) => { | 131 test_with_window((w) => { |
| 129 let errors = []; | 132 let errors = []; |
| 130 w.onerror = function (event, source, lineno, colno, error) { | 133 w.onerror = function (event, source, lineno, colno, error) { |
| 131 errors.push(error.name); | 134 errors.push(error.name); |
| 132 return true; | 135 return true; |
| 133 }; | 136 }; |
| 134 let flag = true; | 137 let flag = true; |
| 135 let e = w.document.createElement('a-a'); | 138 let e = w.document.createElement('a-a'); |
| 136 class A extends w.HTMLElement { | 139 class A extends w.HTMLElement { |
| 137 constructor() { | 140 constructor() { |
| 138 if (flag) { | 141 if (flag) { |
| 139 flag = false; | 142 flag = false; |
| 140 new A(); | 143 new A(); |
| 141 } | 144 } |
| 142 super(); | 145 super(); |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 w.customElements.define('a-a', A); | 148 w.customElements.define('a-a', A); |
| 146 w.document.body.appendChild(e); | 149 w.document.body.appendChild(e); |
| 147 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' + | 150 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' + |
| 148 'that is already constructed marker should throw InvalidStateError'); | 151 'that is already constructed marker should throw InvalidStateError'); |
| 149 }, 'Already constructed marker, upgrade element'); | 152 }, 'Already constructed marker, upgrade element'); |
| 150 </script> | 153 </script> |
| OLD | NEW |