OLD | NEW |
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 Loading... |
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 Loading... |
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 })(); |
OLD | NEW |