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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/es6/promises.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $Object = global.Object 9 // var $Object = global.Object
10 // var $WeakMap = global.WeakMap 10 // var $WeakMap = global.WeakMap
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 deferred.reject(MakeTypeError('invalid_argument')); 259 deferred.reject(MakeTypeError('invalid_argument'));
260 return deferred.promise; 260 return deferred.promise;
261 } 261 }
262 try { 262 try {
263 var count = values.length; 263 var count = values.length;
264 if (count === 0) { 264 if (count === 0) {
265 deferred.resolve(resolutions); 265 deferred.resolve(resolutions);
266 } else { 266 } else {
267 for (var i = 0; i < values.length; ++i) { 267 for (var i = 0; i < values.length; ++i) {
268 this.resolve(values[i]).then( 268 this.resolve(values[i]).then(
269 function(i, x) { 269 (function() {
270 resolutions[i] = x; 270 // Nested scope to get closure over current i (and avoid .bind).
271 if (--count === 0) deferred.resolve(resolutions); 271 // TODO(rossberg): Use for-let instead once available.
272 }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once 272 var i_captured = i;
273 // available 273 return function(x) {
274 resolutions[i_captured] = x;
275 if (--count === 0) deferred.resolve(resolutions);
276 };
277 })(),
274 function(r) { deferred.reject(r) } 278 function(r) { deferred.reject(r) }
275 ); 279 );
276 } 280 }
277 } 281 }
278 } catch (e) { 282 } catch (e) {
279 deferred.reject(e) 283 deferred.reject(e)
280 } 284 }
281 return deferred.promise; 285 return deferred.promise;
282 } 286 }
283 287
(...skipping 29 matching lines...) Expand all
313 "race", PromiseOne, 317 "race", PromiseOne,
314 "resolve", PromiseCast 318 "resolve", PromiseCast
315 ]); 319 ]);
316 InstallFunctions($Promise.prototype, DONT_ENUM, [ 320 InstallFunctions($Promise.prototype, DONT_ENUM, [
317 "chain", PromiseChain, 321 "chain", PromiseChain,
318 "then", PromiseThen, 322 "then", PromiseThen,
319 "catch", PromiseCatch 323 "catch", PromiseCatch
320 ]); 324 ]);
321 325
322 })(); 326 })();
OLDNEW
« 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