• tzik's avatar
    Use non-primary promise handler as a source of fallback microtask context · 39bfa157
    tzik authored
    A microtask requires a non-detached Context to trigger, and the Context
    is usually pulled from the primary handler.
    On an example below, |on_rejected| is primary, as the attached promise
    is rejected and |on_rejected| will be called as the reaction.
    
      Promise.reject().then(on_fulfilled, on_rejected);
    
    If the primary handler is undefined or invalid, we used to use the
    promise's context as the fallback. E.g. the primary handler is undefined
    on the examlpe below, and the context of |promise| was used.
    
      let promise = Promise.reject();
      promise.then(on_fulfilled);
    
    However, that causes a non-intuitive behavior around a detached
    context:
    
      let DeadPromise = iframe.contentWindow.Promise;
      iframe.src = "http://example.com"; // navigate away.
      // DeadPromise's Context is detached state now.
    
      let p = DeadPromise.reject();
    
      // |on_rejected| is called, as the context is pulled from |on_rejected|.
      p.then(on_fulfilled, on_rejected);
    
      // |on_rejected| was NOT called, as a microtask to settle |q| does not
      // run due to the detached context.
      let q = p.then(on_fulfilled);
      q.catch(on_rejected);
    
    After this CL, we use non-primary handler as a source of fallback context.
    On the last example above, the Context is pulled from |on_fullfilled|,
    so that |q| is settled using that context.
    
    Bug: chromium:941271
    Change-Id: Iff71acf7c3617f3493d100abcd2c5c36bd1bbfd1
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1535916Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
    Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#60499}
    39bfa157
Name
Last commit
Last update
benchmarks Loading commit data...
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...
.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...
ChangeLog Loading commit data...
DEPS 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...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...