Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/WebKit/LayoutTests/custom-elements/spec/report-the-exception.html

Issue 2244203002: Fix "report the exception" in Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Took approach 7 and cleanup Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Custom Elements: report the exception</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="resources/custom-elements-helpers.js"></script>
6 <body>
7 <!--
8 The spec has two places where it says to [report the exception]:
9
10 1. In [create an element for a token], step 7.
11 This can occur only when [create an element] is invoked from
12 [create an element for a token] with the synchronous custom elements flag
13 set. The document parser uses this algorithm.
14 2. In [invoke custom element reactions], step 2.1.
15
16 There are different code paths when:
17 1. Author script throws an exception that is rethrown.
18 2. The user agent throws an exception.
19
20 This test contains 4 tests for the combination of the above 2x2.
21
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
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
26 -->
27 <template id="constructor-throws">
28 <script>
29 'use strict';
30 window.errors = [];
31 // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attribut es:handler-onerror
32 window.onerror = function (event, source, lineno, colno, error) {
33 errors.push({
34 event: event,
35 source: source,
36 lineno: lineno,
37 colno: colno,
38 error: error
39 });
40 return true; // Cancel the error event.
41 };
42
43 const rethrowErrorName = 'rethrown';
44 const rethrowErrorMessage = 'check this is rethrown';
45
46 customElements.define('a-a', class extends HTMLElement {
47 constructor() {
48 const error = new Error(rethrowErrorMessage);
49 error.name = rethrowErrorName;
50 throw error;
51 }
52 });
53 </script>
54 </template>
55 <template id="instantiate">
56 <a-a></a-a>
57 </template>
58 <script>
59 'use strict';
60 const rethrowErrorName = 'rethrown';
61 const rethrowErrorMessage = 'check this is rethrown';
62
63 function assert_not_muted_error_event(error) {
64 assert_not_equals(error, undefined, 'should fire error event');
65 // Report an error, 6. If script has muted errors, ...
66 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error
67 assert_false(error.event === 'Script error.'
68 && error.source === '' && error.lineno === 0 && error.colno === 0
69 && error.error === null,
70 'the error should not be muted.');
71 assert_false(!error.event, 'event (1st arg) should not be null');
72 assert_false(!error.source, 'source (2nd arg) should not be null');
73 // The spec doesn't define valid values for lineno/colno.
74 assert_false(!error.error, 'error (5th arg) should not be null');
75 }
76
77 function assert_rethrown_error_event(error) {
78 assert_not_muted_error_event(error);
79 assert_equals(error.error.name, rethrowErrorName);
80 assert_equals(error.error.message, rethrowErrorMessage);
81 }
82
83 const constructor_throws =
84 document.getElementById('constructor-throws').innerHTML;
85 const instantiate = document.getElementById('instantiate').innerHTML;
86
87 test_with_window((w) => {
88 assert_rethrown_error_event(w.errors[0]);
89 }, 'Document parser invokes the constructor that throws',
90 constructor_throws + instantiate);
91
92 test_with_window((w) => {
93 w.document.body.innerHTML = instantiate;
94 assert_rethrown_error_event(w.errors[0]);
95 }, 'Upgrade reaction invokes the constructor that throws',
96 constructor_throws);
97 </script>
98
99 <!--
100 Test when JavaScript returns without throwing errors, but the result is invalid
101 and thus UA should [report the exception].
102 -->
103 <template id="constructor-returns-bad-object">
104 <script>
105 'use strict';
106 window.errors = [];
107 // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attribut es:handler-onerror
108 window.onerror = function (event, source, lineno, colno, error) {
109 errors.push({
110 event: event,
111 source: source,
112 lineno: lineno,
113 colno: colno,
114 error: error
115 });
116 return true; // Cancel the error event.
117 };
118
119 customElements.define('a-a', class extends HTMLElement {
120 constructor() {
121 super();
122 return []; // returning objects other than "this" is invalid.
123 }
124 });
125 </script>
126 </template>
127 <script>
128 const constructor_returns_bad_object =
129 document.getElementById('constructor-returns-bad-object').innerHTML;
130
131 function assert_type_error_event(error) {
132 assert_not_muted_error_event(error);
133 assert_equals(error.error.name, 'TypeError');
134 }
135
136 function assert_invalid_state_dom_error_event(error) {
137 assert_not_muted_error_event(error);
138 assert_equals(error.error.name, 'InvalidStateError');
139 }
140
141 test_with_window((w) => {
142 // "create an element" 6.1.3, throw a TypeError.
143 // https://dom.spec.whatwg.org/#concept-create-element
144 assert_type_error_event(w.errors[0]);
145 }, 'Document parser invokes the constructor that returns a bad object',
146 constructor_returns_bad_object + instantiate);
147
148 test_with_window((w) => {
149 // "upgrade an element" 10, throw an InvalidStateError DOMException.
150 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades
151 w.document.body.innerHTML = instantiate;
152 assert_invalid_state_dom_error_event(w.errors[0]);
153 }, 'Upgrade reaction invokes the constructor that returns a bad object',
154 constructor_returns_bad_object);
155 </script>
156 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698