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