File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ var bind = require('function-bind');
4
4
var GetIntrinsic = require ( 'get-intrinsic' ) ;
5
5
var setFunctionLength = require ( 'set-function-length' ) ;
6
6
7
+ var $TypeError = GetIntrinsic ( '%TypeError%' ) ;
7
8
var $apply = GetIntrinsic ( '%Function.prototype.apply%' ) ;
8
9
var $call = GetIntrinsic ( '%Function.prototype.call%' ) ;
9
10
var $reflectApply = GetIntrinsic ( '%Reflect.apply%' , true ) || bind . call ( $call , $apply ) ;
@@ -21,6 +22,9 @@ if ($defineProperty) {
21
22
}
22
23
23
24
module . exports = function callBind ( originalFunction ) {
25
+ if ( typeof originalFunction !== 'function' ) {
26
+ throw new $TypeError ( 'a function is required' ) ;
27
+ }
24
28
var func = $reflectApply ( bind , $call , arguments ) ;
25
29
return setFunctionLength (
26
30
func ,
Original file line number Diff line number Diff line change 15
15
"lint" : " eslint --ext=.js,.mjs ." ,
16
16
"postlint" : " evalmd README.md" ,
17
17
"pretest" : " npm run lint" ,
18
- "tests-only" : " nyc tape 'test/*'" ,
18
+ "tests-only" : " nyc tape 'test/**/*.js '" ,
19
19
"test" : " npm run tests-only" ,
20
20
"posttest" : " aud --production" ,
21
21
"version" : " auto-changelog && git add CHANGELOG.md" ,
53
53
"@ljharb/eslint-config" : " ^21.1.0" ,
54
54
"aud" : " ^2.0.3" ,
55
55
"auto-changelog" : " ^2.4.0" ,
56
+ "es-value-fixtures" : " ^1.4.2" ,
56
57
"eslint" : " =8.8.0" ,
57
58
"evalmd" : " ^0.0.19" ,
59
+ "for-each" : " ^0.3.3" ,
58
60
"gopd" : " ^1.0.1" ,
59
61
"has-strict-mode" : " ^1.0.1" ,
60
62
"in-publish" : " ^2.0.1" ,
61
63
"npmignore" : " ^0.3.0" ,
62
64
"nyc" : " ^10.3.2" ,
65
+ "object-inspect" : " ^1.13.1" ,
63
66
"safe-publish-latest" : " ^2.0.0" ,
64
67
"tape" : " ^5.7.1"
65
68
},
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ var callBind = require('../');
4
4
var bind = require ( 'function-bind' ) ;
5
5
var gOPD = require ( 'gopd' ) ;
6
6
var hasStrictMode = require ( 'has-strict-mode' ) ( ) ;
7
+ var forEach = require ( 'for-each' ) ;
8
+ var inspect = require ( 'object-inspect' ) ;
9
+ var v = require ( 'es-value-fixtures' ) ;
7
10
8
11
var test = require ( 'tape' ) ;
9
12
@@ -18,6 +21,14 @@ var functionsHaveConfigurableLengths = !!(
18
21
) ;
19
22
20
23
test ( 'callBind' , function ( t ) {
24
+ forEach ( v . nonFunctions , function ( nonFunction ) {
25
+ t [ 'throws' ] (
26
+ function ( ) { callBind ( nonFunction ) ; } ,
27
+ TypeError ,
28
+ inspect ( nonFunction ) + ' is not a function'
29
+ ) ;
30
+ } ) ;
31
+
21
32
var sentinel = { sentinel : true } ;
22
33
var func = function ( a , b ) {
23
34
// eslint-disable-next-line no-invalid-this
You can’t perform that action at this time.
0 commit comments