(obj1, obj2)
| 24 | |
| 25 | // Utility for deep equality testing of objects |
| 26 | function objectsEqual (obj1, obj2) { |
| 27 | /* jshint eqeqeq: false */ |
| 28 | |
| 29 | // Check for undefined or null |
| 30 | if (isUndefinedOrNull(obj1) || isUndefinedOrNull(obj2)) { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | // Object prototypes must be the same |
| 35 | if (obj1.prototype !== obj2.prototype) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | // Handle argument objects |
| 40 | if (isArgumentsObject(obj1)) { |
| 41 | if (!isArgumentsObject(obj2)) { |
| 42 | return false; |
| 43 | } |
| 44 | obj1 = Array.prototype.slice.call(obj1); |
| 45 | obj2 = Array.prototype.slice.call(obj2); |
| 46 | } |
| 47 | |
| 48 | // Check number of own properties |
| 49 | var obj1Keys = getObjectKeys(obj1); |
| 50 | var obj2Keys = getObjectKeys(obj2); |
| 51 | if (obj1Keys.length !== obj2Keys.length) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | obj1Keys.sort(); |
| 56 | obj2Keys.sort(); |
| 57 | |
| 58 | // Cheap initial key test (see https://github.com/joyent/node/blob/master/lib/assert.js) |
| 59 | var key, i, len = obj1Keys.length; |
| 60 | for (i = 0; i < len; i += 1) { |
| 61 | if (obj1Keys[i] != obj2Keys[i]) { |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Expensive deep test |
| 67 | for (i = 0; i < len; i += 1) { |
| 68 | key = obj1Keys[i]; |
| 69 | if (!isDeepEqual(obj1[key], obj2[key])) { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // If it got this far... |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | // Utility for deep equality testing |
| 79 | function isDeepEqual (actual, expected) { |
no test coverage detected