Add function checks to _.modArgs.

This commit is contained in:
jdalton
2015-06-02 20:14:55 -07:00
parent f402dbd1e3
commit 50e129bd8f
2 changed files with 20 additions and 2 deletions

View File

@@ -348,6 +348,20 @@
} }
return -1; return -1;
} }
/**
* The base implementation of `_.isFunction` without support for environments
* with incorrect `typeof` results.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
*/
function baseIsFunction(value) {
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
return typeof value == 'function' || false;
}
/** /**
* Converts `value` to a string if it's not one. An empty string is returned * Converts `value` to a string if it's not one. An empty string is returned
@@ -8033,6 +8047,9 @@
* // => [25, 20] * // => [25, 20]
*/ */
var modArgs = restParam(function(func, transforms) { var modArgs = restParam(function(func, transforms) {
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = transforms.length; var length = transforms.length;
return restParam(function(args) { return restParam(function(args) {
var index = nativeMin(args.length, length); var index = nativeMin(args.length, length);

View File

@@ -17836,6 +17836,7 @@
'defer', 'defer',
'delay', 'delay',
'memoize', 'memoize',
'modArgs',
'negate', 'negate',
'once', 'once',
'partial', 'partial',
@@ -17896,7 +17897,7 @@
var acceptFalsey = _.difference(allMethods, rejectFalsey); var acceptFalsey = _.difference(allMethods, rejectFalsey);
test('should accept falsey arguments', 226, function() { test('should accept falsey arguments', 225, function() {
var emptyArrays = _.map(falsey, _.constant([])), var emptyArrays = _.map(falsey, _.constant([])),
isExposed = '_' in root, isExposed = '_' in root,
oldDash = root._; oldDash = root._;
@@ -17962,7 +17963,7 @@
}); });
}); });
test('should throw an error for falsey arguments', 24, function() { test('should throw an error for falsey arguments', 25, function() {
_.each(rejectFalsey, function(methodName) { _.each(rejectFalsey, function(methodName) {
var expected = _.map(falsey, _.constant(true)), var expected = _.map(falsey, _.constant(true)),
func = _[methodName]; func = _[methodName];