| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 } | 473 } |
| 474 | 474 |
| 475 // false debugEvent so that forwarding the rejection through all does not | 475 // false debugEvent so that forwarding the rejection through all does not |
| 476 // trigger redundant ExceptionEvents | 476 // trigger redundant ExceptionEvents |
| 477 var deferred = NewPromiseCapability(this, false); | 477 var deferred = NewPromiseCapability(this, false); |
| 478 var resolutions = new InternalArray(); | 478 var resolutions = new InternalArray(); |
| 479 var count; | 479 var count; |
| 480 | 480 |
| 481 // For catch prediction, don't treat the .then calls as handling it; | 481 // For catch prediction, don't treat the .then calls as handling it; |
| 482 // instead, recurse outwards. | 482 // instead, recurse outwards. |
| 483 SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true); | 483 var instrumenting = DEBUG_IS_ACTIVE; |
| 484 if (instrumenting) { |
| 485 SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true); |
| 486 } |
| 484 | 487 |
| 485 function CreateResolveElementFunction(index, values, promiseCapability) { | 488 function CreateResolveElementFunction(index, values, promiseCapability) { |
| 486 var alreadyCalled = false; | 489 var alreadyCalled = false; |
| 487 return (x) => { | 490 return (x) => { |
| 488 if (alreadyCalled === true) return; | 491 if (alreadyCalled === true) return; |
| 489 alreadyCalled = true; | 492 alreadyCalled = true; |
| 490 values[index] = x; | 493 values[index] = x; |
| 491 if (--count === 0) { | 494 if (--count === 0) { |
| 492 var valuesArray = []; | 495 var valuesArray = []; |
| 493 %MoveArrayContents(values, valuesArray); | 496 %MoveArrayContents(values, valuesArray); |
| 494 %_Call(promiseCapability.resolve, UNDEFINED, valuesArray); | 497 %_Call(promiseCapability.resolve, UNDEFINED, valuesArray); |
| 495 } | 498 } |
| 496 }; | 499 }; |
| 497 } | 500 } |
| 498 | 501 |
| 499 try { | 502 try { |
| 500 var i = 0; | 503 var i = 0; |
| 501 count = 1; | 504 count = 1; |
| 502 for (var value of iterable) { | 505 for (var value of iterable) { |
| 503 var nextPromise = this.resolve(value); | 506 var nextPromise = this.resolve(value); |
| 504 ++count; | 507 ++count; |
| 505 var throwawayPromise = nextPromise.then( | 508 var throwawayPromise = nextPromise.then( |
| 506 CreateResolveElementFunction(i, resolutions, deferred), | 509 CreateResolveElementFunction(i, resolutions, deferred), |
| 507 deferred.reject); | 510 deferred.reject); |
| 508 // For catch prediction, mark that rejections here are semantically | 511 // For catch prediction, mark that rejections here are semantically |
| 509 // handled by the combined Promise. | 512 // handled by the combined Promise. |
| 510 if (IsPromise(throwawayPromise)) { | 513 if (instrumenting && IsPromise(throwawayPromise)) { |
| 511 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); | 514 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); |
| 512 } | 515 } |
| 513 ++i; | 516 ++i; |
| 514 } | 517 } |
| 515 | 518 |
| 516 // 6.d | 519 // 6.d |
| 517 if (--count === 0) { | 520 if (--count === 0) { |
| 518 var valuesArray = []; | 521 var valuesArray = []; |
| 519 %MoveArrayContents(resolutions, valuesArray); | 522 %MoveArrayContents(resolutions, valuesArray); |
| 520 %_Call(deferred.resolve, UNDEFINED, valuesArray); | 523 %_Call(deferred.resolve, UNDEFINED, valuesArray); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 532 if (!IS_RECEIVER(this)) { | 535 if (!IS_RECEIVER(this)) { |
| 533 throw %make_type_error(kCalledOnNonObject, PromiseRace); | 536 throw %make_type_error(kCalledOnNonObject, PromiseRace); |
| 534 } | 537 } |
| 535 | 538 |
| 536 // false debugEvent so that forwarding the rejection through race does not | 539 // false debugEvent so that forwarding the rejection through race does not |
| 537 // trigger redundant ExceptionEvents | 540 // trigger redundant ExceptionEvents |
| 538 var deferred = NewPromiseCapability(this, false); | 541 var deferred = NewPromiseCapability(this, false); |
| 539 | 542 |
| 540 // For catch prediction, don't treat the .then calls as handling it; | 543 // For catch prediction, don't treat the .then calls as handling it; |
| 541 // instead, recurse outwards. | 544 // instead, recurse outwards. |
| 542 SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true); | 545 var instrumenting = DEBUG_IS_ACTIVE; |
| 546 if (instrumenting) { |
| 547 SET_PRIVATE(deferred.reject, promiseForwardingHandlerSymbol, true); |
| 548 } |
| 543 | 549 |
| 544 try { | 550 try { |
| 545 for (var value of iterable) { | 551 for (var value of iterable) { |
| 546 var throwawayPromise = this.resolve(value).then(deferred.resolve, | 552 var throwawayPromise = this.resolve(value).then(deferred.resolve, |
| 547 deferred.reject); | 553 deferred.reject); |
| 548 // For catch prediction, mark that rejections here are semantically | 554 // For catch prediction, mark that rejections here are semantically |
| 549 // handled by the combined Promise. | 555 // handled by the combined Promise. |
| 550 if (IsPromise(throwawayPromise)) { | 556 if (instrumenting && IsPromise(throwawayPromise)) { |
| 551 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); | 557 SET_PRIVATE(throwawayPromise, promiseHandledBySymbol, deferred.promise); |
| 552 } | 558 } |
| 553 } | 559 } |
| 554 } catch (e) { | 560 } catch (e) { |
| 555 deferred.reject(e) | 561 deferred.reject(e) |
| 556 } | 562 } |
| 557 return deferred.promise; | 563 return deferred.promise; |
| 558 } | 564 } |
| 559 | 565 |
| 560 | 566 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 to.PromiseThen = PromiseThen; | 673 to.PromiseThen = PromiseThen; |
| 668 | 674 |
| 669 to.GlobalPromise = GlobalPromise; | 675 to.GlobalPromise = GlobalPromise; |
| 670 to.NewPromiseCapability = NewPromiseCapability; | 676 to.NewPromiseCapability = NewPromiseCapability; |
| 671 to.PerformPromiseThen = PerformPromiseThen; | 677 to.PerformPromiseThen = PerformPromiseThen; |
| 672 to.ResolvePromise = ResolvePromise; | 678 to.ResolvePromise = ResolvePromise; |
| 673 to.RejectPromise = RejectPromise; | 679 to.RejectPromise = RejectPromise; |
| 674 }); | 680 }); |
| 675 | 681 |
| 676 }) | 682 }) |
| OLD | NEW |