• Timothy Gu's avatar
    Reland "Use context of then function for PromiseResolveThenableJob" · 92a2f0c7
    Timothy Gu authored
    This is a reland of 93253978
    
    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}
    
    Bug: v8:10200
    Change-Id: I5af003a06c60b0c8cd19de47f847a947d40d046c
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2082109Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
    Commit-Queue: Timothy Gu <timothygu@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#66586}
    92a2f0c7
Name
Last commit
Last update
build_overrides Loading commit data...
custom_deps Loading commit data...
docs Loading commit data...
gni Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.clang-tidy Loading commit data...
.editorconfig Loading commit data...
.flake8 Loading commit data...
.git-blame-ignore-revs Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.vpython Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
COMMON_OWNERS Loading commit data...
DEPS Loading commit data...
ENG_REVIEW_OWNERS Loading commit data...
INFRA_OWNERS Loading commit data...
INTL_OWNERS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
MIPS_OWNERS Loading commit data...
OWNERS Loading commit data...
PPC_OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
S390_OWNERS Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...