Commit 2e796df5 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[async] Fix async stack traces for errors created after Promise.reject

Also capture async stack traces if we're in a reject handler.

Fixes node issue https://github.com/nodejs/node/issues/30822

Change-Id: I703012ddb88b5b5d17baba843a969b398ef99fa1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1969897
Auto-Submit: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65687}
parent 0f0329cf
......@@ -1011,7 +1011,11 @@ Handle<Object> CaptureStackTrace(Isolate* isolate, Handle<Object> caller,
IsBuiltinFunction(isolate, promise_reaction_job_task->handler(),
Builtins::kAsyncGeneratorAwaitResolveClosure) ||
IsBuiltinFunction(isolate, promise_reaction_job_task->handler(),
Builtins::kAsyncGeneratorYieldResolveClosure)) {
Builtins::kAsyncGeneratorYieldResolveClosure) ||
IsBuiltinFunction(isolate, promise_reaction_job_task->handler(),
Builtins::kAsyncFunctionAwaitRejectClosure) ||
IsBuiltinFunction(isolate, promise_reaction_job_task->handler(),
Builtins::kAsyncGeneratorAwaitRejectClosure)) {
// Now peak into the handlers' AwaitContext to get to
// the JSGeneratorObject for the async function.
Handle<Context> context(
......
......@@ -317,3 +317,40 @@
await test(one);
})());
})();
// Basic test for reject.
(function() {
async function one(x) {
await two(x);
}
async function two(x) {
try {
await Promise.reject(new Error());
assertUnreachable();
} catch (e) {
throw new Error();
}
}
async function test(f) {
try {
await f(1);
assertUnreachable();
} catch (e) {
assertInstanceof(e, Error);
assertMatches(/Error.+at two.+at async one.+at async test/ms, e.stack);
}
}
assertPromiseResult((async () => {
%PrepareFunctionForOptimization(one);
%PrepareFunctionForOptimization(two);
await test(one);
await test(one);
%OptimizeFunctionOnNextCall(two);
await test(one);
%OptimizeFunctionOnNextCall(one);
await test(one);
})());
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment