Make previous _.isEqual fix pass Underscore unit tests.

Former-commit-id: 2b3563bb628b307ad2e4a2ef00ed5afec2f59506
This commit is contained in:
John-David Dalton
2012-09-09 14:11:07 -07:00
parent e16918ee32
commit 17935a78ff
2 changed files with 8 additions and 11 deletions

View File

@@ -107,11 +107,13 @@
'__chain__', '__chain__',
'__proto__', '__proto__',
'__wrapped__', '__wrapped__',
'a',
'after', 'after',
'all', 'all',
'amd', 'amd',
'any', 'any',
'attachEvent', 'attachEvent',
'b',
'bind', 'bind',
'bindAll', 'bindAll',
'chain', 'chain',
@@ -302,7 +304,7 @@
// minify internal properties used by 'compareAscending', `_.clone`, `_.isEqual`, `_.merge`, and `_.sortBy` // minify internal properties used by 'compareAscending', `_.clone`, `_.isEqual`, `_.merge`, and `_.sortBy`
(function() { (function() {
var properties = ['criteria', 'index', 'isCircular', 'source', 'thorough', 'value'], var properties = ['criteria', 'index', 'source', 'thorough', 'value'],
snippets = source.match(/( +)(?:function (?:clone|compareAscending|isEqual)|var merge|var sortBy)\b[\s\S]+?\n\1}/g); snippets = source.match(/( +)(?:function (?:clone|compareAscending|isEqual)|var merge|var sortBy)\b[\s\S]+?\n\1}/g);
if (!snippets) { if (!snippets) {

View File

@@ -1445,7 +1445,7 @@
return a === b; return a === b;
} }
// init internal data // init internal data
data || (data = { 'isCircular': false, 'thorough': null }); data || (data = { 'thorough': null });
// avoid slower checks on non-objects // avoid slower checks on non-objects
if (data.thorough == null) { if (data.thorough == null) {
@@ -1509,10 +1509,6 @@
return false; return false;
} }
// exit if it's the second pass of a circular reference
if (data.isCircular) {
return true;
}
// assume cyclic structures are equal // assume cyclic structures are equal
// the algorithm for detecting cyclic structures is adapted from ES 5.1 // the algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3)
@@ -1520,9 +1516,8 @@
length = stack.length; length = stack.length;
while (length--) { while (length--) {
if (stack[length] == a) { if (stack[length].a == a) {
data.isCircular = true; return stack[length].b == b;
break;
} }
} }
@@ -1530,8 +1525,8 @@
result = true, result = true,
size = 0; size = 0;
// add `a` to the stack of traversed objects // add `a` and `b` to the stack of traversed objects
stack.push(a); stack.push({ 'a': a, 'b': b });
// recursively compare objects and arrays (susceptible to call stack limits) // recursively compare objects and arrays (susceptible to call stack limits)
if (isArr) { if (isArr) {