[promises] synchronous flag and stack consumption

Hi,

fulfill, resolve and reject algorithms take the synchronous flag.
If it is set the callbacks are processed synchronously i.e. simply called.
If we chain promises and fulfill the original resolver, the promises will
be resolved synchronously, which means stack frames in proportion to the
length of the chain will be consumed.

For example, the following statements leads to an stack overflow error in
Chrome.

var resolver;
var id = 0;
var N = 10000;
var promise = new Promise(function(r) {resolver = r;});
for (var i = 0; i < N; ++i) {
  promise = promise.then(function() {console.log(id++)});
}
resolver.resolve(4);

I think the spec has a problem at this point, is that correct?

Promise.every(Promise.every(...(Promise.every(promise))...)) has the same
problem.

Thanks,

Received on Thursday, 15 August 2013 05:34:10 UTC