2
2
3
3
var callBind = require ( '../' ) ;
4
4
var bind = require ( 'function-bind' ) ;
5
+ var gOPD = require ( 'gopd' ) ;
6
+ var hasStrictMode = require ( 'has-strict-mode' ) ( ) ;
5
7
6
8
var test = require ( 'tape' ) ;
7
9
@@ -10,15 +12,16 @@ var test = require('tape');
10
12
* in io.js v3, it is configurable except on bound functions, hence the .bind()
11
13
*/
12
14
var functionsHaveConfigurableLengths = ! ! (
13
- Object . getOwnPropertyDescriptor
15
+ gOPD
16
+ && Object . getOwnPropertyDescriptor
14
17
&& Object . getOwnPropertyDescriptor ( bind . call ( function ( ) { } ) , 'length' ) . configurable
15
18
) ;
16
19
17
20
test ( 'callBind' , function ( t ) {
18
21
var sentinel = { sentinel : true } ;
19
22
var func = function ( a , b ) {
20
23
// eslint-disable-next-line no-invalid-this
21
- return [ this , a , b ] ;
24
+ return [ ! hasStrictMode && this === global ? undefined : this , a , b ] ;
22
25
} ;
23
26
t . equal ( func . length , 2 , 'original function length is 2' ) ;
24
27
t . deepEqual ( func ( ) , [ undefined , undefined , undefined ] , 'unbound func with too few args' ) ;
@@ -28,8 +31,8 @@ test('callBind', function (t) {
28
31
var bound = callBind ( func ) ;
29
32
t . equal ( bound . length , func . length + 1 , 'function length is preserved' , { skip : ! functionsHaveConfigurableLengths } ) ;
30
33
t . deepEqual ( bound ( ) , [ undefined , undefined , undefined ] , 'bound func with too few args' ) ;
31
- t . deepEqual ( bound ( 1 , 2 ) , [ 1 , 2 , undefined ] , 'bound func with right args' ) ;
32
- t . deepEqual ( bound ( 1 , 2 , 3 ) , [ 1 , 2 , 3 ] , 'bound func with too many args' ) ;
34
+ t . deepEqual ( bound ( 1 , 2 ) , [ hasStrictMode ? 1 : Object ( 1 ) , 2 , undefined ] , 'bound func with right args' ) ;
35
+ t . deepEqual ( bound ( 1 , 2 , 3 ) , [ hasStrictMode ? 1 : Object ( 1 ) , 2 , 3 ] , 'bound func with too many args' ) ;
33
36
34
37
var boundR = callBind ( func , sentinel ) ;
35
38
t . equal ( boundR . length , func . length , 'function length is preserved' , { skip : ! functionsHaveConfigurableLengths } ) ;
0 commit comments