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 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 310 } |
311 | 311 |
312 function PromiseCatch(onReject) { | 312 function PromiseCatch(onReject) { |
313 return this.then(UNDEFINED, onReject); | 313 return this.then(UNDEFINED, onReject); |
314 } | 314 } |
315 | 315 |
316 // Combinators. | 316 // Combinators. |
317 | 317 |
318 function PromiseCast(x) { | 318 function PromiseCast(x) { |
319 if (!IS_RECEIVER(this)) { | 319 if (!IS_RECEIVER(this)) { |
320 throw MakeTypeError(kCalledOnNonObject, PromiseCast); | 320 throw MakeTypeError(kCalledOnNonObject, "Promise.resolve"); |
321 } | 321 } |
322 if (IsPromise(x) && x.constructor === this) { | 322 if (IsPromise(x) && x.constructor === this) return x; |
323 return x; | 323 |
324 } else { | 324 var promiseCapability = NewPromiseCapability(this); |
325 return new this(function(resolve, reject) { resolve(x) }); | 325 var resolveResult = %_Call(promiseCapability.resolve, UNDEFINED, x); |
326 } | 326 return promiseCapability.promise; |
327 } | 327 } |
328 | 328 |
329 function PromiseAll(iterable) { | 329 function PromiseAll(iterable) { |
330 var deferred = NewPromiseCapability(this); | 330 var deferred = NewPromiseCapability(this); |
331 var resolutions = []; | 331 var resolutions = []; |
332 try { | 332 try { |
333 var count = 0; | 333 var count = 0; |
334 var i = 0; | 334 var i = 0; |
335 for (var value of iterable) { | 335 for (var value of iterable) { |
336 var reject = function(r) { deferred.reject(r) }; | 336 var reject = function(r) { deferred.reject(r) }; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 443 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
444 fn => %FunctionRemovePrototype(fn)); | 444 fn => %FunctionRemovePrototype(fn)); |
445 | 445 |
446 utils.Export(function(to) { | 446 utils.Export(function(to) { |
447 to.PromiseChain = PromiseChain; | 447 to.PromiseChain = PromiseChain; |
448 to.PromiseDeferred = PromiseDeferred; | 448 to.PromiseDeferred = PromiseDeferred; |
449 to.PromiseResolved = PromiseResolved; | 449 to.PromiseResolved = PromiseResolved; |
450 }); | 450 }); |
451 | 451 |
452 }) | 452 }) |
OLD | NEW |