• Benedikt Meurer's avatar
    [async] Introduce the notion of a "current microtask". · 9f28c129
    Benedikt Meurer authored
    Change the way we start collecting async stack traces by storing the
    current microtask as a root instead of trying to make sense of the
    last frame we see. This makes it possible to use the zero cost async
    stack traces in Node.js as well (where the last JavaScript frame we
    see is not the actual async function, but some frame related to the
    main event loop usually).
    
    In addition to the benefit that it now works with Node.js, we can also
    extend the new machinery to look through (almost arbitrary) promise
    chains. For example this code snippet
    
    ```js
    (async function() {
      await Promise.resolve().then(() =>
        console.log(new Error().stack));
    })();
    ```
    
    can be made to also show the async function frame, even though at the
    point where the stack trace is collected we don't have any async
    function on the stack. But instead there's a PromiseReactionJobTask
    as "current microtask", and we can dig into the chained promise to
    see where the async execution is going to continue and eventually
    find the await promise in the chain.
    
    This also removes the removes the need to allocate `.generator_object`
    specially during scope resolution.
    
    Bug: v8:7522
    Ref: nodejs/node#11865
    Tbr: ulan@chromium.org
    Design-Document: bit.ly/v8-zero-cost-async-stack-traces
    Change-Id: Ib96cb17c2f75cce083a24e5ba2bbb7914e20d203
    Reviewed-on: https://chromium-review.googlesource.com/c/1277505
    Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
    Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#56590}
    9f28c129
ForOfLoop.golden 45.6 KB