• Francis McCabe's avatar
    Revert "Use context of then function for PromiseResolveThenableJob" · 7558e182
    Francis McCabe authored
    This reverts commit 93253978.
    
    Reason for revert: Causing blink layout failures. See 
    
    https://ci.chromium.org/p/v8/builders/ci/V8%20Blink%20Linux%20Future/2684
    
    Original change's description:
    > Use context of then function for PromiseResolveThenableJob
    > 
    > When a microtask is executed, we need to use an appropriate,
    > non-detached Context for its execution. Currently with
    > PromiseResolveThenableJobs [1], the Context used is always drawn from
    > the realm of the Promise constructor being used. This may cause
    > non-intuitive behavior, such as in the following case:
    > 
    >   const DeadPromise = iframe.contentWindow.Promise;
    >   const p = DeadPromise.resolve({
    >     then() {
    >       return { success: true };
    >     }
    >   });
    >   p.then(result => { console.log(result); });
    > 
    >   // Some time later, but synchronously...
    >   iframe.src = "http://example.com"; // navigate away.
    >   // DeadPromise's Context is detached state now.
    >   // p never gets resolved, and its reaction handler never gets called.
    > 
    > To fix this behavior, when PromiseResolveThenableJob is being queued up,
    > the `then` method of the thenable should be used to determine the
    > context of the resultant microtask. Doing so aligns with Firefox, and
    > also with the latest HTML spec [2][3].
    > 
    > This change is analogous to CL 1465902, which uses the realm of the
    > reaction handlers to determine the Context PromiseReactionJobs run in.
    > 
    > [1]: https://tc39.es/ecma262/#sec-promiseresolvethenablejob
    > [2]: https://html.spec.whatwg.org/C/#enqueuejob(queuename,-job,-arguments)
    > [3]: https://github.com/whatwg/html/pull/5212
    > 
    > Bug: v8:10200
    > Change-Id: I2312788eeea0f9e870c13cf3cb5730a87d15609e
    > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071624
    > Commit-Queue: Timothy Gu <timothygu@chromium.org>
    > Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    > Reviewed-by: Shu-yu Guo <syg@chromium.org>
    > Cr-Commit-Position: refs/heads/master@{#66507}
    
    TBR=verwaest@chromium.org,timothygu@chromium.org,syg@chromium.org
    
    Change-Id: I81737750f8b369567ba586c5a2cfb489836b7e74
    No-Presubmit: true
    No-Tree-Checks: true
    No-Try: true
    Bug: v8:10200
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2081091Reviewed-by: 's avatarFrancis McCabe <fgm@chromium.org>
    Commit-Queue: Francis McCabe <fgm@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#66510}
    7558e182
microtask-queue-unittest.cc 19.8 KB