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

Unified Diff: src/js/harmony-async-await.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 | « no previous file | src/js/prologue.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/harmony-async-await.js
diff --git a/src/js/harmony-async-await.js b/src/js/harmony-async-await.js
index c6705efe36d027134dc4cbf09003d27e107fe0d4..d9fbba307a55f61e7e2642774bf2ef2fc6f93a28 100644
--- a/src/js/harmony-async-await.js
+++ b/src/js/harmony-async-await.js
@@ -13,29 +13,44 @@
var AsyncFunctionNext;
var AsyncFunctionThrow;
-var PromiseReject;
-var PromiseResolve;
-var PromiseThen;
+var IsPromise;
+var GlobalPromise;
+var NewPromiseCapability;
+var PerformPromiseThen;
utils.Import(function(from) {
AsyncFunctionNext = from.AsyncFunctionNext;
AsyncFunctionThrow = from.AsyncFunctionThrow;
- PromiseReject = from.PromiseCreateRejected;
- PromiseResolve = from.PromiseCreateResolved;
- PromiseThen = from.PromiseThen;
+ IsPromise = from.IsPromise;
+ GlobalPromise = from.GlobalPromise;
+ NewPromiseCapability = from.NewPromiseCapability;
+ PerformPromiseThen = from.PerformPromiseThen;
});
// -------------------------------------------------------------------
function AsyncFunctionAwait(generator, value) {
- return %_Call(
- PromiseThen, PromiseResolve(value),
- function(sentValue) {
- return %_Call(AsyncFunctionNext, generator, sentValue);
- },
- function(sentError) {
- return %_Call(AsyncFunctionThrow, generator, sentError);
- });
+ // Promise.resolve(value).then(
+ // value => AsyncFunctionNext(value),
+ // error => AsyncFunctionThrow(error)
+ // );
+ var promise;
+ if (IsPromise(value)) {
+ promise = value;
+ } else {
+ var promiseCapability = NewPromiseCapability(GlobalPromise);
+ %_Call(promiseCapability.resolve, UNDEFINED, value);
+ promise = promiseCapability.promise;
+ }
+
+ var onFulfilled =
+ (sentValue) => %_Call(AsyncFunctionNext, generator, sentValue);
+ var onRejected =
+ (sentError) => %_Call(AsyncFunctionThrow, generator, sentError);
+
+ var throwawayCapability = NewPromiseCapability(GlobalPromise);
+ return PerformPromiseThen(promise, onFulfilled, onRejected,
+ throwawayCapability);
}
%InstallToContext([ "async_function_await", AsyncFunctionAwait ]);
« no previous file with comments | « no previous file | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698