OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug | |
6 | |
7 Debug = debug.Debug | |
8 | |
9 let exception = null; | |
jgruber
2016/09/08 10:19:58
This is never set.
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
| |
10 let events = 0; | |
11 | |
12 function listener(event, exec_state, event_data, data) { | |
13 if (event != Debug.DebugEvent.Exception) return; | |
14 try { | |
15 events++; | |
jgruber
2016/09/08 10:19:58
Can this ever fail?
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
| |
16 } catch (e) { | |
17 %AbortJS(e + "\n" + e.stack); | |
18 } | |
19 } | |
20 | |
21 async function thrower() { | |
22 throw "a"; // Exception a | |
23 } | |
24 | |
25 var reject = () => Promise.reject("b"); // Exception b | |
26 | |
27 async function awaitReturn() { await 1; return; } | |
28 | |
29 async function scalar() { return 1; } | |
30 | |
31 function nothing() { return 1; } | |
32 | |
33 function rejectConstructor() { | |
34 return new Promise((resolve, reject) => reject("c")); // Exception c | |
35 } | |
36 | |
37 async function argThrower(x = (() => { throw "d"; })()) { } // Exception d | |
38 | |
39 async function awaitThrow() { | |
40 await undefined; | |
41 throw "e"; // Exception e | |
42 } | |
43 | |
44 function constructorThrow() { | |
45 return new Promise((resolve, reject) => | |
46 Promise.resolve().then(() => | |
47 reject("f") // Exception f | |
48 ) | |
49 ); | |
50 } | |
51 | |
52 function suppressThrow() { | |
53 return thrower(); | |
54 } | |
55 | |
56 async function caught(producer) { | |
57 try { | |
58 await producer(); | |
59 } catch (e) { | |
60 } | |
61 } | |
62 | |
63 async function uncaught(producer) { | |
64 await producer(); | |
65 } | |
66 | |
67 async function caught(producer) { | |
jgruber
2016/09/08 10:19:58
Duplicate from above.
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
| |
68 try { | |
69 await producer(); | |
70 } catch (e) { | |
71 } | |
72 } | |
73 | |
74 async function indirectUncaught(producer) { | |
75 await uncaught(producer); | |
76 } | |
77 | |
78 async function indirectCaught(producer) { | |
79 try { | |
80 await uncaught(producer); | |
81 } catch (e) { | |
82 } | |
83 } | |
84 | |
85 function dotCatch(producer) { | |
86 Promise.resolve(producer()).catch(() => {}); | |
87 } | |
88 | |
89 function indirectReturnDotCatch(producer) { | |
90 (async() => producer())().catch(() => {}); | |
91 } | |
92 | |
93 function indirectAwaitDotCatch(producer) { | |
94 (async() => await producer())().catch(() => {}); | |
95 } | |
96 | |
97 function nestedDotCatch(producer) { | |
98 Promise.resolve(producer()).then().catch(() => {}); | |
99 } | |
100 | |
101 async function indirectAwaitCatch(producer) { | |
102 try { | |
103 await (() => producer())(); | |
104 } catch (e) { | |
105 } | |
106 } | |
107 | |
108 let catches = [caught, indirectCaught, indirectAwaitCatch]; | |
109 let noncatches = [uncaught, indirectUncaught]; | |
110 let lateCatches = [dotCatch, indirectReturnDotCatch, indirectAwaitDotCatch, nest edDotCatch]; | |
jgruber
2016/09/08 10:19:58
Nit: 80 columns here and below.
Dan Ehrenberg
2016/09/08 22:34:04
Fixed
| |
111 | |
112 let throws = [thrower, reject, argThrower, suppressThrow]; | |
113 let nonthrows = [awaitReturn, scalar, nothing]; | |
114 // TODO(littledan): Build a dependency graph to track the relationship between P romises | |
115 // linked by async/await, and enable tests so that | |
116 // let lateThrows = [awaitThrow, constructorThrow, rejectConstructor]; | |
jgruber
2016/09/08 10:19:58
Maybe we could add these (awaitThrow, constructorT
Dan Ehrenberg
2016/09/08 22:34:04
Done
Dan Ehrenberg
2016/09/08 22:34:04
Done
| |
117 let lateThrows = []; | |
118 | |
119 let cases = []; | |
120 | |
121 for (let producer of throws.concat(lateThrows)) { | |
122 for (let consumer of catches) { | |
123 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
124 cases.push({ producer, consumer, expectedEvents: 0, caught: false }); | |
125 } | |
126 } | |
127 | |
128 for (let producer of throws.concat(lateThrows)) { | |
129 for (let consumer of noncatches) { | |
130 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
131 cases.push({ producer, consumer, expectedEvents: 1, caught: false }); | |
132 } | |
133 } | |
134 | |
135 for (let producer of nonthrows) { | |
136 for (let consumer of catches.concat(noncatches, lateCatches)) { | |
137 cases.push({ producer, consumer, expectedEvents: 0, caught: true }); | |
138 cases.push({ producer, consumer, expectedEvents: 0, caught: false }); | |
139 } | |
140 } | |
141 | |
142 for (let producer of lateThrows) { | |
143 for (let consumer of lateCatches) { | |
144 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
145 cases.push({ producer, consumer, expectedEvents: 0, caught: false }); | |
146 } | |
147 } | |
148 | |
149 for (let producer of throws) { | |
150 for (let consumer of lateCatches) { | |
151 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
152 cases.push({ producer, consumer, expectedEvents: 1, caught: false }); | |
153 } | |
154 } | |
155 | |
156 const tonsOfTasks = 50; | |
157 | |
158 function afterWaiting(callback, tasks = tonsOfTasks) { | |
jgruber
2016/09/08 10:19:58
This appears to be unused.
Dan Ehrenberg
2016/09/08 22:34:05
Removed
| |
159 if (tasks === 0) callback(); | |
160 else %EnqueueMicrotask(() => afterWaiting(callback, tasks - 1)); | |
161 } | |
162 | |
163 let failureCount = 0; | |
164 | |
165 for (let {producer, consumer, expectedEvents, caught} of cases) { | |
166 events = 0; | |
167 Debug.setListener(listener); | |
168 if (caught) | |
169 Debug.setBreakOnException(); | |
170 else | |
171 Debug.setBreakOnUncaughtException(); | |
172 | |
173 consumer(producer); | |
174 | |
175 %RunMicrotasks(); | |
176 | |
177 Debug.setListener(null); | |
178 if (caught) Debug.clearBreakOnException(); | |
179 else Debug.clearBreakOnUncaughtException(); | |
180 if (expectedEvents != events || exception) { | |
181 print(`producer ${producer} consumer ${consumer} expectedEvents ` + | |
182 `${expectedEvents} caught ${caught} events ${events} exception ` + | |
183 `${exception}`); | |
184 failureCount++; | |
185 } | |
186 } | |
187 | |
188 if (failureCount > 0) { | |
jgruber
2016/09/08 10:19:58
What about assertEquals() here (or above in the lo
Dan Ehrenberg
2016/09/08 22:34:04
Now it exits at the first failure (though this for
| |
189 print(`failureCount ${failureCount}`); | |
190 quit(1); | |
191 } | |
OLD | NEW |