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

Unified Diff: src/js/promise.js

Issue 2459283004: [promises] Move CreateResolvingFunctions to c++ (Closed)
Patch Set: Remove header Created 4 years, 1 month 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
« src/factory.cc ('K') | « src/js/async-await.js ('k') | src/v8.gyp » ('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 75ec6e1c57683f56c9107e5f8754590b532c46d3..eea90f44f1fc62322e5e740bb55cac545e86af1c 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -49,36 +49,6 @@ const kPending = 0;
const kFulfilled = +1;
const kRejected = +2;
-// ES#sec-createresolvingfunctions
-// CreateResolvingFunctions ( promise )
-function CreateResolvingFunctions(promise, debugEvent) {
- var alreadyResolved = false;
-
- // ES#sec-promise-resolve-functions
- // Promise Resolve Functions
- var resolve = value => {
- if (alreadyResolved === true) return;
- alreadyResolved = true;
- ResolvePromise(promise, value);
- };
-
- // ES#sec-promise-reject-functions
- // Promise Reject Functions
- var reject = reason => {
- if (alreadyResolved === true) return;
- alreadyResolved = true;
- %PromiseReject(promise, reason, debugEvent);
- PromiseSet(promise, kRejected, reason);
- };
-
- return {
- __proto__: null,
- resolve: resolve,
- reject: reject
- };
-}
-
-
// ES#sec-promise-executor
// Promise ( executor )
var GlobalPromise = function Promise(executor) {
@@ -92,13 +62,13 @@ var GlobalPromise = function Promise(executor) {
var promise = PromiseInit(%_NewObject(GlobalPromise, new.target));
// Calling the reject function would be a new exception, so debugEvent = true
- var callbacks = CreateResolvingFunctions(promise, true);
+ var callbacks = %create_resolving_functions(promise, true);
var debug_is_active = DEBUG_IS_ACTIVE;
try {
if (debug_is_active) %DebugPushPromise(promise);
- executor(callbacks.resolve, callbacks.reject);
+ executor(callbacks[0], callbacks[1]);
adamk 2016/11/09 00:06:23 Define constants for these 0 and 1?
gsathya 2016/11/09 00:57:33 Done.
} %catch (e) { // Natives syntax to mark this catch block.
- %_Call(callbacks.reject, UNDEFINED, e);
+ %_Call(callbacks[1], UNDEFINED, e);
} finally {
if (debug_is_active) %DebugPopPromise();
}
@@ -291,13 +261,13 @@ function ResolvePromise(promise, resolution) {
}
if (IS_CALLABLE(then)) {
- var callbacks = CreateResolvingFunctions(promise, false);
+ var callbacks = %create_resolving_functions(promise, false);
if (DEBUG_IS_ACTIVE && IsPromise(resolution)) {
// Mark the dependency of the new promise on the resolution
SET_PRIVATE(resolution, promiseHandledBySymbol, promise);
}
%EnqueuePromiseResolveThenableJob(
- resolution, then, callbacks.resolve, callbacks.reject);
+ resolution, then, callbacks[0], callbacks[1]);
return;
}
}
@@ -307,8 +277,8 @@ function ResolvePromise(promise, resolution) {
}
// Only used by async-await.js
-function RejectPromise(promise, reason) {
- %PromiseReject(promise, reason, false);
+function RejectPromise(promise, reason, debugEvent) {
+ %PromiseReject(promise, reason, debugEvent);
PromiseSet(promise, kRejected, reason);
}
@@ -324,11 +294,11 @@ function NewPromiseCapability(C, debugEvent) {
if (C === GlobalPromise) {
// Optimized case, avoid extra closure.
var promise = PromiseCreate();
- var callbacks = CreateResolvingFunctions(promise, debugEvent);
+ var callbacks = %create_resolving_functions(promise, debugEvent);
return {
promise: promise,
- resolve: callbacks.resolve,
- reject: callbacks.reject
+ resolve: callbacks[0],
+ reject: callbacks[1]
};
}
@@ -643,6 +613,8 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [
"promise_create", PromiseCreate,
"promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
"promise_reject", DoRejectPromise,
+ //TODO(gsathya): Remove this once we update the promise builtin.
adamk 2016/11/09 00:06:23 Super nit: space between "//" and "TODO" please.
gsathya 2016/11/09 00:57:33 Done.
+ "promise_internal_reject", RejectPromise,
"promise_resolve", ResolvePromise,
"promise_then", PromiseThen,
"promise_handle", PromiseHandle,
« src/factory.cc ('K') | « src/js/async-await.js ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698