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

Side by Side Diff: test/mjsunit/harmony/async-debug-caught-exception-cases.js

Issue 2487673002: [debugger] Basic scope functionality and exception events in wrapper (Closed)
Patch Set: Formatting Created 4 years, 1 month 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 // 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 async function awaitThrow() {
35 await undefined;
36 throw "e"; // Exception e
37 }
38
39 function constructorThrow() {
40 return new Promise((resolve, reject) =>
41 Promise.resolve().then(() =>
42 reject("f") // Exception f
43 )
44 );
45 }
46
47 function suppressThrow() {
48 return thrower();
49 }
50
51 async function caught(producer) {
52 try {
53 await producer();
54 } catch (e) {
55 }
56 }
57
58 async function uncaught(producer) {
59 await producer();
60 }
61
62 async function indirectUncaught(producer) {
63 await uncaught(producer);
64 }
65
66 async function indirectCaught(producer) {
67 try {
68 await uncaught(producer);
69 } catch (e) {
70 }
71 }
72
73 function dotCatch(producer) {
74 Promise.resolve(producer()).catch(() => {});
75 }
76
77 function indirectReturnDotCatch(producer) {
78 (async() => producer())().catch(() => {});
79 }
80
81 function indirectAwaitDotCatch(producer) {
82 (async() => await producer())().catch(() => {});
83 }
84
85 function nestedDotCatch(producer) {
86 Promise.resolve(producer()).then().catch(() => {});
87 }
88
89 async function indirectAwaitCatch(producer) {
90 try {
91 await (() => producer())();
92 } catch (e) {
93 }
94 }
95
96 function switchCatch(producer) {
97 let resolve;
98 let promise = new Promise(r => resolve = r);
99 async function localCaught() {
100 try {
101 await promise; // force switching to localUncaught and back
102 await producer();
103 } catch (e) { }
104 }
105 async function localUncaught() {
106 await undefined;
107 resolve();
108 }
109 localCaught();
110 localUncaught();
111 }
112
113 function switchDotCatch(producer) {
114 let resolve;
115 let promise = new Promise(r => resolve = r);
116 async function localCaught() {
117 await promise; // force switching to localUncaught and back
118 await producer();
119 }
120 async function localUncaught() {
121 await undefined;
122 resolve();
123 }
124 localCaught().catch(() => {});
125 localUncaught();
126 }
127
128 let catches = [caught,
129 indirectCaught,
130 indirectAwaitCatch,
131 switchCatch,
132 switchDotCatch];
133 let noncatches = [uncaught, indirectUncaught];
134 let lateCatches = [dotCatch,
135 indirectReturnDotCatch,
136 indirectAwaitDotCatch,
137 nestedDotCatch];
138
139 let throws = [thrower, reject, argThrower, suppressThrow];
140 let nonthrows = [awaitReturn, scalar, nothing];
141 let lateThrows = [awaitThrow, constructorThrow];
142 let uncatchable = [rejectConstructor];
143
144 let cases = [];
145
146 for (let producer of throws.concat(lateThrows)) {
147 for (let consumer of catches) {
148 cases.push({ producer, consumer, expectedEvents: 1, caught: true });
149 cases.push({ producer, consumer, expectedEvents: 0, caught: false });
150 }
151 }
152
153 for (let producer of throws.concat(lateThrows)) {
154 for (let consumer of noncatches) {
155 cases.push({ producer, consumer, expectedEvents: 1, caught: true });
156 cases.push({ producer, consumer, expectedEvents: 1, caught: false });
157 }
158 }
159
160 for (let producer of nonthrows) {
161 for (let consumer of catches.concat(noncatches, lateCatches)) {
162 cases.push({ producer, consumer, expectedEvents: 0, caught: true });
163 cases.push({ producer, consumer, expectedEvents: 0, caught: false });
164 }
165 }
166
167 for (let producer of uncatchable) {
168 for (let consumer of catches.concat(noncatches, lateCatches)) {
169 cases.push({ producer, consumer, expectedEvents: 1, caught: true });
170 cases.push({ producer, consumer, expectedEvents: 1, caught: false });
171 }
172 }
173
174 for (let producer of lateThrows) {
175 for (let consumer of lateCatches) {
176 cases.push({ producer, consumer, expectedEvents: 1, caught: true });
177 cases.push({ producer, consumer, expectedEvents: 0, caught: false });
178 }
179 }
180
181 for (let producer of throws) {
182 for (let consumer of lateCatches) {
183 cases.push({ producer, consumer, expectedEvents: 1, caught: true });
184 cases.push({ producer, consumer, expectedEvents: 1, caught: false });
185 }
186 }
187
188
189 function runPart(n) {
190 let subcases = cases.slice(n * cases.length / 4,
191 ((n + 1) * cases.length) / 4);
192 for (let {producer, consumer, expectedEvents, caught} of subcases) {
193 Debug.setListener(listener);
194 if (caught) {
195 Debug.setBreakOnException();
196 } else {
197 Debug.setBreakOnUncaughtException();
198 }
199
200 events = 0;
201 consumer(producer);
202 %RunMicrotasks();
203
204 Debug.setListener(null);
205 if (caught) {
206 Debug.clearBreakOnException();
207 } else {
208 Debug.clearBreakOnUncaughtException();
209 }
210 if (expectedEvents != events) {
211 print(`producer ${producer} consumer ${consumer} expectedEvents ` +
212 `${expectedEvents} caught ${caught} events ${events}`);
213 quit(1);
214 }
215 }
216 }
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/async-debug-caught-exception.js ('k') | test/mjsunit/harmony/async-debug-caught-exception-cases0.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698