This repository was archived by the owner on Aug 21, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 12 files changed +67
-31
lines changed Expand file tree Collapse file tree 12 files changed +67
-31
lines changed Original file line number Diff line number Diff line change @@ -585,24 +585,27 @@ window.Promise || (window.Promise = new function () {
585585 } ) ;
586586 }
587587
588+ function isCallable ( anything ) {
589+ return 'function' == typeof anything ;
590+ }
591+
588592 function isPromise ( anything ) {
589593 return anything instanceof Promise ;
590594 }
591595
592596 function isThenable ( anything ) {
593- return Object ( anything ) === anything &&
594- 'function' == typeof anything . then ;
597+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
595598 }
596599
597600 function isSettled ( promise ) {
598601 return promise . _fulfilled || promise . _rejected ;
599602 }
600603
601- function defaultOnFulfilled ( value ) {
604+ function identity ( value ) {
602605 return value ;
603606 }
604607
605- function defaultOnRejected ( reason ) {
608+ function thrower ( reason ) {
606609 throw reason ;
607610 }
608611
@@ -769,6 +772,9 @@ window.Promise || (window.Promise = new function () {
769772
770773 var promise = this ;
771774
775+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
776+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
777+
772778 return new Promise ( function ( resolve , reject ) {
773779
774780 onFulfilled = onFulfilled || defaultOnFulfilled ;
Original file line number Diff line number Diff line change @@ -585,24 +585,27 @@ window.Promise || (window.Promise = new function () {
585585 } ) ;
586586 }
587587
588+ function isCallable ( anything ) {
589+ return 'function' == typeof anything ;
590+ }
591+
588592 function isPromise ( anything ) {
589593 return anything instanceof Promise ;
590594 }
591595
592596 function isThenable ( anything ) {
593- return Object ( anything ) === anything &&
594- 'function' == typeof anything . then ;
597+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
595598 }
596599
597600 function isSettled ( promise ) {
598601 return promise . _fulfilled || promise . _rejected ;
599602 }
600603
601- function defaultOnFulfilled ( value ) {
604+ function identity ( value ) {
602605 return value ;
603606 }
604607
605- function defaultOnRejected ( reason ) {
608+ function thrower ( reason ) {
606609 throw reason ;
607610 }
608611
@@ -769,6 +772,9 @@ window.Promise || (window.Promise = new function () {
769772
770773 var promise = this ;
771774
775+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
776+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
777+
772778 return new Promise ( function ( resolve , reject ) {
773779
774780 onFulfilled = onFulfilled || defaultOnFulfilled ;
Original file line number Diff line number Diff line change @@ -585,24 +585,27 @@ window.Promise || (window.Promise = new function () {
585585 } ) ;
586586 }
587587
588+ function isCallable ( anything ) {
589+ return 'function' == typeof anything ;
590+ }
591+
588592 function isPromise ( anything ) {
589593 return anything instanceof Promise ;
590594 }
591595
592596 function isThenable ( anything ) {
593- return Object ( anything ) === anything &&
594- 'function' == typeof anything . then ;
597+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
595598 }
596599
597600 function isSettled ( promise ) {
598601 return promise . _fulfilled || promise . _rejected ;
599602 }
600603
601- function defaultOnFulfilled ( value ) {
604+ function identity ( value ) {
602605 return value ;
603606 }
604607
605- function defaultOnRejected ( reason ) {
608+ function thrower ( reason ) {
606609 throw reason ;
607610 }
608611
@@ -769,6 +772,9 @@ window.Promise || (window.Promise = new function () {
769772
770773 var promise = this ;
771774
775+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
776+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
777+
772778 return new Promise ( function ( resolve , reject ) {
773779
774780 onFulfilled = onFulfilled || defaultOnFulfilled ;
Original file line number Diff line number Diff line change @@ -585,24 +585,27 @@ window.Promise || (window.Promise = new function () {
585585 } ) ;
586586 }
587587
588+ function isCallable ( anything ) {
589+ return 'function' == typeof anything ;
590+ }
591+
588592 function isPromise ( anything ) {
589593 return anything instanceof Promise ;
590594 }
591595
592596 function isThenable ( anything ) {
593- return Object ( anything ) === anything &&
594- 'function' == typeof anything . then ;
597+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
595598 }
596599
597600 function isSettled ( promise ) {
598601 return promise . _fulfilled || promise . _rejected ;
599602 }
600603
601- function defaultOnFulfilled ( value ) {
604+ function identity ( value ) {
602605 return value ;
603606 }
604607
605- function defaultOnRejected ( reason ) {
608+ function thrower ( reason ) {
606609 throw reason ;
607610 }
608611
@@ -769,6 +772,9 @@ window.Promise || (window.Promise = new function () {
769772
770773 var promise = this ;
771774
775+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
776+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
777+
772778 return new Promise ( function ( resolve , reject ) {
773779
774780 onFulfilled = onFulfilled || defaultOnFulfilled ;
Original file line number Diff line number Diff line change @@ -1005,24 +1005,27 @@ window.Promise || (window.Promise = new function () {
10051005 } ) ;
10061006 }
10071007
1008+ function isCallable ( anything ) {
1009+ return 'function' == typeof anything ;
1010+ }
1011+
10081012 function isPromise ( anything ) {
10091013 return anything instanceof Promise ;
10101014 }
10111015
10121016 function isThenable ( anything ) {
1013- return Object ( anything ) === anything &&
1014- 'function' == typeof anything . then ;
1017+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
10151018 }
10161019
10171020 function isSettled ( promise ) {
10181021 return promise . _fulfilled || promise . _rejected ;
10191022 }
10201023
1021- function defaultOnFulfilled ( value ) {
1024+ function identity ( value ) {
10221025 return value ;
10231026 }
10241027
1025- function defaultOnRejected ( reason ) {
1028+ function thrower ( reason ) {
10261029 throw reason ;
10271030 }
10281031
@@ -1189,6 +1192,9 @@ window.Promise || (window.Promise = new function () {
11891192
11901193 var promise = this ;
11911194
1195+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
1196+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
1197+
11921198 return new Promise ( function ( resolve , reject ) {
11931199
11941200 onFulfilled = onFulfilled || defaultOnFulfilled ;
Original file line number Diff line number Diff line change @@ -1005,24 +1005,27 @@ window.Promise || (window.Promise = new function () {
10051005 } ) ;
10061006 }
10071007
1008+ function isCallable ( anything ) {
1009+ return 'function' == typeof anything ;
1010+ }
1011+
10081012 function isPromise ( anything ) {
10091013 return anything instanceof Promise ;
10101014 }
10111015
10121016 function isThenable ( anything ) {
1013- return Object ( anything ) === anything &&
1014- 'function' == typeof anything . then ;
1017+ return Object ( anything ) === anything && isCallable ( anything . then ) ;
10151018 }
10161019
10171020 function isSettled ( promise ) {
10181021 return promise . _fulfilled || promise . _rejected ;
10191022 }
10201023
1021- function defaultOnFulfilled ( value ) {
1024+ function identity ( value ) {
10221025 return value ;
10231026 }
10241027
1025- function defaultOnRejected ( reason ) {
1028+ function thrower ( reason ) {
10261029 throw reason ;
10271030 }
10281031
@@ -1189,6 +1192,9 @@ window.Promise || (window.Promise = new function () {
11891192
11901193 var promise = this ;
11911194
1195+ onFulfilled = isCallable ( onFulfilled ) ? onFulfilled : identity ;
1196+ onRejected = isCallable ( onRejected ) ? onRejected : thrower ;
1197+
11921198 return new Promise ( function ( resolve , reject ) {
11931199
11941200 onFulfilled = onFulfilled || defaultOnFulfilled ;
You can’t perform that action at this time.
0 commit comments