diff --git a/lib/node_modules/@stdlib/utils/mask-arguments/lib/main.js b/lib/node_modules/@stdlib/utils/mask-arguments/lib/main.js index 102935b06985..70e19f1b56e8 100644 --- a/lib/node_modules/@stdlib/utils/mask-arguments/lib/main.js +++ b/lib/node_modules/@stdlib/utils/mask-arguments/lib/main.js @@ -148,7 +148,7 @@ function maskArguments( fcn, mask, thisArg ) { var i; args = []; - for ( i = 0; i < arguments.length; i++ ) { + for ( i = 0; i < idx.length; i++ ) { args.push( arguments[ idx[i] ] ); } return fcn.apply( thisArg, args ); diff --git a/lib/node_modules/@stdlib/utils/mask-arguments/test/test.js b/lib/node_modules/@stdlib/utils/mask-arguments/test/test.js index 289dc26c3744..805caf337432 100644 --- a/lib/node_modules/@stdlib/utils/mask-arguments/test/test.js +++ b/lib/node_modules/@stdlib/utils/mask-arguments/test/test.js @@ -234,6 +234,42 @@ tape( 'the returned function invokes a function according to an argument mask (n } }); +tape( 'the returned function only forwards the masked-in arguments when called with more arguments than mask entries (nary)', function test( t ) { + var bar = maskArguments( foo, [ 1, 1, 1, 1, 1, 1 ] ); + + t.deepEqual( bar( 1, 2, 3, 4, 5, 6, 7, 8 ), [ 6, 1, 2, 3, 4, 5, 6 ], 'returns expected value' ); + t.end(); + + function foo() { + var args; + var i; + + args = [ arguments.length ]; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return args; + } +}); + +tape( 'the returned function forwards the masked-in arguments when called with fewer arguments than mask entries (nary)', function test( t ) { + var bar = maskArguments( foo, [ 1, 1, 1, 1, 1, 1 ] ); + + t.deepEqual( bar( 1, 2, 3 ), [ 6, 1, 2, 3, void 0, void 0, void 0 ], 'returns expected value' ); + t.end(); + + function foo() { + var args; + var i; + + args = [ arguments.length ]; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return args; + } +}); + tape( 'the function supports providing a `this` context', function test( t ) { var ctx; var bar; diff --git a/lib/node_modules/@stdlib/utils/pick-arguments/lib/main.js b/lib/node_modules/@stdlib/utils/pick-arguments/lib/main.js index 2d1fdd42915a..24d6ed0e5882 100644 --- a/lib/node_modules/@stdlib/utils/pick-arguments/lib/main.js +++ b/lib/node_modules/@stdlib/utils/pick-arguments/lib/main.js @@ -148,7 +148,7 @@ function pickArguments( fcn, indices, thisArg ) { var i; args = []; - for ( i = 0; i < arguments.length; i++ ) { + for ( i = 0; i < idx.length; i++ ) { args.push( arguments[ idx[i] ] ); } return fcn.apply( thisArg, args ); diff --git a/lib/node_modules/@stdlib/utils/pick-arguments/test/test.js b/lib/node_modules/@stdlib/utils/pick-arguments/test/test.js index 3ab8c7200222..47ac0c93b8d5 100644 --- a/lib/node_modules/@stdlib/utils/pick-arguments/test/test.js +++ b/lib/node_modules/@stdlib/utils/pick-arguments/test/test.js @@ -236,6 +236,42 @@ tape( 'the returned function invokes a function with specified arguments (nary)' } }); +tape( 'the returned function only forwards the specified number of arguments when called with more arguments than indices (nary)', function test( t ) { + var bar = pickArguments( foo, [ 0, 1, 2, 3, 4, 5 ] ); + + t.deepEqual( bar( 1, 2, 3, 4, 5, 6, 7, 8 ), [ 6, 1, 2, 3, 4, 5, 6 ], 'returns expected value' ); + t.end(); + + function foo() { + var args; + var i; + + args = [ arguments.length ]; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return args; + } +}); + +tape( 'the returned function forwards the specified number of arguments when called with fewer arguments than indices (nary)', function test( t ) { + var bar = pickArguments( foo, [ 0, 1, 2, 3, 4, 5 ] ); + + t.deepEqual( bar( 1, 2, 3 ), [ 6, 1, 2, 3, void 0, void 0, void 0 ], 'returns expected value' ); + t.end(); + + function foo() { + var args; + var i; + + args = [ arguments.length ]; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return args; + } +}); + tape( 'the function supports providing a `this` context', function test( t ) { var ctx; var bar;