Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Remove IsPromise brand check.
Browse files Browse the repository at this point in the history
Fixes #41.
  • Loading branch information
ljharb committed Oct 30, 2017
1 parent 4cc43af commit a162888
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@
</div>
</div>
<div id="spec-container">
<h1 class="version first">Stage 3 Draft / October 27, 2017</h1>
<h1 class="version first">Stage 3 Draft / October 30, 2017</h1>
<h1 class="title">Promise.prototype.finally</h1>

<emu-clause id="sec-promise.prototype.finally">
Expand All @@ -2159,8 +2159,7 @@ <h1><span class="secnum">1</span>Promise.prototype.finally ( <var>onFinally</var
<li>Let <var>promise</var> be the
<emu-val>this</emu-val> value.</li>
<li>If
<emu-xref aoid="IsPromise" id="_ref_2"><a href="https://tc39.github.io/ecma262/#sec-ispromise">IsPromise</a></emu-xref>(<var>promise</var>) is
<emu-val>false</emu-val>, throw a
<emu-xref aoid="Type" id="_ref_2"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>promise</var>) is not Object, throw a
<emu-val>TypeError</emu-val> exception.</li>
<li>Let <var>C</var> be ?
<emu-xref aoid="SpeciesConstructor" id="_ref_3"><a href="https://tc39.github.io/ecma262/#sec-speciesconstructor">SpeciesConstructor</a></emu-xref>(<var>promise</var>,
Expand Down
9 changes: 6 additions & 3 deletions polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ if (typeof Promise.prototype.finally !== 'function') {

var shim = {
finally(onFinally) {
var promise = this;
if (typeof promise !== 'object' || promise === null) {
throw new TypeError('"this" value is not an Object');
}
var C = speciesConstructor(promise, Promise); // throws if SpeciesConstructor throws
var handler = typeof onFinally === 'function' ? onFinally : () => {};
var C;
var newPromise = Promise.prototype.then.call(
this, // throw if IsPromise(this) is not true
promise,
x => new C(resolve => resolve(handler())).then(() => x),
e => new C(resolve => resolve(handler())).then(() => { throw e; })
);
C = speciesConstructor(this, Promise); // throws if SpeciesConstructor throws
return newPromise;
}
};
Expand Down
2 changes: 1 addition & 1 deletion spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contributors: Jordan Harband
<p>When the `finally` method is called with argument _onFinally_, the following steps are taken:</p>
<emu-alg>
1. Let _promise_ be the *this* value.
1. If IsPromise(_promise_) is *false*, throw a *TypeError* exception.
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 not *true*,
Expand Down
6 changes: 3 additions & 3 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

When the `finally` method is called with argument _onFinally_, the following steps are taken:
1. Let _promise_ be the **this** value.
1. If <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-ispromise">IsPromise</a>(_promise_) is **false**, throw a **TypeError** exception.
1. If <a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a>(_promise_) is not Object, throw a *TypeError* exception.
1. Assert: <a href="https://tc39.github.io/ecma262/#sec-isconstructor">IsConstructor</a>(_C_) is *true*.
1. If <a href="https://tc39.github.io/ecma262/#sec-iscallable">IsCallable</a>(_onFinally_) is not *true*,
1. Let _thenFinally_ be _onFinally_.
Expand Down Expand Up @@ -46,14 +46,14 @@ When a CatchFinally function _F_ is called with argument _reason_, the following

The `resolve` function returns either a new promise resolved with the passed argument, or the argument itself if the argument is a promise produced by this constructor.
1. Let _C_ be the *this* value.
1. If <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-data-types-and-values">Type</a>(_C_) is not Object, throw a *TypeError* exception.
1. If <a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a>(_C_) is not Object, throw a *TypeError* exception.
1. Return ? PromiseResolve(_C_, _x_).

Note: the `resolve` function expects its *this* value to be a constructor function that supports the parameter conventions of the `Promise` constructor.

## PromiseResolve ( _C_, _x_ )
The abstract operation PromiseResolve, given a constructor and a value, returns a new promise resolved with that value.
1. Assert: <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-data-types-and-values">Type</a>(_C_) is Object.
1. Assert: <a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a>(_C_) is Object.
1. If <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-ispromise">IsPromise</a>(_x_) is *true*, then
1. Let _xConstructor_ be ? <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-get-o-p">Get</a>(_x_, `"constructor"`).
1. If SameValue(_xConstructor_, _C_) is *true*, return _x_.
Expand Down

0 comments on commit a162888

Please sign in to comment.