OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 247 |
248 function PromiseAll(values) { | 248 function PromiseAll(values) { |
249 var deferred = %_CallFunction(this, PromiseDeferred); | 249 var deferred = %_CallFunction(this, PromiseDeferred); |
250 var resolutions = []; | 250 var resolutions = []; |
251 try { | 251 try { |
252 var count = values.length; | 252 var count = values.length; |
253 if (count === 0) { | 253 if (count === 0) { |
254 deferred.resolve(resolutions); | 254 deferred.resolve(resolutions); |
255 } else { | 255 } else { |
256 for (var i = 0; i < values.length; ++i) { | 256 for (var i = 0; i < values.length; ++i) { |
257 this.cast(values[i]).chain( | 257 this.cast(values[i]).then( |
258 function(i, x) { | 258 function(i, x) { |
259 resolutions[i] = x; | 259 resolutions[i] = x; |
260 if (--count === 0) deferred.resolve(resolutions); | 260 if (--count === 0) deferred.resolve(resolutions); |
261 }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once available | 261 }.bind(UNDEFINED, i), // TODO(rossberg): use let loop once available |
262 function(r) { deferred.reject(r) } | 262 function(r) { deferred.reject(r) } |
263 ); | 263 ); |
264 } | 264 } |
265 } | 265 } |
266 } catch (e) { | 266 } catch (e) { |
267 deferred.reject(e) | 267 deferred.reject(e) |
268 } | 268 } |
269 return deferred.promise; | 269 return deferred.promise; |
270 } | 270 } |
271 | 271 |
272 function PromiseOne(values) { | 272 function PromiseOne(values) { |
273 var deferred = %_CallFunction(this, PromiseDeferred); | 273 var deferred = %_CallFunction(this, PromiseDeferred); |
274 try { | 274 try { |
275 for (var i = 0; i < values.length; ++i) { | 275 for (var i = 0; i < values.length; ++i) { |
276 this.cast(values[i]).chain( | 276 this.cast(values[i]).then( |
277 function(x) { deferred.resolve(x) }, | 277 function(x) { deferred.resolve(x) }, |
278 function(r) { deferred.reject(r) } | 278 function(r) { deferred.reject(r) } |
279 ); | 279 ); |
280 } | 280 } |
281 } catch (e) { | 281 } catch (e) { |
282 deferred.reject(e) | 282 deferred.reject(e) |
283 } | 283 } |
284 return deferred.promise; | 284 return deferred.promise; |
285 } | 285 } |
286 | 286 |
(...skipping 12 matching lines...) Expand all Loading... |
299 "cast", PromiseCast | 299 "cast", PromiseCast |
300 ]); | 300 ]); |
301 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 301 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
302 "chain", PromiseChain, | 302 "chain", PromiseChain, |
303 "then", PromiseThen, | 303 "then", PromiseThen, |
304 "catch", PromiseCatch | 304 "catch", PromiseCatch |
305 ]); | 305 ]); |
306 } | 306 } |
307 | 307 |
308 SetUpPromise(); | 308 SetUpPromise(); |
OLD | NEW |