• caitpotter88's avatar
    [es6] refactor Promise resolution · 24ff30b7
    caitpotter88 authored
    Several changes are included here:
    
    1. Each resolution callback references shared data indicating whether
    it has already been resolved or not, as described in 25.4.1.3
    http://tc39.github.io/ecma262/#sec-createresolvingfunctions.
    Previously this was handled exclusively by the Promise's status,
    which does not work correctly with the current chaining behaviour.
    
    2. During fulfillment, When a Promise is resolved with a thenable, the
    spec chains the promises together by invoking the thenable's `then`
    function with the original Promise's resolve and reject methods (per
    section 25.4.2.2, or
    http://tc39.github.io/ecma262/#sec-promiseresolvethenablejob, on the
    next tick, regardless of whether or not there are pending tasks.
    
    3. Adds a spec compliance fix to ensure that the Promise constructor
    is only loaded once when `then()` is called, solving v8:4539 as well.
    This involves refactoring PromiseChain to accept a constructor
    argument. PromiseChain/PromiseDeferred will hopefully be removed soon,
    simplifying the process.
    
    BUG=v8:4162, v8:4539, v8:3237
    LOG=N
    R=rossberg@chromium.org, littledan@chromium.org, adamk@chromium.org
    
    Review URL: https://codereview.chromium.org/1394463003
    
    Cr-Commit-Position: refs/heads/master@{#32046}
    24ff30b7
promise.js 13.8 KB