-
Notifications
You must be signed in to change notification settings - Fork 110
Description
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).