This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22982 - Synchronous flag and stack consumption of DOM/Promises
Summary: Synchronous flag and stack consumption of DOM/Promises
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-16 04:40 UTC by Yutaka Hirano
Modified: 2013-09-06 15:33 UTC (History)
4 users (show)

See Also:


Attachments

Description Yutaka Hirano 2013-08-16 04:40:33 UTC
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 a 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);

Promise.every(Promise.every(...(Promise.every(promise))...)) has the same problem.
Comment 1 Anne 2013-09-06 15:33:05 UTC
This is solved by the replacement hosted here: https://github.com/domenic/promises-unwrapping