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

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: Renamed to ErrorEventDispatcher 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]:
9
10 1. In the [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; i.e., the document parser.
14 2. In the [invoke custom element reactions], step 2.1.
15
16 Also it is likely that platform may run different code paths for:
17 1. When JavaScript throws and the platform rethrows.
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="common">
28 <script>
29 'use strict';
30 window.errors = [];
31 window.onerror = function () {
32 errors.push(Array.prototype.slice.call(arguments));
33 return true; // Cancel the error event.
34 };
35 </script>
36 </template>
37 <template id="constructor-throws">
38 <script>
39 const rethrowErrorName = 'rethrown';
40 const rethrowErrorMessage = 'check this is rethrown';
41
42 function create_rethrow_error() {
43 const error = new Error(rethrowErrorMessage);
44 error.name = rethrowErrorName;
45 return error;
46 }
47
48 customElements.define('a-a', class extends HTMLElement {
49 constructor() {
50 throw create_rethrow_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_rethrown(error) {
64 assert_equals(error.name, rethrowErrorName);
65 assert_equals(error.message, rethrowErrorMessage);
66 }
67
68 const common = document.getElementById('common').innerHTML;
69 const constructor_throws = common
70 + document.getElementById('constructor-throws').innerHTML;
71 const instantiate = document.getElementById('instantiate').innerHTML;
72
73 test_with_window(w => {
74 assert_rethrown(w.errors[0][4]);
75 }, 'Document parser invokes the constructor that throws',
76 constructor_throws + instantiate);
77
78 test_with_window(w => {
79 w.document.body.innerHTML = instantiate;
80 assert_rethrown(w.errors[0][4]);
81 }, 'Upgrade reaction invokes the constructor that throws',
82 constructor_throws);
83 </script>
84
85 <!--
86 -->
87 <template id="constructor-returns-bad-object">
88 <script>
89 customElements.define('a-a', class extends HTMLElement {
90 constructor() {
91 super();
92 return []; // returning other objects than "this" is invalid.
93 }
94 });
95 </script>
96 </template>
97 <script>
98 const constructor_returns_bad_object = common
99 + document.getElementById('constructor-returns-bad-object').innerHTML;
100
101 function assert_type_error(error) {
102 assert_equals(error.name, 'TypeError');
103 }
104
105 function assert_invalid_state_dom_error(error) {
106 assert_equals(error.name, 'InvalidStateError');
107 }
108
109 test_with_window(w => {
110 // "create an element" 6.1.3, throw a TypeError.
111 // https://dom.spec.whatwg.org/#concept-create-element
112 assert_type_error(w.errors[0][4]);
113 }, 'Document parser invokes the constructor that returns a bad object',
114 constructor_returns_bad_object + instantiate);
115
116 test_with_window(w => {
117 // "upgrade an element" 10, throw an InvalidStateError DOMException.
118 // https://html.spec.whatwg.org/multipage/scripting.html#upgrades
119 w.document.body.innerHTML = instantiate;
120 assert_invalid_state_dom_error(w.errors[0][4]);
121 }, 'Upgrade reaction invokes the constructor that returns a bad object',
122 constructor_returns_bad_object);
123 </script>
124 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698