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

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

Issue 2325813002: Async/await catch prediction for "the synchronous case" (Closed)
Patch Set: TryCall 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/runtime/runtime-internal.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 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
139 events = 0;
140 consumer(producer);
141 %RunMicrotasks();
142
143 Debug.setListener(null);
144 if (caught) {
145 Debug.clearBreakOnException();
146 } else {
147 Debug.clearBreakOnUncaughtException();
148 }
149 if (expectedEvents != events) {
150 print(`producer ${producer} consumer ${consumer} expectedEvents ` +
151 `${expectedEvents} caught ${caught} events ${events}`);
152 quit(1);
153 }
154 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698