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

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

Issue 2286753002: Synchronous path changes
Patch Set: Created 4 years, 3 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
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 exception = null;
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++;
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) {
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];
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];
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) {
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 assertEquals(expectedEvents, events);
181 assertNull(exception);
182 }
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698