Skip to content

2.2.2.2 fails when resolving synchronously outside of .then's event-loop-turn #68

@avih

Description

@avih

This is the test for 2.2.2.2:

        var d = deferred();
        var isFulfilled = false;
        d.promise.then(function onFulfilled() {
            assert.strictEqual(isFulfilled, true);
            done();
        });
        setTimeout(function () {
            d.resolve(dummy);
            isFulfilled = true;
        }, 50);

I think the spec says that onFulfilled should be called with a clean stack with regards to the then, but not necessarily WRT resolve. Spec 2.2.4 says:

onFulfilled or onRejected must not be called until the execution context stack contains only platform code. [3.1].

Where note 3.1 clarifies:

In practice, this requirement ensures that onFulfilled and onRejected execute asynchronously, after the event loop turn in which then is called, and with a fresh stack.

Depending on interpretation, specifically of "and with a fresh stack" but mostly because then's context is mentioned explicitly while resolve/reject are not, if d.resolve(dummy) executes onFulfilled synchronously, which at this test is not at the same execution context where then was called, then I think the spec says it's OK, but this test will fail because it expects onFulfilled to be at a different context to resolve (i.e. that isFulfilled = true; runs before onFulfilled)

Personally I think that the spec should enforce fully async of resolve/reject as well (like the test expects), and even further that two onFulfilled/onRejected should also not be called at the same execution context, but if an implementer tries to squeeze every ounce of speed by using synchronous executions where the spec allows, then I think this test should pass if resolve executes onFulfilled synchronously (same for the equivalent reject and possibly other tests).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions