Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / _equalObjects.js
1 var keys = require('./keys');
2
3 /** Used to compose bitmasks for comparison styles. */
4 var PARTIAL_COMPARE_FLAG = 2;
5
6 /** Used for built-in method references. */
7 var objectProto = Object.prototype;
8
9 /** Used to check objects for own properties. */
10 var hasOwnProperty = objectProto.hasOwnProperty;
11
12 /**
13  * A specialized version of `baseIsEqualDeep` for objects with support for
14  * partial deep comparisons.
15  *
16  * @private
17  * @param {Object} object The object to compare.
18  * @param {Object} other The other object to compare.
19  * @param {Function} equalFunc The function to determine equivalents of values.
20  * @param {Function} customizer The function to customize comparisons.
21  * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
22  *  for more details.
23  * @param {Object} stack Tracks traversed `object` and `other` objects.
24  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
25  */
26 function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
27   var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
28       objProps = keys(object),
29       objLength = objProps.length,
30       othProps = keys(other),
31       othLength = othProps.length;
32
33   if (objLength != othLength && !isPartial) {
34     return false;
35   }
36   var index = objLength;
37   while (index--) {
38     var key = objProps[index];
39     if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
40       return false;
41     }
42   }
43   // Assume cyclic values are equal.
44   var stacked = stack.get(object);
45   if (stacked && stack.get(other)) {
46     return stacked == other;
47   }
48   var result = true;
49   stack.set(object, other);
50   stack.set(other, object);
51
52   var skipCtor = isPartial;
53   while (++index < objLength) {
54     key = objProps[index];
55     var objValue = object[key],
56         othValue = other[key];
57
58     if (customizer) {
59       var compared = isPartial
60         ? customizer(othValue, objValue, key, other, object, stack)
61         : customizer(objValue, othValue, key, object, other, stack);
62     }
63     // Recursively compare objects (susceptible to call stack limits).
64     if (!(compared === undefined
65           ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
66           : compared
67         )) {
68       result = false;
69       break;
70     }
71     skipCtor || (skipCtor = key == 'constructor');
72   }
73   if (result && !skipCtor) {
74     var objCtor = object.constructor,
75         othCtor = other.constructor;
76
77     // Non `Object` object instances with different constructors are not equal.
78     if (objCtor != othCtor &&
79         ('constructor' in object && 'constructor' in other) &&
80         !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
81           typeof othCtor == 'function' && othCtor instanceof othCtor)) {
82       result = false;
83     }
84   }
85   stack['delete'](object);
86   stack['delete'](other);
87   return result;
88 }
89
90 module.exports = equalObjects;