Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: src/js/promise.js

Issue 2209433003: [promise] separate PerformPromiseThen from PromiseThen (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate Dan's debugger fixes, + try to fix windows failures Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/prologue.js ('k') | test/mjsunit/harmony/async-await-species.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/promise.js
diff --git a/src/js/promise.js b/src/js/promise.js
index 466912d5eb6eaba98a8e4d9fe41c90ead55c4667..20ffc8c4892327ac68f5242c7900a1006303959e 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -390,40 +390,47 @@ function PromiseCreateResolved(x) {
return %_Call(PromiseResolve, GlobalPromise, x);
}
-// ES#sec-promise.prototype.then
-// Promise.prototype.then ( onFulfilled, onRejected )
-// Multi-unwrapped chaining with thenable coercion.
-function PromiseThen(onResolve, onReject) {
- var status = GET_PRIVATE(this, promiseStateSymbol);
- if (IS_UNDEFINED(status)) {
- throw MakeTypeError(kNotAPromise, this);
- }
+function PerformPromiseThen(promise, onResolve, onReject, resultCapability) {
+ if (!IS_CALLABLE(onResolve)) onResolve = PromiseIdResolveHandler;
+ if (!IS_CALLABLE(onReject)) onReject = PromiseIdRejectHandler;
- var constructor = SpeciesConstructor(this, GlobalPromise);
- onResolve = IS_CALLABLE(onResolve) ? onResolve : PromiseIdResolveHandler;
- onReject = IS_CALLABLE(onReject) ? onReject : PromiseIdRejectHandler;
- var deferred = NewPromiseCapability(constructor);
+ var status = GET_PRIVATE(promise, promiseStateSymbol);
switch (status) {
case kPending:
- PromiseAttachCallbacks(this, deferred, onResolve, onReject);
+ PromiseAttachCallbacks(promise, resultCapability, onResolve, onReject);
break;
case kFulfilled:
- PromiseEnqueue(GET_PRIVATE(this, promiseResultSymbol),
- onResolve, deferred, kFulfilled);
+ PromiseEnqueue(GET_PRIVATE(promise, promiseResultSymbol),
+ onResolve, resultCapability, kFulfilled);
break;
case kRejected:
- if (!HAS_DEFINED_PRIVATE(this, promiseHasHandlerSymbol)) {
+ if (!HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) {
// Promise has already been rejected, but had no handler.
// Revoke previously triggered reject event.
- %PromiseRevokeReject(this);
+ %PromiseRevokeReject(promise);
}
- PromiseEnqueue(GET_PRIVATE(this, promiseResultSymbol),
- onReject, deferred, kRejected);
+ PromiseEnqueue(GET_PRIVATE(promise, promiseResultSymbol),
+ onReject, resultCapability, kRejected);
break;
}
+
// Mark this promise as having handler.
- SET_PRIVATE(this, promiseHasHandlerSymbol, true);
- return deferred.promise;
+ SET_PRIVATE(promise, promiseHasHandlerSymbol, true);
+ return resultCapability.promise;
+}
+
+// ES#sec-promise.prototype.then
+// Promise.prototype.then ( onFulfilled, onRejected )
+// Multi-unwrapped chaining with thenable coercion.
+function PromiseThen(onResolve, onReject) {
+ var status = GET_PRIVATE(this, promiseStateSymbol);
+ if (IS_UNDEFINED(status)) {
+ throw MakeTypeError(kNotAPromise, this);
+ }
+
+ var constructor = SpeciesConstructor(this, GlobalPromise);
+ var resultCapability = NewPromiseCapability(constructor);
+ return PerformPromiseThen(this, onResolve, onReject, resultCapability);
}
// Unspecified V8-specific legacy function
@@ -622,6 +629,8 @@ utils.InstallFunctions(extrasUtils, 0, [
fn => %FunctionRemovePrototype(fn));
utils.Export(function(to) {
+ to.IsPromise = IsPromise;
+
to.PromiseChain = PromiseChain;
to.PromiseDefer = PromiseDefer;
to.PromiseAccept = PromiseAccept;
@@ -629,6 +638,10 @@ utils.Export(function(to) {
to.PromiseCreateRejected = PromiseCreateRejected;
to.PromiseCreateResolved = PromiseCreateResolved;
to.PromiseThen = PromiseThen;
+
+ to.GlobalPromise = GlobalPromise;
+ to.NewPromiseCapability = NewPromiseCapability;
+ to.PerformPromiseThen = PerformPromiseThen;
});
})
« no previous file with comments | « src/js/prologue.js ('k') | test/mjsunit/harmony/async-await-species.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698