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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 return onResolve(x); | 347 return onResolve(x); |
348 } | 348 } |
349 }, | 349 }, |
350 onReject | 350 onReject |
351 ); | 351 ); |
352 } | 352 } |
353 | 353 |
354 // Combinators. | 354 // Combinators. |
355 | 355 |
356 function PromiseCast(x) { | 356 function PromiseCast(x) { |
357 if (IsPromise(x) && x.constructor === this) { | 357 if (!IS_RECEIVER(this)) { |
358 return x; | 358 throw MakeTypeError(kCalledOnNonObject, "Promise.resolve"); |
359 } else { | |
360 return new this(function(resolve) { resolve(x) }); | |
361 } | 359 } |
360 | |
361 if (IsPromise(x) && x.constructor === this) return x; | |
362 | |
363 var promiseCapability = NewPromiseCapability(this); | |
caitp (gmail)
2016/01/04 14:52:11
Technically, the assertions added in NewPromiseCap
Dan Ehrenberg
2016/01/04 18:04:20
Yep, I agree. Still looks good to me. The trybot j
| |
364 var resolveResult = promiseCapability.resolve(x); | |
365 return promiseCapability.promise; | |
362 } | 366 } |
363 | 367 |
364 function PromiseAll(iterable) { | 368 function PromiseAll(iterable) { |
365 var deferred = NewPromiseCapability(this); | 369 var deferred = NewPromiseCapability(this); |
366 var resolutions = []; | 370 var resolutions = []; |
367 try { | 371 try { |
368 var count = 0; | 372 var count = 0; |
369 var i = 0; | 373 var i = 0; |
370 for (var value of iterable) { | 374 for (var value of iterable) { |
371 var reject = function(r) { deferred.reject(r) }; | 375 var reject = function(r) { deferred.reject(r) }; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( | 482 [PromiseChain, PromiseDeferred, PromiseResolved].forEach( |
479 fn => %FunctionRemovePrototype(fn)); | 483 fn => %FunctionRemovePrototype(fn)); |
480 | 484 |
481 utils.Export(function(to) { | 485 utils.Export(function(to) { |
482 to.PromiseChain = PromiseChain; | 486 to.PromiseChain = PromiseChain; |
483 to.PromiseDeferred = PromiseDeferred; | 487 to.PromiseDeferred = PromiseDeferred; |
484 to.PromiseResolved = PromiseResolved; | 488 to.PromiseResolved = PromiseResolved; |
485 }); | 489 }); |
486 | 490 |
487 }) | 491 }) |
OLD | NEW |