* @ngdoc function * @name angular.equals * @module ng * @kind function * * @description * Determines if two objects or two values are equivalent. Supports value types, regular * expressions, arrays and objects. * * Two objects or values are considered equivalent if at least one of the follo
(o1, o2)
| 1047 | * @returns {boolean} True if arguments are equal. |
| 1048 | */ |
| 1049 | function equals(o1, o2) { |
| 1050 | if (o1 === o2) return true; |
| 1051 | if (o1 === null || o2 === null) return false; |
| 1052 | if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN |
| 1053 | var t1 = typeof o1, t2 = typeof o2, length, key, keySet; |
| 1054 | if (t1 == t2) { |
| 1055 | if (t1 == 'object') { |
| 1056 | if (isArray(o1)) { |
| 1057 | if (!isArray(o2)) return false; |
| 1058 | if ((length = o1.length) == o2.length) { |
| 1059 | for (key = 0; key < length; key++) { |
| 1060 | if (!equals(o1[key], o2[key])) return false; |
| 1061 | } |
| 1062 | return true; |
| 1063 | } |
| 1064 | } else if (isDate(o1)) { |
| 1065 | if (!isDate(o2)) return false; |
| 1066 | return equals(o1.getTime(), o2.getTime()); |
| 1067 | } else if (isRegExp(o1)) { |
| 1068 | return isRegExp(o2) ? o1.toString() == o2.toString() : false; |
| 1069 | } else { |
| 1070 | if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || |
| 1071 | isArray(o2) || isDate(o2) || isRegExp(o2)) return false; |
| 1072 | keySet = createMap(); |
| 1073 | for (key in o1) { |
| 1074 | if (key.charAt(0) === '$' || isFunction(o1[key])) continue; |
| 1075 | if (!equals(o1[key], o2[key])) return false; |
| 1076 | keySet[key] = true; |
| 1077 | } |
| 1078 | for (key in o2) { |
| 1079 | if (!(key in keySet) && |
| 1080 | key.charAt(0) !== '$' && |
| 1081 | isDefined(o2[key]) && |
| 1082 | !isFunction(o2[key])) return false; |
| 1083 | } |
| 1084 | return true; |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | var csp = function() { |
| 1092 | if (!isDefined(csp.rules)) { |
no test coverage detected