mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Ensure isIterateeCall doesn't error if index is an object without a toString method. [closes #994]
This commit is contained in:
@@ -3839,8 +3839,11 @@
|
|||||||
} else {
|
} else {
|
||||||
prereq = type == 'string' && index in object;
|
prereq = type == 'string' && index in object;
|
||||||
}
|
}
|
||||||
var other = object[index];
|
if (prereq) {
|
||||||
return prereq && (value === value ? value === other : other !== other);
|
var other = object[index];
|
||||||
|
return value === value ? value === other : other !== other;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
26
test/test.js
26
test/test.js
@@ -833,6 +833,18 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return `false` for non-iteratee calls', 4, function() {
|
||||||
|
if (func) {
|
||||||
|
strictEqual(func(2, 0, array), false);
|
||||||
|
strictEqual(func(1, 1.1, array), false);
|
||||||
|
strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
|
||||||
|
strictEqual(func(1, 'b', object), false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(4);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('should work with `NaN` values', 2, function() {
|
test('should work with `NaN` values', 2, function() {
|
||||||
if (func) {
|
if (func) {
|
||||||
strictEqual(func(NaN, 0, [NaN]), true);
|
strictEqual(func(NaN, 0, [NaN]), true);
|
||||||
@@ -843,15 +855,17 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `false` for non-iteratee calls', 4, function() {
|
test('should not error when `index` is an object without a `toString` method', 1, function() {
|
||||||
if (func) {
|
if (func) {
|
||||||
strictEqual(func(2, 0, array), false);
|
try {
|
||||||
strictEqual(func(1, 1.1, array), false);
|
var actual = func(1, { 'toString': null }, [1]);
|
||||||
strictEqual(func(1, 0, { 'length': MAX_SAFE_INTEGER + 1 }), false);
|
} catch(e) {
|
||||||
strictEqual(func(1, 'b', object), false);
|
var message = e.message;
|
||||||
|
}
|
||||||
|
strictEqual(actual, false, message || '');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(4);
|
skipTest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user