Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ea5dea4

Browse files
committed
making the equals method work when the obj graph has circular dependencies
1 parent 9ad6c77 commit ea5dea4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Angular.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -825,18 +825,24 @@ function shallowCopy(src, dst) {
825825
* @param {*} o2 Object or value to compare.
826826
* @returns {boolean} True if arguments are equal.
827827
*/
828-
function equals(o1, o2) {
828+
function equals(o1, o2, visitedObjArr) {
829829
if (o1 === o2) return true;
830830
if (o1 === null || o2 === null) return false;
831831
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
832832
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
833833
if (t1 == t2) {
834834
if (t1 == 'object') {
835+
if (typeof visitedObjArr == 'undefined') {
836+
visitedObjArr = {};
837+
} else {
838+
if (o1 in visitedObjArr) return true;
839+
}
840+
visitedObjArr[o1] = true;
835841
if (isArray(o1)) {
836842
if (!isArray(o2)) return false;
837843
if ((length = o1.length) == o2.length) {
838844
for (key=0; key<length; key++) {
839-
if (!equals(o1[key], o2[key])) return false;
845+
if (!equals(o1[key], o2[key], visitedObjArr)) return false;
840846
}
841847
return true;
842848
}
@@ -850,7 +856,7 @@ function equals(o1, o2) {
850856
keySet = {};
851857
for (key in o1) {
852858
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
853-
if (!equals(o1[key], o2[key])) return false;
859+
if (!equals(o1[key], o2[key], visitedObjArr)) return false;
854860
keySet[key] = true;
855861
}
856862
for (key in o2) {

0 commit comments

Comments
 (0)