| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: report the exception</title> | 2 <title>Custom Elements: report the exception</title> |
| 3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/custom-elements-helpers.js"></script> | 5 <script src="resources/custom-elements-helpers.js"></script> |
| 6 <body> | 6 <body> |
| 7 <!-- | 7 <!-- |
| 8 The spec has two places where it says to [report the exception]: | 8 The spec has two places where it says to [report the exception]: |
| 9 | 9 |
| 10 1. In [create an element for a token], step 7. | 10 1. In [create an element for a token], step 6.1 |
| 11 This can occur only when [create an element] is invoked from | 11 This can occur when [create an element] is invoked from |
| 12 [create an element for a token] with the synchronous custom elements flag | 12 [create an element for a token] with the synchronous custom elements flag |
| 13 set. The document parser uses this algorithm. | 13 set, or from createElement. |
| 14 2. In [invoke custom element reactions], step 2.1. | 14 2. In [invoke custom element reactions], step 2.1. |
| 15 | 15 |
| 16 There are different code paths when: | 16 There are different code paths when: |
| 17 1. Author script throws an exception that is rethrown. | 17 1. Author script throws an exception that is rethrown. |
| 18 2. The user agent throws an exception. | 18 2. The user agent throws an exception. |
| 19 | 19 |
| 20 This test contains 4 tests for the combination of the above 2x2. | 20 This test contains tests for the combination of the above 2x2. |
| 21 | 21 |
| 22 [create an element]: https://dom.spec.whatwg.org/#concept-create-element | 22 [create an element]: https://dom.spec.whatwg.org/#concept-create-element |
| 23 [create an element for a token]: https://html.spec.whatwg.org/multipage/syntax.h
tml#create-an-element-for-the-token | 23 [create an element for a token]: https://html.spec.whatwg.org/multipage/syntax.h
tml#create-an-element-for-the-token |
| 24 [invoke custom element reactions]: https://html.spec.whatwg.org/multipage/script
ing.html#invoke-custom-element-reactions | 24 [invoke custom element reactions]: https://html.spec.whatwg.org/multipage/script
ing.html#invoke-custom-element-reactions |
| 25 [report the exception]: https://html.spec.whatwg.org/multipage/webappapis.html#r
eport-the-exception | 25 [report the exception]: https://html.spec.whatwg.org/multipage/webappapis.html#r
eport-the-exception |
| 26 --> | 26 --> |
| 27 <template id="constructor-throws"> | 27 <template id="constructor-throws"> |
| 28 <script> | 28 <script> |
| 29 'use strict'; | 29 'use strict'; |
| 30 window.errors = []; | 30 window.errors = []; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 const error = new Error(rethrowErrorMessage); | 48 const error = new Error(rethrowErrorMessage); |
| 49 error.name = rethrowErrorName; | 49 error.name = rethrowErrorName; |
| 50 throw error; | 50 throw error; |
| 51 } | 51 } |
| 52 }); | 52 }); |
| 53 </script> | 53 </script> |
| 54 </template> | 54 </template> |
| 55 <template id="instantiate"> | 55 <template id="instantiate"> |
| 56 <a-a></a-a> | 56 <a-a></a-a> |
| 57 </template> | 57 </template> |
| 58 <template id="createElement"> |
| 59 <script> |
| 60 window.e = document.createElement('a-a'); |
| 61 </script> |
| 62 </template> |
| 58 <script> | 63 <script> |
| 59 'use strict'; | 64 'use strict'; |
| 60 const rethrowErrorName = 'rethrown'; | 65 const rethrowErrorName = 'rethrown'; |
| 61 const rethrowErrorMessage = 'check this is rethrown'; | 66 const rethrowErrorMessage = 'check this is rethrown'; |
| 62 | 67 |
| 63 function assert_not_muted_error_event(error) { | 68 function assert_not_muted_error_event(error) { |
| 64 assert_not_equals(error, undefined, 'should fire error event'); | 69 assert_not_equals(error, undefined, 'should fire error event'); |
| 65 // Report an error, 6. If script has muted errors, ... | 70 // Report an error, 6. If script has muted errors, ... |
| 66 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error | 71 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error |
| 67 assert_false(error.event === 'Script error.' | 72 assert_false(error.event === 'Script error.' |
| 68 && error.source === '' && error.lineno === 0 && error.colno === 0 | 73 && error.source === '' && error.lineno === 0 && error.colno === 0 |
| 69 && error.error === null, | 74 && error.error === null, |
| 70 'the error should not be muted.'); | 75 'the error should not be muted.'); |
| 71 assert_false(!error.event, 'event (1st arg) should not be null'); | 76 assert_false(!error.event, 'event (1st arg) should not be null'); |
| 72 assert_false(!error.source, 'source (2nd arg) should not be null'); | 77 assert_false(!error.source, 'source (2nd arg) should not be null'); |
| 73 // The spec doesn't define valid values for lineno/colno. | 78 // The spec doesn't define valid values for lineno/colno. |
| 74 assert_false(!error.error, 'error (5th arg) should not be null'); | 79 assert_false(!error.error, 'error (5th arg) should not be null'); |
| 75 } | 80 } |
| 76 | 81 |
| 77 function assert_rethrown_error_event(error) { | 82 function assert_reported_error_event(error) { |
| 78 assert_not_muted_error_event(error); | 83 assert_not_muted_error_event(error); |
| 79 assert_equals(error.error.name, rethrowErrorName); | 84 assert_equals(error.error.name, rethrowErrorName); |
| 80 assert_equals(error.error.message, rethrowErrorMessage); | 85 assert_equals(error.error.message, rethrowErrorMessage); |
| 81 } | 86 } |
| 82 | 87 |
| 83 const constructor_throws = | 88 const constructor_throws = |
| 84 document.getElementById('constructor-throws').innerHTML; | 89 document.getElementById('constructor-throws').innerHTML; |
| 85 const instantiate = document.getElementById('instantiate').innerHTML; | 90 const instantiate = document.getElementById('instantiate').innerHTML; |
| 91 const create_element = document.getElementById('createElement').innerHTML; |
| 86 | 92 |
| 87 test_with_window((w) => { | 93 test_with_window((w) => { |
| 88 assert_rethrown_error_event(w.errors[0]); | 94 assert_reported_error_event(w.errors[0]); |
| 89 }, 'Document parser invokes the constructor that throws', | 95 }, 'Document parser invokes the constructor that throws', |
| 90 constructor_throws + instantiate); | 96 constructor_throws + instantiate); |
| 91 | 97 |
| 92 test_with_window((w) => { | 98 test_with_window((w) => { |
| 93 w.document.body.innerHTML = instantiate; | 99 w.document.body.innerHTML = instantiate; |
| 94 assert_rethrown_error_event(w.errors[0]); | 100 assert_reported_error_event(w.errors[0]); |
| 95 }, 'Upgrade reaction invokes the constructor that throws', | 101 }, 'Upgrade reaction invokes the constructor that throws', |
| 96 constructor_throws); | 102 constructor_throws); |
| 103 |
| 104 test_with_window((w) => { |
| 105 assert_reported_error_event(w.errors[0]); |
| 106 assert_true( |
| 107 w.e instanceof w.HTMLUnknownElement, |
| 108 'the created element should be HTMLUnknownElement'); |
| 109 }, 'createElement invokes the constructor that throws', |
| 110 constructor_throws + create_element); |
| 97 </script> | 111 </script> |
| 98 | 112 |
| 99 <!-- | 113 <!-- |
| 100 Test when JavaScript returns without throwing errors, but the result is invalid | 114 Test when JavaScript returns without throwing errors, but the result is invalid |
| 101 and thus UA should [report the exception]. | 115 and thus UA should [report the exception]. |
| 102 --> | 116 --> |
| 103 <template id="constructor-returns-bad-object"> | 117 <template id="constructor-returns-bad-object"> |
| 104 <script> | 118 <script> |
| 105 'use strict'; | 119 'use strict'; |
| 106 window.errors = []; | 120 window.errors = []; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 161 |
| 148 test_with_window((w) => { | 162 test_with_window((w) => { |
| 149 // "upgrade an element" 10, throw an InvalidStateError DOMException. | 163 // "upgrade an element" 10, throw an InvalidStateError DOMException. |
| 150 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades | 164 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades |
| 151 w.document.body.innerHTML = instantiate; | 165 w.document.body.innerHTML = instantiate; |
| 152 assert_invalid_state_dom_error_event(w.errors[0]); | 166 assert_invalid_state_dom_error_event(w.errors[0]); |
| 153 }, 'Upgrade reaction invokes the constructor that returns a bad object', | 167 }, 'Upgrade reaction invokes the constructor that returns a bad object', |
| 154 constructor_returns_bad_object); | 168 constructor_returns_bad_object); |
| 155 </script> | 169 </script> |
| 156 </body> | 170 </body> |
| OLD | NEW |