Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / equalObjects.js
1 var keys = require('../object/keys');
2
3 /** Used for native method references. */
4 var objectProto = Object.prototype;
5
6 /** Used to check objects for own properties. */
7 var hasOwnProperty = objectProto.hasOwnProperty;
8
9 /**
10  * A specialized version of `baseIsEqualDeep` for objects with support for
11  * partial deep comparisons.
12  *
13  * @private
14  * @param {Object} object The object to compare.
15  * @param {Object} other The other object to compare.
16  * @param {Function} equalFunc The function to determine equivalents of values.
17  * @param {Function} [customizer] The function to customize comparing values.
18  * @param {boolean} [isLoose] Specify performing partial comparisons.
19  * @param {Array} [stackA] Tracks traversed `value` objects.
20  * @param {Array} [stackB] Tracks traversed `other` objects.
21  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
22  */
23 function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
24   var objProps = keys(object),
25       objLength = objProps.length,
26       othProps = keys(other),
27       othLength = othProps.length;
28
29   if (objLength != othLength && !isLoose) {
30     return false;
31   }
32   var index = objLength;
33   while (index--) {
34     var key = objProps[index];
35     if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
36       return false;
37     }
38   }
39   var skipCtor = isLoose;
40   while (++index < objLength) {
41     key = objProps[index];
42     var objValue = object[key],
43         othValue = other[key],
44         result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
45
46     // Recursively compare objects (susceptible to call stack limits).
47     if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
48       return false;
49     }
50     skipCtor || (skipCtor = key == 'constructor');
51   }
52   if (!skipCtor) {
53     var objCtor = object.constructor,
54         othCtor = other.constructor;
55
56     // Non `Object` object instances with different constructors are not equal.
57     if (objCtor != othCtor &&
58         ('constructor' in object && 'constructor' in other) &&
59         !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
60           typeof othCtor == 'function' && othCtor instanceof othCtor)) {
61       return false;
62     }
63   }
64   return true;
65 }
66
67 module.exports = equalObjects;