This repository was archived by the owner on Aug 21, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments