8000 Ensure `func` is a function before querying the weakmap. [closes #1319] · lodash/lodash@744f3a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 744f3a5

Browse files
committed
Ensure func is a function before querying the weakmap. [closes #1319]
1 parent 4753c78 commit 744f3a5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lodash.src.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@
39983998
* @returns {*} Returns the metadata for `func`.
39993999
*/
40004000
var getData = !metaMap ? noop : function(func) {
4001-
return metaMap.get(func);
4001+
return typeof func == 'function' ? metaMap.get(func) : undefined;
40024002
};
40034003

40044004
/**

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,20 @@
33793379
fn = function(a, b) { return slice.call(arguments); },
33803380
isCurry = methodName == 'curry';
33813381

3382+
test('`_.' + methodName + '` should not error on functions with the same name as lodash methods', 1, function() {
3383+
function run(a, b) {
3384+
return a + b;
3385+
}
3386+
3387+
var curried = func(run);
3388+
3389+
try {
3390+
var actual = curried(1)(2);
3391+
} catch(e) {}
3392+
3393+
strictEqual(actual, 3);
3394+
});
3395+
33823396
test('`_.' + methodName + '` should work as an iteratee for methods like `_.map`', 2, function() {
33833397
var array = [fn, fn, fn],
33843398
object = { 'a': fn, 'b': fn, 'c': fn };

0 commit comments

Comments
 (0)
0