<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>296261</bug_id>
          
          <creation_ts>2025-07-21 00:29:54 -0700</creation_ts>
          <short_desc>[JSC] Add async stack traces behind the flag</short_desc>
          <delta_ts>2025-09-04 17:44:30 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sosuke Suzuki">sosuke</reporter>
          <assigned_to name="Sosuke Suzuki">sosuke</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2131525</commentid>
    <comment_count>0</comment_count>
    <who name="Sosuke Suzuki">sosuke</who>
    <bug_when>2025-07-21 00:29:54 -0700</bug_when>
    <thetext>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(&quot;error from two&quot;);
        }
        one(1).catch((err) =&gt; { 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&apos;s Context field
    - Trace AsyncContext (parent generators recorded as @context fields) from the
      Promise&apos;s reaction chain
    - Walk up the chain of parent generators and construct stack frames from function
      information stored in each async function&apos;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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2131526</commentid>
    <comment_count>1</comment_count>
    <who name="Sosuke Suzuki">sosuke</who>
    <bug_when>2025-07-21 00:31:06 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/48314</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2132799</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-07-28 00:30:36 -0700</bug_when>
    <thetext>&lt;rdar://problem/156890795&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2140502</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-09-02 21:07:41 -0700</bug_when>
    <thetext>Committed 299482@main (f8a073dfbecf): &lt;https://commits.webkit.org/299482@main&gt;

Reviewed commits have been landed. Closing PR #48314 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2140857</commentid>
    <comment_count>4</comment_count>
    <who name="Sosuke Suzuki">sosuke</who>
    <bug_when>2025-09-04 00:22:13 -0700</bug_when>
    <thetext>Re-opening for pull request https://github.com/WebKit/WebKit/pull/50290</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2141095</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-09-04 17:43:38 -0700</bug_when>
    <thetext>Committed 299595@main (74c38785fa38): &lt;https://commits.webkit.org/299595@main&gt;

Reviewed commits have been landed. Closing PR #50290 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>