* Compares two JavaScript values for type and value equality. * It checks internals of arrays and objects.
(a, b)
| 61 | * It checks internals of arrays and objects. |
| 62 | */ |
| 63 | function deepEquals(a, b) { |
| 64 | if (a === b) { |
| 65 | // Check for -0. |
| 66 | if (a === 0) return (1 / a) === (1 / b); |
| 67 | return true; |
| 68 | } |
| 69 | if (typeof a != typeof b) return false; |
| 70 | if (typeof a == 'number') return isNaN(a) && isNaN(b); |
| 71 | if (typeof a !== 'object' && typeof a !== 'function') return false; |
| 72 | // Neither a nor b is primitive. |
| 73 | var objectClass = classOf(a); |
| 74 | if (objectClass !== classOf(b)) return false; |
| 75 | if (objectClass === 'RegExp') { |
| 76 | // For RegExp, just compare pattern and flags using its toString. |
| 77 | return (a.toString() === b.toString()); |
| 78 | } |
| 79 | // Functions are only identical to themselves. |
| 80 | if (objectClass === 'Function') return false; |
| 81 | if (objectClass === 'Array') { |
| 82 | var elementCount = 0; |
| 83 | if (a.length != b.length) { |
| 84 | return false; |
| 85 | } |
| 86 | for (var i = 0; i < a.length; i++) { |
| 87 | if (!deepEquals(a[i], b[i])) return false; |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | if (objectClass == 'String' || objectClass == 'Number' || |
| 92 | objectClass == 'Boolean' || objectClass == 'Date') { |
| 93 | if (a.valueOf() !== b.valueOf()) return false; |
| 94 | } |
| 95 | return deepObjectEquals(a, b); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Throws an exception containing the user_message (if any) and the values. |
no test coverage detected
searching dependent graphs…