* @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)
| 1089 | </example> |
| 1090 | */ |
| 1091 | function equals(o1, o2) { |
| 1092 | if (o1 === o2) return true; |
| 1093 | if (o1 === null || o2 === null) return false; |
| 1094 | // eslint-disable-next-line no-self-compare |
| 1095 | if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN |
| 1096 | var t1 = typeof o1, t2 = typeof o2, length, key, keySet; |
| 1097 | if (t1 === t2 && t1 === 'object') { |
| 1098 | if (isArray(o1)) { |
| 1099 | if (!isArray(o2)) return false; |
| 1100 | if ((length = o1.length) === o2.length) { |
| 1101 | for (key = 0; key < length; key++) { |
| 1102 | if (!equals(o1[key], o2[key])) return false; |
| 1103 | } |
| 1104 | return true; |
| 1105 | } |
| 1106 | } else if (isDate(o1)) { |
| 1107 | if (!isDate(o2)) return false; |
| 1108 | return equals(o1.getTime(), o2.getTime()); |
| 1109 | } else if (isRegExp(o1)) { |
| 1110 | if (!isRegExp(o2)) return false; |
| 1111 | return o1.toString() === o2.toString(); |
| 1112 | } else { |
| 1113 | if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || |
| 1114 | isArray(o2) || isDate(o2) || isRegExp(o2)) return false; |
| 1115 | keySet = createMap(); |
| 1116 | for (key in o1) { |
| 1117 | if (key.charAt(0) === '$' || isFunction(o1[key])) continue; |
| 1118 | if (!equals(o1[key], o2[key])) return false; |
| 1119 | keySet[key] = true; |
| 1120 | } |
| 1121 | for (key in o2) { |
| 1122 | if (!(key in keySet) && |
| 1123 | key.charAt(0) !== '$' && |
| 1124 | isDefined(o2[key]) && |
| 1125 | !isFunction(o2[key])) return false; |
| 1126 | } |
| 1127 | return true; |
| 1128 | } |
| 1129 | } |
| 1130 | return false; |
| 1131 | } |
| 1132 | |
| 1133 | var csp = function() { |
| 1134 | if (!isDefined(csp.rules)) { |
no test coverage detected