Add stack params to several customizer callback calls.

This commit is contained in:
John-David Dalton
2015-08-13 08:57:48 -07:00
parent dd472f489b
commit ba3ede584e
2 changed files with 53 additions and 36 deletions

View File

@@ -1602,7 +1602,7 @@
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) { function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
var result; var result;
if (customizer) { if (customizer) {
result = object ? customizer(value, key, object) : customizer(value); result = object ? customizer(value, key, object, stackA, stackB) : customizer(value);
} }
if (result !== undefined) { if (result !== undefined) {
return result; return result;
@@ -3489,9 +3489,13 @@
// Ignore non-index properties. // Ignore non-index properties.
while (++index < arrLength) { while (++index < arrLength) {
var arrValue = array[index], var arrValue = array[index],
othValue = other[index], othValue = other[index];
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
if (customizer) {
var result = isLoose
? customizer(othValue, arrValue, index, other, array, stackA, stackB)
: customizer(arrValue, othValue, index, array, other, stackA, stackB);
}
if (result !== undefined) { if (result !== undefined) {
if (result) { if (result) {
continue; continue;
@@ -3585,9 +3589,13 @@
while (++index < objLength) { while (++index < objLength) {
key = objProps[index]; key = objProps[index];
var objValue = object[key], var objValue = object[key],
othValue = other[key], othValue = other[key];
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
if (customizer) {
var result = isLoose
? customizer(othValue, objValue, key, other, object, stackA, stackB)
: customizer(objValue, othValue, key, object, other, stackA, stackB);
}
// Recursively compare objects (susceptible to call stack limits). // Recursively compare objects (susceptible to call stack limits).
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) { if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
return false; return false;
@@ -7640,7 +7648,7 @@
* This method is like `_.clone` except that it accepts `customizer` which * This method is like `_.clone` except that it accepts `customizer` which
* is invoked to produce the cloned value. If `customizer` returns `undefined` * is invoked to produce the cloned value. If `customizer` returns `undefined`
* cloning is handled by the method instead. The `customizer` is invoked with * cloning is handled by the method instead. The `customizer` is invoked with
* up to three arguments; (value [, index|key, object]). * up to five arguments; (value [, index|key, object, stackA, stackB]).
* *
* @static * @static
* @memberOf _ * @memberOf _
@@ -7964,10 +7972,10 @@
} }
/** /**
* This method is like `_.isEqual` except that it accepts `customizer` which * This method is like `_.isEqual` except that it accepts `customizer` which is
* is invoked to compare values. If `customizer` returns `undefined` comparisons * invoked to compare values. If `customizer` returns `undefined` comparisons are
* are handled by the method instead. The `customizer` is invoked with up to * handled by the method instead. The `customizer` is invoked with up to seven arguments:
* three arguments: (value, other [, index|key]). * (objectValue, otherValue [, index|key, object, other, stackA, stackB]).
* *
* @static * @static
* @memberOf _ * @memberOf _

View File

@@ -2020,7 +2020,7 @@
argsList.push(slice.call(arguments)); argsList.push(slice.call(arguments));
}); });
deepEqual(argsList, isDeepWith ? [[foo], [1, 'a', foo]] : [[foo]]); deepEqual(argsList, isDeepWith ? [[foo], [1, 'a', foo, [foo], [{ 'a': 1 }]]] : [[foo]]);
}); });
test('`_.' + methodName + '` should handle cloning if `customizer` returns `undefined`', 1, function() { test('`_.' + methodName + '` should handle cloning if `customizer` returns `undefined`', 1, function() {
@@ -5150,13 +5150,17 @@
test('`_.' + methodName + '` should provide the correct `customizer` arguments', 3, function() { test('`_.' + methodName + '` should provide the correct `customizer` arguments', 3, function() {
var args, var args,
object = { 'a': 1 }, object = { 'a': 1 },
source = { 'a': 2 }; source = { 'a': 2 },
expected = [1, 2, 'a', object, source];
func(object, source, function() { func(object, source, function() {
args || (args = slice.call(arguments)); args || (args = slice.call(arguments));
}); });
deepEqual(args, [1, 2, 'a', object, source], 'primitive property values'); if (isMergeWith) {
expected.push(undefined, undefined);
}
deepEqual(args, expected, 'primitive property values');
args = null; args = null;
object = { 'a': 1 }; object = { 'a': 1 };
@@ -5166,7 +5170,11 @@
args || (args = slice.call(arguments)); args || (args = slice.call(arguments));
}); });
deepEqual(args, [undefined, 2, 'b', object, source], 'missing destination property'); expected = [undefined, 2, 'b', object, source];
if (isMergeWith) {
expected.push(undefined, undefined);
}
deepEqual(args, expected, 'missing destination property');
var argsList = [], var argsList = [],
objectValue = [1, 2], objectValue = [1, 2],
@@ -5179,9 +5187,10 @@
argsList.push(slice.call(arguments)); argsList.push(slice.call(arguments));
}); });
var expected = [[objectValue, sourceValue, 'a', object, source]]; expected = [[objectValue, sourceValue, 'a', object, source]];
if (isMergeWith) { if (isMergeWith) {
expected.push([undefined, 2, 'b', sourceValue, sourceValue]); expected[0].push([sourceValue], [sourceValue]);
expected.push([undefined, 2, 'b', sourceValue, sourceValue, [sourceValue], [sourceValue]]);
} }
deepEqual(argsList, expected, 'object property values'); deepEqual(argsList, expected, 'object property values');
}); });
@@ -7055,14 +7064,14 @@
var expected = [ var expected = [
[object1, object2], [object1, object2],
[object1.a, object2.a, 'a'], [object1.a, object2.a, 'a', object1, object2, [], []],
[object1.a[0], object2.a[0], 0], [object1.a[0], object2.a[0], 0, object1.a, object2.a, [], []],
[object1.a[1], object2.a[1], 1], [object1.a[1], object2.a[1], 1, object1.a, object2.a, [], []],
[object1.b, object2.b, 'b'], [object1.b, object2.b, 'b', object1.b, object2.b, [], []],
[object1.b.a, object2.b.a, 'a'], [object1.b.a, object2.b.a, 'a', object1.b, object2.b, [], []],
[object1.b.a[0], object2.b.a[0], 0], [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a, [], []],
[object1.b.a[1], object2.b.a[1], 1], [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a, [], []],
[object1.b.b, object2.b.b, 'b'] [object1.b.b, object2.b.b, 'b', object1.b.b, object2.b.b, [], []]
]; ];
_.isEqualWith(object1, object2, function() { _.isEqualWith(object1, object2, function() {
@@ -7519,18 +7528,18 @@
object2.b = object1; object2.b = object1;
var expected = [ var expected = [
[object1.a, object2.a, 'a'], [object1.a, object2.a, 'a', object1, object2, [], []],
[object1.a[0], object2.a[0], 0], [object1.a[0], object2.a[0], 0, object1.a, object2.a, [], []],
[object1.a[1], object2.a[1], 1], [object1.a[1], object2.a[1], 1, object1.a, object2.a, [], []],
[object1.b, object2.b, 'b'], [object1.b, object2.b, 'b', object1, object2, [], []],
[object1.b.a, object2.b.a, 'a'], [object1.b.a, object2.b.a, 'a', object1.b, object2.b, [], []],
[object1.b.a[0], object2.b.a[0], 0], [object1.b.a[0], object2.b.a[0], 0, object1.b.a, object2.b.a, [], []],
[object1.b.a[1], object2.b.a[1], 1], [object1.b.a[1], object2.b.a[1], 1, object1.b.a, object2.b.a, [], []],
[object1.b.b, object2.b.b, 'b'], [object1.b.b, object2.b.b, 'b', object1.b, object2.b, [], []],
[object1.b.b.a, object2.b.b.a, 'a'], [object1.b.b.a, object2.b.b.a, 'a', object1.b.b, object2.b.b, [], []],
[object1.b.b.a[0], object2.b.b.a[0], 0], [object1.b.b.a[0], object2.b.b.a[0], 0, object1.b.b.a, object2.b.b.a, [], []],
[object1.b.b.a[1], object2.b.b.a[1], 1], [object1.b.b.a[1], object2.b.b.a[1], 1, object1.b.b.a, object2.b.b.a, [], []],
[object1.b.b.b, object2.b.b.b, 'b'] [object1.b.b.b, object2.b.b.b, 'b', object1.b.b, object2.b.b, [], []]
]; ];
_.isMatchWith(object1, object2, function() { _.isMatchWith(object1, object2, function() {