node/deps/v8/test/inspector/debugger/break-on-exception-async-gen.js
Michaël Zasso f226350fcb deps: update V8 to 11.3.244.4
PR-URL: https://github.com/nodejs/node/pull/47251
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2023-03-31 14:15:23 +00:00

119 lines
3.1 KiB
JavaScript

// 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)');
},
]);