Commit ffdd76e6 authored by gsathya's avatar gsathya Committed by Commit bot

This patch updates certain functions and parameters to match the Promise spec.

Review-Url: https://codereview.chromium.org/2001283006
Cr-Commit-Position: refs/heads/master@{#36535}
parent c1af2821
...@@ -51,7 +51,7 @@ function CreateResolvingFunctions(promise) { ...@@ -51,7 +51,7 @@ function CreateResolvingFunctions(promise) {
var resolve = value => { var resolve = value => {
if (alreadyResolved === true) return; if (alreadyResolved === true) return;
alreadyResolved = true; alreadyResolved = true;
FulfillPromise(promise, value); ResolvePromise(promise, value);
}; };
// ES#sec-promise-reject-functions // ES#sec-promise-reject-functions
...@@ -72,13 +72,13 @@ function CreateResolvingFunctions(promise) { ...@@ -72,13 +72,13 @@ function CreateResolvingFunctions(promise) {
// ES#sec-promise-executor // ES#sec-promise-executor
// Promise ( executor ) // Promise ( executor )
var GlobalPromise = function Promise(resolver) { var GlobalPromise = function Promise(executor) {
if (resolver === promiseRawSymbol) { if (executor === promiseRawSymbol) {
return %_NewObject(GlobalPromise, new.target); return %_NewObject(GlobalPromise, new.target);
} }
if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this); if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this);
if (!IS_CALLABLE(resolver)) { if (!IS_CALLABLE(executor)) {
throw MakeTypeError(kResolverNotAFunction, resolver); throw MakeTypeError(kResolverNotAFunction, executor);
} }
var promise = PromiseInit(%_NewObject(GlobalPromise, new.target)); var promise = PromiseInit(%_NewObject(GlobalPromise, new.target));
...@@ -86,7 +86,7 @@ var GlobalPromise = function Promise(resolver) { ...@@ -86,7 +86,7 @@ var GlobalPromise = function Promise(resolver) {
var debug_is_active = DEBUG_IS_ACTIVE; var debug_is_active = DEBUG_IS_ACTIVE;
try { try {
if (debug_is_active) %DebugPushPromise(promise, Promise); if (debug_is_active) %DebugPushPromise(promise, Promise);
resolver(callbacks.resolve, callbacks.reject); executor(callbacks.resolve, callbacks.reject);
} catch (e) { } catch (e) {
%_Call(callbacks.reject, UNDEFINED, e); %_Call(callbacks.reject, UNDEFINED, e);
} finally { } finally {
...@@ -118,7 +118,7 @@ function PromiseInit(promise) { ...@@ -118,7 +118,7 @@ function PromiseInit(promise) {
promise, kPending, UNDEFINED, new InternalArray, new InternalArray) promise, kPending, UNDEFINED, new InternalArray, new InternalArray)
} }
function PromiseDone(promise, status, value, promiseQueue) { function FulfillPromise(promise, status, value, promiseQueue) {
if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) {
var tasks = GET_PRIVATE(promise, promiseQueue); var tasks = GET_PRIVATE(promise, promiseQueue);
if (tasks.length) PromiseEnqueue(value, tasks, status); if (tasks.length) PromiseEnqueue(value, tasks, status);
...@@ -178,16 +178,16 @@ function PromiseCreate() { ...@@ -178,16 +178,16 @@ function PromiseCreate() {
return new GlobalPromise(PromiseNopResolver) return new GlobalPromise(PromiseNopResolver)
} }
// ES#sec-fulfillpromise // ES#sec-promise-resolve-functions
// FulfillPromise ( promise, value) // Promise Resolve Functions, steps 6-13
function FulfillPromise(promise, x) { function ResolvePromise(promise, resolution) {
if (x === promise) { if (resolution === promise) {
return RejectPromise(promise, MakeTypeError(kPromiseCyclic, x)); return RejectPromise(promise, MakeTypeError(kPromiseCyclic, resolution));
} }
if (IS_RECEIVER(x)) { if (IS_RECEIVER(resolution)) {
// 25.4.1.3.2 steps 8-12 // 25.4.1.3.2 steps 8-12
try { try {
var then = x.then; var then = resolution.then;
} catch (e) { } catch (e) {
return RejectPromise(promise, e); return RejectPromise(promise, e);
} }
...@@ -200,7 +200,7 @@ function FulfillPromise(promise, x) { ...@@ -200,7 +200,7 @@ function FulfillPromise(promise, x) {
} }
var callbacks = CreateResolvingFunctions(promise); var callbacks = CreateResolvingFunctions(promise);
try { try {
%_Call(then, x, callbacks.resolve, callbacks.reject); %_Call(then, resolution, callbacks.resolve, callbacks.reject);
} catch (e) { } catch (e) {
%_Call(callbacks.reject, UNDEFINED, e); %_Call(callbacks.reject, UNDEFINED, e);
} }
...@@ -216,22 +216,22 @@ function FulfillPromise(promise, x) { ...@@ -216,22 +216,22 @@ function FulfillPromise(promise, x) {
return; return;
} }
} }
PromiseDone(promise, kFulfilled, x, promiseFulfillReactionsSymbol); FulfillPromise(promise, kFulfilled, resolution, promiseFulfillReactionsSymbol);
} }
// ES#sec-rejectpromise // ES#sec-rejectpromise
// RejectPromise ( promise, reason ) // RejectPromise ( promise, reason )
function RejectPromise(promise, r) { function RejectPromise(promise, reason) {
// Check promise status to confirm that this reject has an effect. // Check promise status to confirm that this reject has an effect.
// Call runtime for callbacks to the debugger or for unhandled reject. // Call runtime for callbacks to the debugger or for unhandled reject.
if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) {
var debug_is_active = DEBUG_IS_ACTIVE; var debug_is_active = DEBUG_IS_ACTIVE;
if (debug_is_active || if (debug_is_active ||
!HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) { !HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) {
%PromiseRejectEvent(promise, r, debug_is_active); %PromiseRejectEvent(promise, reason, debug_is_active);
} }
} }
PromiseDone(promise, kRejected, r, promiseRejectReactionsSymbol) FulfillPromise(promise, kRejected, reason, promiseRejectReactionsSymbol)
} }
// ES#sec-newpromisecapability // ES#sec-newpromisecapability
...@@ -496,7 +496,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [ ...@@ -496,7 +496,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [
"promise_create", PromiseCreate, "promise_create", PromiseCreate,
"promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler, "promise_has_user_defined_reject_handler", PromiseHasUserDefinedRejectHandler,
"promise_reject", RejectPromise, "promise_reject", RejectPromise,
"promise_resolve", FulfillPromise, "promise_resolve", ResolvePromise,
"promise_then", PromiseThen, "promise_then", PromiseThen,
"promise_create_rejected", PromiseCreateRejected, "promise_create_rejected", PromiseCreateRejected,
"promise_create_resolved", PromiseCreateResolved "promise_create_resolved", PromiseCreateResolved
...@@ -507,7 +507,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [ ...@@ -507,7 +507,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [
// promise without having to hold on to those closures forever. // promise without having to hold on to those closures forever.
utils.InstallFunctions(extrasUtils, 0, [ utils.InstallFunctions(extrasUtils, 0, [
"createPromise", PromiseCreate, "createPromise", PromiseCreate,
"resolvePromise", FulfillPromise, "resolvePromise", ResolvePromise,
"rejectPromise", RejectPromise "rejectPromise", RejectPromise
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment