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

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: New approach to use TryCatch::ReThrow Created 4 years, 4 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 custom elements spec has 2 places where it [report the exception]:
dominicc (has gone to gerrit) 2016/08/19 07:51:29 "it report" isn't right; it would need to be repor
9
10 1. In the [create an element for a token], step 7.
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Omit 'the', or give the article something to name,
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; i.e., the document parser.
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Might be more readable to avoid Latin, id est avoi
14 2. In the [invoke custom element reactions], step 2.1.
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Same as above, the ... algorithm or simply drop "t
15
16 Also it is likely that platform may run different code paths for:
dominicc (has gone to gerrit) 2016/08/19 07:51:29 singular "platform" needs an article. The platform
17 1. When JavaScript throws and the platform rethrows.
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Again, grammar; "for when JavaScript throws" isn't
18 2. When the platform throws.
19
20 This test contains 4 tests for the combination of the above 2x2.
21
22 [report the exception]: https://html.spec.whatwg.org/multipage/webappapis.html#r eport-the-exception
23 [create an element for a token]: https://html.spec.whatwg.org/multipage/syntax.h tml#create-an-element-for-the-token
24 [create an element]: https://dom.spec.whatwg.org/#concept-create-element
25 [invoke custom element reactions]: https://html.spec.whatwg.org/multipage/script ing.html#invoke-custom-element-reactions
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({
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Thank you. I know it is a bit verbose, but it is v
34 event: event,
35 source: source,
36 lineno: lineno,
37 colno: colno,
38 error: error,
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Maybe omit the trailing comma?
39 });
40 return true; // Cancel the error event.
41 };
42
43 const rethrowErrorName = 'rethrown';
44 const rethrowErrorMessage = 'check this is rethrown';
45
46 function create_rethrow_error() {
dominicc (has gone to gerrit) 2016/08/19 07:51:29 This is only used in one place; just inline it?
47 const error = new Error(rethrowErrorMessage);
48 error.name = rethrowErrorName;
49 return error;
50 }
51
52 customElements.define('a-a', class extends HTMLElement {
53 constructor() {
54 throw create_rethrow_error();
55 }
56 });
57 </script>
58 </template>
59 <template id="instantiate">
60 <a-a></a-a>
61 </template>
62 <script>
63 'use strict';
64 const rethrowErrorName = 'rethrown';
65 const rethrowErrorMessage = 'check this is rethrown';
66
67 function assert_not_muted_error_event(error) {
68 // Report an error, 6. If script has muted errors, ...
69 // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error
70 assert_false(error.event === 'Script error.'
71 && error.source === '' && error.lineno === 0 && error.colno === 0
72 && error.error === null,
73 'the error should not be muted.');
74 assert_false(!error.event, 'event (1st arg) should not be null');
75 assert_false(!error.source, 'source (2nd arg) should not be null');
76 // The spec doesn't define valid values for lineno/colno.
77 assert_false(!error.error, 'error (5th arg) should not be null');
78 }
79
80 function assert_rethrown_error_event(error) {
81 assert_not_muted_error_event(error);
82 assert_equals(error.error.name, rethrowErrorName);
83 assert_equals(error.error.message, rethrowErrorMessage);
84 }
85
86 const constructor_throws =
87 document.getElementById('constructor-throws').innerHTML;
dominicc (has gone to gerrit) 2016/08/19 07:51:29 Indent two additional spaces.
88 const instantiate = document.getElementById('instantiate').innerHTML;
89
90 test_with_window((w) => {
91 assert_rethrown_error_event(w.errors[0]);
92 }, 'Document parser invokes the constructor that throws',
93 constructor_throws + instantiate);
94
95 test_with_window((w) => {
96 w.document.body.innerHTML = instantiate;
97 assert_rethrown_error_event(w.errors[0]);
98 }, 'Upgrade reaction invokes the constructor that throws',
99 constructor_throws);
100 </script>
101
102 <!--
103 Test when JavaScript returns without throwing errors, but the result is invalid
104 and thus UA should [report the exception].
105 -->
106 <template id="constructor-returns-bad-object">
107 <script>
108 'use strict';
109 window.errors = [];
110 // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attribut es:handler-onerror
111 window.onerror = function (event, source, lineno, colno, error) {
112 errors.push({
113 event: event,
114 source: source,
115 lineno: lineno,
116 colno: colno,
117 error: error,
118 });
119 return true; // Cancel the error event.
120 };
121
122 customElements.define('a-a', class extends HTMLElement {
123 constructor() {
124 super();
125 return []; // returning other objects than "this" is invalid.
dominicc (has gone to gerrit) 2016/08/19 07:51:29 objects other than "this" I'm not 100% sure this
126 }
127 });
128 </script>
129 </template>
130 <script>
131 const constructor_returns_bad_object =
132 document.getElementById('constructor-returns-bad-object').innerHTML;
133
134 function assert_type_error_event(error) {
135 assert_not_muted_error_event(error);
136 assert_equals(error.error.name, 'TypeError');
137 }
138
139 function assert_invalid_state_dom_error_event(error) {
140 assert_not_muted_error_event(error);
141 assert_equals(error.error.name, 'InvalidStateError');
142 }
143
144 test_with_window((w) => {
145 // "create an element" 6.1.3, throw a TypeError.
146 // https://dom.spec.whatwg.org/#concept-create-element
147 assert_type_error_event(w.errors[0]);
148 }, 'Document parser invokes the constructor that returns a bad object',
149 constructor_returns_bad_object + instantiate);
150
151 test_with_window((w) => {
152 // "upgrade an element" 10, throw an InvalidStateError DOMException.
153 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades
154 w.document.body.innerHTML = instantiate;
155 assert_invalid_state_dom_error_event(w.errors[0]);
156 }, 'Upgrade reaction invokes the constructor that returns a bad object',
157 constructor_returns_bad_object);
158 </script>
159 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698