Chromium Code Reviews| Index: test/mjsunit/harmony/async-debug-caught-exception2.js |
| diff --git a/test/mjsunit/harmony/async-debug-caught-exception2.js b/test/mjsunit/harmony/async-debug-caught-exception2.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..97f2c14dce10873b5d2ae073a5603833a145b9f1 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/async-debug-caught-exception2.js |
| @@ -0,0 +1,191 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --allow-natives-syntax --harmony-async-await --expose-debug-as debug |
| + |
| +Debug = debug.Debug |
| + |
| +let exception = null; |
|
jgruber
2016/09/08 10:19:58
This is never set.
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
|
| +let events = 0; |
| + |
| +function listener(event, exec_state, event_data, data) { |
| + if (event != Debug.DebugEvent.Exception) return; |
| + try { |
| + events++; |
|
jgruber
2016/09/08 10:19:58
Can this ever fail?
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
|
| + } catch (e) { |
| + %AbortJS(e + "\n" + e.stack); |
| + } |
| +} |
| + |
| +async function thrower() { |
| + throw "a"; // Exception a |
| +} |
| + |
| +var reject = () => Promise.reject("b"); // Exception b |
| + |
| +async function awaitReturn() { await 1; return; } |
| + |
| +async function scalar() { return 1; } |
| + |
| +function nothing() { return 1; } |
| + |
| +function rejectConstructor() { |
| + return new Promise((resolve, reject) => reject("c")); // Exception c |
| +} |
| + |
| +async function argThrower(x = (() => { throw "d"; })()) { } // Exception d |
| + |
| +async function awaitThrow() { |
| + await undefined; |
| + throw "e"; // Exception e |
| +} |
| + |
| +function constructorThrow() { |
| + return new Promise((resolve, reject) => |
| + Promise.resolve().then(() => |
| + reject("f") // Exception f |
| + ) |
| + ); |
| +} |
| + |
| +function suppressThrow() { |
| + return thrower(); |
| +} |
| + |
| +async function caught(producer) { |
| + try { |
| + await producer(); |
| + } catch (e) { |
| + } |
| +} |
| + |
| +async function uncaught(producer) { |
| + await producer(); |
| +} |
| + |
| +async function caught(producer) { |
|
jgruber
2016/09/08 10:19:58
Duplicate from above.
Dan Ehrenberg
2016/09/08 22:34:04
Deleted
|
| + try { |
| + await producer(); |
| + } catch (e) { |
| + } |
| +} |
| + |
| +async function indirectUncaught(producer) { |
| + await uncaught(producer); |
| +} |
| + |
| +async function indirectCaught(producer) { |
| + try { |
| + await uncaught(producer); |
| + } catch (e) { |
| + } |
| +} |
| + |
| +function dotCatch(producer) { |
| + Promise.resolve(producer()).catch(() => {}); |
| +} |
| + |
| +function indirectReturnDotCatch(producer) { |
| + (async() => producer())().catch(() => {}); |
| +} |
| + |
| +function indirectAwaitDotCatch(producer) { |
| + (async() => await producer())().catch(() => {}); |
| +} |
| + |
| +function nestedDotCatch(producer) { |
| + Promise.resolve(producer()).then().catch(() => {}); |
| +} |
| + |
| +async function indirectAwaitCatch(producer) { |
| + try { |
| + await (() => producer())(); |
| + } catch (e) { |
| + } |
| +} |
| + |
| +let catches = [caught, indirectCaught, indirectAwaitCatch]; |
| +let noncatches = [uncaught, indirectUncaught]; |
| +let lateCatches = [dotCatch, indirectReturnDotCatch, indirectAwaitDotCatch, nestedDotCatch]; |
|
jgruber
2016/09/08 10:19:58
Nit: 80 columns here and below.
Dan Ehrenberg
2016/09/08 22:34:04
Fixed
|
| + |
| +let throws = [thrower, reject, argThrower, suppressThrow]; |
| +let nonthrows = [awaitReturn, scalar, nothing]; |
| +// TODO(littledan): Build a dependency graph to track the relationship between Promises |
| +// linked by async/await, and enable tests so that |
| +// 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
|
| +let lateThrows = []; |
| + |
| +let cases = []; |
| + |
| +for (let producer of throws.concat(lateThrows)) { |
| + for (let consumer of catches) { |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: true }); |
| + cases.push({ producer, consumer, expectedEvents: 0, caught: false }); |
| + } |
| +} |
| + |
| +for (let producer of throws.concat(lateThrows)) { |
| + for (let consumer of noncatches) { |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: true }); |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: false }); |
| + } |
| +} |
| + |
| +for (let producer of nonthrows) { |
| + for (let consumer of catches.concat(noncatches, lateCatches)) { |
| + cases.push({ producer, consumer, expectedEvents: 0, caught: true }); |
| + cases.push({ producer, consumer, expectedEvents: 0, caught: false }); |
| + } |
| +} |
| + |
| +for (let producer of lateThrows) { |
| + for (let consumer of lateCatches) { |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: true }); |
| + cases.push({ producer, consumer, expectedEvents: 0, caught: false }); |
| + } |
| +} |
| + |
| +for (let producer of throws) { |
| + for (let consumer of lateCatches) { |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: true }); |
| + cases.push({ producer, consumer, expectedEvents: 1, caught: false }); |
| + } |
| +} |
| + |
| +const tonsOfTasks = 50; |
| + |
| +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
|
| + if (tasks === 0) callback(); |
| + else %EnqueueMicrotask(() => afterWaiting(callback, tasks - 1)); |
| +} |
| + |
| +let failureCount = 0; |
| + |
| +for (let {producer, consumer, expectedEvents, caught} of cases) { |
| + events = 0; |
| + Debug.setListener(listener); |
| + if (caught) |
| + Debug.setBreakOnException(); |
| + else |
| + Debug.setBreakOnUncaughtException(); |
| + |
| + consumer(producer); |
| + |
| + %RunMicrotasks(); |
| + |
| + Debug.setListener(null); |
| + if (caught) Debug.clearBreakOnException(); |
| + else Debug.clearBreakOnUncaughtException(); |
| + if (expectedEvents != events || exception) { |
| + print(`producer ${producer} consumer ${consumer} expectedEvents ` + |
| + `${expectedEvents} caught ${caught} events ${events} exception ` + |
| + `${exception}`); |
| + failureCount++; |
| + } |
| +} |
| + |
| +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
|
| + print(`failureCount ${failureCount}`); |
| + quit(1); |
| +} |