Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: src/promise.js

Issue 366103005: Avoid brittle use of .bind in Promise.all (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Thorough test & rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/promise.js
diff --git a/src/promise.js b/src/promise.js
index 8214445c11a1e8e5f930aa31500e6c022724927e..2ea4911a80847cba21de10a19fb754e59c44f0a3 100644
--- a/src/promise.js
+++ b/src/promise.js
@@ -266,11 +266,15 @@ var promiseRaw = GLOBAL_PRIVATE("Promise#raw");
} else {
for (var i = 0; i < values.length; ++i) {
this.resolve(values[i]).then(
- function(i, x) {
- resolutions[i] = x;
- if (--count === 0) deferred.resolve(resolutions);
- }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once
- // available
+ (function() {
+ // Nested scope to get closure over current i (and avoid .bind).
+ // TODO(rossberg): Use for-let instead once available.
+ var i_captured = i;
+ return function(x) {
+ resolutions[i_captured] = x;
+ if (--count === 0) deferred.resolve(resolutions);
+ };
+ })(),
function(r) { deferred.reject(r) }
);
}
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698