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 events = 0; | |
10 | |
11 function listener(event, exec_state, event_data, data) { | |
12 if (event != Debug.DebugEvent.Exception) return; | |
13 events++; | |
14 } | |
15 | |
16 async function thrower() { | |
17 throw "a"; // Exception a | |
18 } | |
19 | |
20 var reject = () => Promise.reject("b"); // Exception b | |
21 | |
22 async function awaitReturn() { await 1; return; } | |
23 | |
24 async function scalar() { return 1; } | |
25 | |
26 function nothing() { return 1; } | |
27 | |
28 function rejectConstructor() { | |
29 return new Promise((resolve, reject) => reject("c")); // Exception c | |
30 } | |
31 | |
32 async function argThrower(x = (() => { throw "d"; })()) { } // Exception d | |
33 | |
34 function suppressThrow() { | |
35 return thrower(); | |
36 } | |
37 | |
38 async function caught(producer) { | |
39 try { | |
40 await producer(); | |
41 } catch (e) { | |
42 } | |
43 } | |
44 | |
45 async function uncaught(producer) { | |
46 await producer(); | |
47 } | |
48 | |
49 async function indirectUncaught(producer) { | |
50 await uncaught(producer); | |
51 } | |
52 | |
53 async function indirectCaught(producer) { | |
54 try { | |
55 await uncaught(producer); | |
56 } catch (e) { | |
57 } | |
58 } | |
59 | |
60 function dotCatch(producer) { | |
61 Promise.resolve(producer()).catch(() => {}); | |
62 } | |
63 | |
64 function indirectReturnDotCatch(producer) { | |
65 (async() => producer())().catch(() => {}); | |
66 } | |
67 | |
68 function indirectAwaitDotCatch(producer) { | |
69 (async() => await producer())().catch(() => {}); | |
70 } | |
71 | |
72 function nestedDotCatch(producer) { | |
73 Promise.resolve(producer()).then().catch(() => {}); | |
74 } | |
75 | |
76 async function indirectAwaitCatch(producer) { | |
77 try { | |
78 await (() => producer())(); | |
79 } catch (e) { | |
80 } | |
81 } | |
82 | |
83 let catches = [caught, indirectCaught, indirectAwaitCatch]; | |
84 let noncatches = [uncaught, indirectUncaught]; | |
85 let lateCatches = [dotCatch, | |
86 indirectReturnDotCatch, | |
87 indirectAwaitDotCatch, | |
88 nestedDotCatch]; | |
89 | |
90 let throws = [thrower, reject, argThrower, suppressThrow]; | |
91 let nonthrows = [awaitReturn, scalar, nothing]; | |
92 let uncatchable = [rejectConstructor]; | |
93 | |
94 let cases = []; | |
95 | |
96 for (let producer of throws) { | |
97 for (let consumer of catches) { | |
98 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
99 cases.push({ producer, consumer, expectedEvents: 0, caught: false }); | |
100 } | |
101 } | |
102 | |
103 for (let producer of throws) { | |
104 for (let consumer of noncatches) { | |
105 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
106 cases.push({ producer, consumer, expectedEvents: 1, caught: false }); | |
107 } | |
108 } | |
109 | |
110 for (let producer of nonthrows) { | |
111 for (let consumer of catches.concat(noncatches, lateCatches)) { | |
112 cases.push({ producer, consumer, expectedEvents: 0, caught: true }); | |
113 cases.push({ producer, consumer, expectedEvents: 0, caught: false }); | |
114 } | |
115 } | |
116 | |
117 for (let producer of uncatchable) { | |
118 for (let consumer of catches.concat(noncatches, lateCatches)) { | |
119 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
120 cases.push({ producer, consumer, expectedEvents: 1, caught: false }); | |
121 } | |
122 } | |
123 | |
124 for (let producer of throws) { | |
125 for (let consumer of lateCatches) { | |
126 cases.push({ producer, consumer, expectedEvents: 1, caught: true }); | |
127 cases.push({ producer, consumer, expectedEvents: 1, caught: false }); | |
128 } | |
129 } | |
130 | |
131 for (let {producer, consumer, expectedEvents, caught} of cases) { | |
132 Debug.setListener(listener); | |
133 if (caught) | |
134 Debug.setBreakOnException(); | |
135 else | |
136 Debug.setBreakOnUncaughtException(); | |
137 | |
138 events = 0; | |
139 consumer(producer); | |
140 %RunMicrotasks(); | |
141 | |
142 Debug.setListener(null); | |
143 if (caught) Debug.clearBreakOnException(); | |
kozy
2016/09/12 18:13:56
Please format it as if in line 133.
Dan Ehrenberg
2016/09/12 22:12:11
Done
| |
144 else Debug.clearBreakOnUncaughtException(); | |
145 if (expectedEvents != events) { | |
146 print(`producer ${producer} consumer ${consumer} expectedEvents ` + | |
147 `${expectedEvents} caught ${caught} events ${events}`); | |
148 quit(1); | |
149 } | |
150 } | |
OLD | NEW |