From 07b72b9921442b22956f8198d56b378dafb61bc5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 23 Jan 2018 14:15:51 -0800 Subject: [PATCH] Normative: Add Promise.prototype.finally --- spec.html | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/spec.html b/spec.html index df01a4e740..9862ba5a15 100644 --- a/spec.html +++ b/spec.html @@ -37403,12 +37403,7 @@

Promise.resolve ( _x_ )

1. Let _C_ be the *this* value. 1. If Type(_C_) is not Object, throw a *TypeError* exception. - 1. If IsPromise(_x_) is *true*, then - 1. Let _xConstructor_ be ? Get(_x_, `"constructor"`). - 1. If SameValue(_xConstructor_, _C_) is *true*, return _x_. - 1. Let _promiseCapability_ be ? NewPromiseCapability(_C_). - 1. Perform ? Call(_promiseCapability_.[[Resolve]], *undefined*, « _x_ »). - 1. Return _promiseCapability_.[[Promise]]. + 1. Return ? PromiseResolve(_C_, _x_).

This function is the %Promise_resolve% intrinsic object.

@@ -37416,6 +37411,20 @@

Promise.resolve ( _x_ )

+ +

PromiseResolve ( _C_, _x_ )

+

The abstract operation PromiseResolve, given a constructor and a value, returns a new promise resolved with that value.

+ + 1. Assert: Type(_C_) is Object. + 1. If IsPromise(_x_) is *true*, then + 1. Let _xConstructor_ be ? Get(_x_, `"constructor"`). + 1. If SameValue(_xConstructor_, _C_) is *true*, return _x_. + 1. Let _promiseCapability_ be ? NewPromiseCapability(_C_). + 1. Perform ? Call(_promiseCapability_.[[Resolve]], *undefined*, « _x_ »). + 1. Return _promiseCapability_.[[Promise]]. + +
+

get Promise [ @@species ]

@@ -37451,6 +37460,58 @@

Promise.prototype.constructor

The initial value of `Promise.prototype.constructor` is the intrinsic object %Promise%.

+ +

Promise.prototype.finally ( _onFinally_ )

+

When the `finally` method is called with argument _onFinally_, the following steps are taken:

+ + 1. Let _promise_ be the *this* value. + 1. If Type(_promise_) is not Object, throw a *TypeError* exception. + 1. Let _C_ be ? SpeciesConstructor(_promise_, %Promise%). + 1. Assert: IsConstructor(_C_) is *true*. + 1. If IsCallable(_onFinally_) is *false*, + 1. Let _thenFinally_ be _onFinally_. + 1. Let _catchFinally_ be _onFinally_. + 1. Else, + 1. Let _thenFinally_ be a new built-in function object as defined in ThenFinally Function. + 1. Let _catchFinally_ be a new built-in function object as defined in CatchFinally Function. + 1. Set _thenFinally_ and _catchFinally_'s [[Constructor]] internal slots to _C_. + 1. Set _thenFinally_ and _catchFinally_'s [[OnFinally]] internal slots to _onFinally_. + 1. Return ? Invoke(_promise_, `"then"`, « _thenFinally_, _catchFinally_ »). + + + +

ThenFinally Function

+

A ThenFinally function is an anonymous built-in function that has a [[Constructor]] and an [[OnFinally]] internal slot. The value of the [[Constructor]] internal slot is a `Promise`-like constructor function object, and the value of the [[OnFinally]] internal slot is a function object.

+

When a ThenFinally function _F_ is called with argument _value_, the following steps are taken:

+ + 1. Let _onFinally_ be _F_.[[OnFinally]]. + 1. Assert: IsCallable(_onFinally_) is *true*. + 1. Let _result_ be ? Call(_onFinally_, *undefined*). + 1. Let _C_ be _F_.[[Constructor]]. + 1. Assert: IsConstructor(_C_) is *true*. + 1. Let _promise_ be ? PromiseResolve(_C_, _result_). + 1. Let _valueThunk_ be equivalent to a function that returns _value_. + 1. Return ? Invoke(_promise_, `"then"`, « _valueThunk_ »). + +
+ + +

CatchFinally Function

+

A CatchFinally function is an anonymous built-in function that has a [[Constructor]] and an [[OnFinally]] internal slot. The value of the [[Constructor]] internal slot is a `Promise`-like constructor function object, and the value of the [[OnFinally]] internal slot is a function object.

+

When a CatchFinally function _F_ is called with argument _reason_, the following steps are taken:

+ + 1. Let _onFinally_ be _F_.[[OnFinally]]. + 1. Assert: IsCallable(_onFinally_) is *true*. + 1. Let _result_ be ? Call(_onFinally_, *undefined*). + 1. Let _C_ be _F_.[[Constructor]]. + 1. Assert: IsConstructor(_C_) is *true*. + 1. Let _promise_ be ? PromiseResolve(_C_, _result_). + 1. Let _thrower_ be equivalent to a function that throws _reason_. + 1. Return ? Invoke(_promise_, `"then"`, « _thrower_ »). + +
+
+

Promise.prototype.then ( _onFulfilled_, _onRejected_ )