1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright 2023 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.
let {session, contextGroup, Protocol} = InspectorTest.start('Check that "break on exceptions" works for async generators.');
contextGroup.addScript(`
async function* simpleThrow() {
throw new Error();
}
async function* yieldBeforeThrow() {
yield 1;
throw new Error();
}
async function* awaitBeforeThrow() {
await 1;
throw new Error();
}
async function* yieldBeforeThrowWithAwait() {
await 1;
yield 2;
throw new Error();
}
async function* awaitBeforeThrowWithYield() {
yield 1;
await 2;
throw new Error();
}
async function* yieldThrows() {
yield 1;
yield thrower();
}
async function* awaitThrows() {
yield 1;
await thrower();
}
async function runGenWithCatch(gen) {
try {
for await (const val of gen());
} catch {}
}
async function runGenWithoutCatch(gen) {
for await (const val of gen());
}
async function thrower() {
await 1; // Suspend once.
throw new Error();
}`);
Protocol.Debugger.onPaused(async ({ params: { data }}) => {
const caughtOrUncaught = data.uncaught ? 'UNCAUGHT' : 'CAUGHT';
InspectorTest.log(`Paused for ${caughtOrUncaught} exception.`);
await Protocol.Debugger.resume();
});
async function runTest(expression) {
await Promise.all([
Protocol.Debugger.enable(),
Protocol.Debugger.setPauseOnExceptions({state: 'all'}),
]);
await Protocol.Runtime.evaluate({ expression, awaitPromise: true });
await Protocol.Debugger.disable();
}
InspectorTest.runAsyncTestSuite([
async function testSimpleGeneratorThrowCaught() {
await runTest('runGenWithCatch(simpleThrow)');
},
async function testSimpleGeneratorThrowUncaught() {
await runTest('runGenWithoutCatch(simpleThrow)');
},
async function testYieldBeforeThrowCaught() {
await runTest('runGenWithCatch(yieldBeforeThrow)');
},
async function testYieldBeforeThrowUncaught() {
await runTest('runGenWithoutCatch(yieldBeforeThrow)');
},
async function testAwaitBeforeThrowCaught() {
await runTest('runGenWithCatch(awaitBeforeThrow)');
},
async function testAwaitBeforeThrowUncaught() {
await runTest('runGenWithoutCatch(awaitBeforeThrow)');
},
async function testYieldBeforeThrowWithAwaitCaught() {
await runTest('runGenWithCatch(yieldBeforeThrowWithAwait)');
},
async function testYieldBeforeThrowWithAwaitUncaught() {
await runTest('runGenWithoutCatch(yieldBeforeThrowWithAwait)');
},
async function testAwaitBeforeThrowWithYieldCaught() {
await runTest('runGenWithCatch(awaitBeforeThrowWithYield)');
},
async function testAwaitBeforeThrowWithYieldUncaught() {
await runTest('runGenWithoutCatch(awaitBeforeThrowWithYield)');
},
async function testYieldThrowsCaught() {
await runTest('runGenWithCatch(yieldThrows)');
},
async function testYieldThrowsUncaught() {
await runTest('runGenWithoutCatch(yieldThrows)');
},
async function testAwaitThrowsCaught() {
await runTest('runGenWithCatch(awaitThrows)');
},
async function testAwaitThrowsUncaught() {
await runTest('runGenWithoutCatch(awaitThrows)');
},
]);
|