mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Ensure _.isEqual performs comparisons between objects with shared property values correctly. [closes #415]
This commit is contained in:
69
lodash.js
69
lodash.js
@@ -1446,51 +1446,54 @@
|
||||
|
||||
// recursively compare objects and arrays (susceptible to call stack limits)
|
||||
if (isArr) {
|
||||
// compare lengths to determine if a deep comparison is necessary
|
||||
length = a.length;
|
||||
size = b.length;
|
||||
result = size == length;
|
||||
|
||||
// compare lengths to determine if a deep comparison is necessary
|
||||
result = size == a.length;
|
||||
if (!result && !isWhere) {
|
||||
return result;
|
||||
}
|
||||
// deep compare the contents, ignoring non-numeric properties
|
||||
while (size--) {
|
||||
var index = length,
|
||||
value = b[size];
|
||||
if (result || isWhere) {
|
||||
// deep compare the contents, ignoring non-numeric properties
|
||||
while (size--) {
|
||||
var index = length,
|
||||
value = b[size];
|
||||
|
||||
if (isWhere) {
|
||||
while (index--) {
|
||||
if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
|
||||
break;
|
||||
if (isWhere) {
|
||||
while (index--) {
|
||||
if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
|
||||
break;
|
||||
}
|
||||
} else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
|
||||
// which, in this case, is more costly
|
||||
forIn(b, function(value, key, b) {
|
||||
if (hasOwnProperty.call(b, key)) {
|
||||
// count the number of properties.
|
||||
size++;
|
||||
// deep compare each property value.
|
||||
return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
|
||||
}
|
||||
});
|
||||
|
||||
if (result && !isWhere) {
|
||||
// ensure both objects have the same number of properties
|
||||
forIn(a, function(value, key, a) {
|
||||
if (hasOwnProperty.call(a, key)) {
|
||||
// `size` will be `-1` if `a` has more properties than `b`
|
||||
return (result = --size > -1);
|
||||
else {
|
||||
// deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
|
||||
// which, in this case, is more costly
|
||||
forIn(b, function(value, key, b) {
|
||||
if (hasOwnProperty.call(b, key)) {
|
||||
// count the number of properties.
|
||||
size++;
|
||||
// deep compare each property value.
|
||||
return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
|
||||
}
|
||||
});
|
||||
|
||||
if (result && !isWhere) {
|
||||
// ensure both objects have the same number of properties
|
||||
forIn(a, function(value, key, a) {
|
||||
if (hasOwnProperty.call(a, key)) {
|
||||
// `size` will be `-1` if `a` has more properties than `b`
|
||||
return (result = --size > -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
stackA.pop();
|
||||
stackB.pop();
|
||||
|
||||
if (initedStack) {
|
||||
releaseArray(stackA);
|
||||
releaseArray(stackB);
|
||||
|
||||
Reference in New Issue
Block a user