• 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
..
api Loading commit data...
asmjs Loading commit data...
assembler Loading commit data...
base Loading commit data...
compiler Loading commit data...
compiler-dispatcher Loading commit data...
heap Loading commit data...
interpreter Loading commit data...
libplatform Loading commit data...
parser Loading commit data...
regress Loading commit data...
torque Loading commit data...
wasm Loading commit data...
zone Loading commit data...
BUILD.gn Loading commit data...
DEPS Loading commit data...
allocation-unittest.cc Loading commit data...
background-compile-task-unittest.cc Loading commit data...
bigint-unittest.cc Loading commit data...
cancelable-tasks-unittest.cc Loading commit data...
char-predicates-unittest.cc Loading commit data...
code-stub-assembler-unittest.cc Loading commit data...
code-stub-assembler-unittest.h Loading commit data...
conversions-unittest.cc Loading commit data...
counters-unittest.cc Loading commit data...
detachable-vector-unittest.cc Loading commit data...
eh-frame-iterator-unittest.cc Loading commit data...
eh-frame-writer-unittest.cc Loading commit data...
locked-queue-unittest.cc Loading commit data...
microtask-queue-unittest.cc Loading commit data...
object-unittest.cc Loading commit data...
register-configuration-unittest.cc Loading commit data...
run-all-unittests.cc Loading commit data...
source-position-table-unittest.cc Loading commit data...
strings-storage-unittest.cc Loading commit data...
test-helpers.cc Loading commit data...
test-helpers.h Loading commit data...
test-utils.cc Loading commit data...
test-utils.h Loading commit data...
testcfg.py Loading commit data...
unicode-unittest.cc Loading commit data...
unittests.status Loading commit data...
utils-unittest.cc Loading commit data...
value-serializer-unittest.cc Loading commit data...