Skip to content

Commit

Permalink
Merge pull request #379 from paulmillr/promise-checks
Browse files Browse the repository at this point in the history
[Fix] Add missing checks to `Promise.resolve` and `Promise.reject`
  • Loading branch information
ljharb committed Dec 13, 2015
2 parents 20d978a + c8a69f9 commit 42c0217
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 42c0217

Please sign in to comment.