RESOLVED FIXED296261
[JSC] Add async stack traces behind the flag
https://bugs.webkit.org/show_bug.cgi?id=296261
Summary [JSC] Add async stack traces behind the flag
Sosuke Suzuki
Reported 2025-07-21 00:29:54 PDT
JSC cannot obtain sufficient async stack traces. For example, this code: async function one(x) { await two(x); } async function two(x) { await x; throw new Error("error from two"); } one(1).catch((err) => { print(err.stack); }); prints this stack trace: two@./test.js:6:20 When an error occurs within an async function, the stack trace is cut off at the most recent await point, so higher-level functions in the async call chain are not displayed. This happens because when an async function is suspended at an await statement and later resumed from the microtask queue, the original call stack is lost. While this behavior is correct from the semantics of call stacks and microtask queues, it is inconvenient for users. This patch builds async stack traces through the following approach (only when the --useAsyncStackTrace flag is enabled): - Detect calls to `@asyncFunctionResume` during stack trace construction and retrieve the JSGenerator object hidden behind async-await from its arguments - Obtain references to awaited Promises held in each generator's Context field - Trace AsyncContext (parent generators recorded as @context fields) from the Promise's reaction chain - Walk up the chain of parent generators and construct stack frames from function information stored in each async function's Next field After this patch, the previous code outputs this stack trace: two@./WebKitBuild/Debug/test.js:6:20 one@./WebKitBuild/Debug/test.js:2:14 V8 constructs async stack traces using a similar approach [1][2]. [1]: https://docs.google.com/document/d/13Sy_kBIJGP0XT34V1CV3nkWya4TwYx9L3Yv45LdGB6Q/edit?tab=t.0#heading=h.9 ss45aibqpw2 [2]: https://issues.chromium.org/issues/42210758
Attachments
Sosuke Suzuki
Comment 1 2025-07-21 00:31:06 PDT
Radar WebKit Bug Importer
Comment 2 2025-07-28 00:30:36 PDT
EWS
Comment 3 2025-09-02 21:07:41 PDT
Committed 299482@main (f8a073dfbecf): <https://commits.webkit.org/299482@main> Reviewed commits have been landed. Closing PR #48314 and removing active labels.
Sosuke Suzuki
Comment 4 2025-09-04 00:22:13 PDT
EWS
Comment 5 2025-09-04 17:43:38 PDT
Committed 299595@main (74c38785fa38): <https://commits.webkit.org/299595@main> Reviewed commits have been landed. Closing PR #50290 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.