Skip to content

Commit

Permalink
Add missing checks to Promise.resolve and Promise.reject.
Browse files Browse the repository at this point in the history
These checks were overlooked when @@species was resolved from these
methods.

Discovered by running the ES2015 test262 test suite against es6-shim.
  • Loading branch information
cscott committed Dec 12, 2015
1 parent 20d978a commit c8a69f9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,9 @@

reject: function reject(reason) {
var C = this;
if (!ES.TypeIsObject(C)) {
throw new TypeError('Bad promise constructor');
}
var capability = new PromiseCapability(C);
var rejectFunc = capability.reject;
rejectFunc(reason); // call with this===undefined
Expand All @@ -2325,6 +2328,9 @@
resolve: function resolve(v) {
// See https://esdiscuss.org/topic/fixing-promise-resolve for spec
var C = this;
if (!ES.TypeIsObject(C)) {
throw new TypeError('Bad promise constructor');
}
if (ES.IsPromise(v)) {
var constructor = v.constructor;
if (constructor === C) { return v; }
Expand Down

0 comments on commit c8a69f9

Please sign in to comment.