Chromium Code Reviews| Index: src/js/promise.js |
| diff --git a/src/js/promise.js b/src/js/promise.js |
| index d7e25124708737f8c5031e8d86d0d20b31176be1..e8722ee2d25b145617cc03ccecbf8224fc443043 100644 |
| --- a/src/js/promise.js |
| +++ b/src/js/promise.js |
| @@ -291,6 +291,17 @@ function DoRejectPromise(promise, reason) { |
| PromiseSet(promise, kRejected, reason); |
| } |
| +// The resultCapability.promise is only ever fulfilled internally, |
| +// so we don't need the closures to protect against accidentally |
| +// calling them multiple times. |
| +function NewPromiseCapabilityWithoutCallbacks() { |
|
Dan Ehrenberg
2016/11/18 12:54:52
Name suggestion: CreatePromiseCapability
gsathya
2016/11/18 15:39:48
Doesn't seem to convey the difference between NewP
caitp
2016/11/18 15:42:28
"CreateInternalPromiseCapability"?
|
| + return { |
| + promise: PromiseCreate(), |
| + resolve: UNDEFINED, |
| + reject: UNDEFINED |
| + }; |
| +} |
| + |
| // ES#sec-newpromisecapability |
| // NewPromiseCapability ( C ) |
| function NewPromiseCapability(C, debugEvent) { |
| @@ -381,22 +392,14 @@ function PromiseThen(onResolve, onReject) { |
| var constructor = SpeciesConstructor(this, GlobalPromise); |
| var resultCapability; |
| - |
| - // The resultCapability.promise is only ever fulfilled internally, |
| - // so we don't need the closures to protect against accidentally |
| - // calling them multiple times. |
| if (constructor === GlobalPromise) { |
| - // TODO(gsathya): Combine this into NewPromiseCapability. |
| - resultCapability = { |
| - promise: PromiseCreate(), |
| - resolve: UNDEFINED, |
| - reject: UNDEFINED |
| - }; |
| + resultCapability = NewPromiseCapabilityWithoutCallbacks(); |
| } else { |
| // Pass false for debugEvent so .then chaining does not trigger |
| // redundant ExceptionEvents. |
| resultCapability = NewPromiseCapability(constructor, false); |
| } |
| + |
|
Dan Ehrenberg
2016/11/18 12:54:52
Nit: consider reverting the irrelevant whitespace
gsathya
2016/11/18 15:39:48
Done.
|
| return PerformPromiseThen(this, onResolve, onReject, resultCapability); |
| } |
| @@ -641,7 +644,8 @@ utils.Export(function(to) { |
| to.PromiseThen = PromiseThen; |
| to.GlobalPromise = GlobalPromise; |
| - to.NewPromiseCapability = NewPromiseCapability; |
| + to.NewPromiseCapabilityWithoutCallbacks = |
| + NewPromiseCapabilityWithoutCallbacks; |
| to.PerformPromiseThen = PerformPromiseThen; |
| to.ResolvePromise = ResolvePromise; |
| to.RejectPromise = RejectPromise; |