[promises] synchronous flag and stack consumption

Yutaka Hirano <[email protected]>
Newsgroups gmane.comp.web.dom.general
Message-ID <CABihn6Ej7Q_MFu6PrLNc2T5ejdNbvtZfJ6sCVAGx1jgvxBP-ig@mail.gmail.com>
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,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.