1 var getAllKeys = require('./_getAllKeys');
3 /** Used to compose bitmasks for value comparisons. */
4 var COMPARE_PARTIAL_FLAG = 1;
6 /** Used for built-in method references. */
7 var objectProto = Object.prototype;
9 /** Used to check objects for own properties. */
10 var hasOwnProperty = objectProto.hasOwnProperty;
13 * A specialized version of `baseIsEqualDeep` for objects with support for
14 * partial deep comparisons.
17 * @param {Object} object The object to compare.
18 * @param {Object} other The other object to compare.
19 * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
20 * @param {Function} customizer The function to customize comparisons.
21 * @param {Function} equalFunc The function to determine equivalents of values.
22 * @param {Object} stack Tracks traversed `object` and `other` objects.
23 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
25 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
26 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
27 objProps = getAllKeys(object),
28 objLength = objProps.length,
29 othProps = getAllKeys(other),
30 othLength = othProps.length;
32 if (objLength != othLength && !isPartial) {
35 var index = objLength;
37 var key = objProps[index];
38 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
42 // Assume cyclic values are equal.
43 var stacked = stack.get(object);
44 if (stacked && stack.get(other)) {
45 return stacked == other;
48 stack.set(object, other);
49 stack.set(other, object);
51 var skipCtor = isPartial;
52 while (++index < objLength) {
53 key = objProps[index];
54 var objValue = object[key],
55 othValue = other[key];
58 var compared = isPartial
59 ? customizer(othValue, objValue, key, other, object, stack)
60 : customizer(objValue, othValue, key, object, other, stack);
62 // Recursively compare objects (susceptible to call stack limits).
63 if (!(compared === undefined
64 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
70 skipCtor || (skipCtor = key == 'constructor');
72 if (result && !skipCtor) {
73 var objCtor = object.constructor,
74 othCtor = other.constructor;
76 // Non `Object` object instances with different constructors are not equal.
77 if (objCtor != othCtor &&
78 ('constructor' in object && 'constructor' in other) &&
79 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
80 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
84 stack['delete'](object);
85 stack['delete'](other);
89 module.exports = equalObjects;