Bug 296261
| Summary: | [JSC] Add async stack traces behind the flag | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Sosuke Suzuki <sosuke> |
| Component: | JavaScriptCore | Assignee: | Sosuke Suzuki <sosuke> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Sosuke Suzuki
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Sosuke Suzuki
Pull request: https://github.com/WebKit/WebKit/pull/48314
Radar WebKit Bug Importer
<rdar://problem/156890795>
EWS
Committed 299482@main (f8a073dfbecf): <https://commits.webkit.org/299482@main>
Reviewed commits have been landed. Closing PR #48314 and removing active labels.
Sosuke Suzuki
Re-opening for pull request https://github.com/WebKit/WebKit/pull/50290
EWS
Committed 299595@main (74c38785fa38): <https://commits.webkit.org/299595@main>
Reviewed commits have been landed. Closing PR #50290 and removing active labels.