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

Unified Diff: src/js/promise.js

Issue 2497523002: [promises] Move promise constructor to TFS (Closed)
Patch Set: use jsbuiltinconstruct stub 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
Index: src/js/promise.js
diff --git a/src/js/promise.js b/src/js/promise.js
index f9d1f7abf59605f89e2c7e701a2b7dc91ca4b468..54dfdadbb3be6e129746169ca10d5d348541afa4 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -35,6 +35,7 @@ var SpeciesConstructor;
var speciesSymbol = utils.ImportNow("species_symbol");
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
var ObjectHasOwnProperty;
+var GlobalPromise = global.Promise;
utils.Import(function(from) {
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
@@ -52,35 +53,6 @@ const kRejected = +2;
const kResolveCallback = 0;
const kRejectCallback = 1;
-// ES#sec-promise-executor
-// Promise ( executor )
-var GlobalPromise = function Promise(executor) {
- if (executor === promiseRawSymbol) {
- return %_NewObject(GlobalPromise, new.target);
- }
- if (IS_UNDEFINED(new.target)) throw %make_type_error(kNotAPromise, this);
- if (!IS_CALLABLE(executor)) {
- throw %make_type_error(kResolverNotAFunction, executor);
- }
-
- var promise = PromiseInit(%_NewObject(GlobalPromise, new.target));
- // Calling the reject function would be a new exception, so debugEvent = true
- // TODO(gsathya): Remove container for callbacks when this is moved
- // to CPP/TF.
- var callbacks = %create_resolving_functions(promise, true);
- var debug_is_active = DEBUG_IS_ACTIVE;
- try {
- if (debug_is_active) %DebugPushPromise(promise);
- executor(callbacks[kResolveCallback], callbacks[kRejectCallback]);
- } %catch (e) { // Natives syntax to mark this catch block.
- %_Call(callbacks[kRejectCallback], UNDEFINED, e);
- } finally {
- if (debug_is_active) %DebugPopPromise();
- }
-
- return promise;
-}
-
// Core functionality.
function PromiseSet(promise, status, value) {
@@ -109,7 +81,7 @@ function PromiseSet(promise, status, value) {
}
function PromiseCreateAndSet(status, value) {
- var promise = new GlobalPromise(promiseRawSymbol);
+ var promise = %promise_internal_constructor();
// If debug is active, notify about the newly created promise first.
if (DEBUG_IS_ACTIVE) PromiseSet(promise, kPending, UNDEFINED);
return PromiseSet(promise, status, value);
@@ -208,13 +180,14 @@ SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
// For bootstrapper.
+// Only used by utils
// ES#sec-ispromise IsPromise ( x )
function IsPromise(x) {
return IS_RECEIVER(x) && HAS_DEFINED_PRIVATE(x, promiseStateSymbol);
}
function PromiseCreate() {
- return PromiseInit(new GlobalPromise(promiseRawSymbol));
+ return PromiseInit(%promise_internal_constructor());
}
// ES#sec-promise-resolve-functions
@@ -385,8 +358,7 @@ function PerformPromiseThen(promise, onResolve, onReject, resultCapability) {
// 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)) {
+ if (!IsPromise(this)) {
throw %make_type_error(kNotAPromise, this);
}
@@ -601,7 +573,6 @@ function PromiseSpecies() {
// -------------------------------------------------------------------
// Install exported functions.
-%AddNamedProperty(global, 'Promise', GlobalPromise, DONT_ENUM);
%AddNamedProperty(GlobalPromise.prototype, toStringTagSymbol, "Promise",
jgruber 2016/11/22 08:55:55 You could also move this to bootstrapper.
gsathya 2016/11/23 14:31:18 Done.
DONT_ENUM | READ_ONLY);

Powered by Google App Engine
This is Rietveld 408576698