Skip to content
This repository was archived by the owner on Aug 21, 2022. It is now read-only.

Commit c0ebb56

Browse files
committed
then checks isCallable
1 parent ffd4ed9 commit c0ebb56

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/polyfill/promise.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,27 @@ window.Promise || (window.Promise = new function () {
2020
});
2121
}
2222

23+
function isCallable(anything) {
24+
return 'function' == typeof anything;
25+
}
26+
2327
function isPromise(anything) {
2428
return anything instanceof Promise;
2529
}
2630

2731
function isThenable(anything) {
28-
return Object(anything) === anything &&
29-
'function' == typeof anything.then;
32+
return Object(anything) === anything && isCallable(anything.then);
3033
}
3134

3235
function isSettled(promise) {
3336
return promise._fulfilled || promise._rejected;
3437
}
3538

36-
function defaultOnFulfilled(value) {
39+
function identity(value) {
3740
return value;
3841
}
3942

40-
function defaultOnRejected(reason) {
43+
function thrower(reason) {
4144
throw reason;
4245
}
4346

@@ -204,6 +207,9 @@ window.Promise || (window.Promise = new function () {
204207

205208
var promise = this;
206209

210+
onFulfilled = isCallable(onFulfilled) ? onFulfilled : identity;
211+
onRejected = isCallable(onRejected) ? onRejected : thrower;
212+
207213
return new Promise(function (resolve, reject) {
208214

209215
onFulfilled = onFulfilled || defaultOnFulfilled;

0 commit comments

Comments
 (0)