00001 var getAllKeys = require('./_getAllKeys');
00002
00004 var COMPARE_PARTIAL_FLAG = 1;
00005
00007 var objectProto = Object.prototype;
00008
00010 var hasOwnProperty = objectProto.hasOwnProperty;
00011
00025 function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
00026 var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
00027 objProps = getAllKeys(object),
00028 objLength = objProps.length,
00029 othProps = getAllKeys(other),
00030 othLength = othProps.length;
00031
00032 if (objLength != othLength && !isPartial) {
00033 return false;
00034 }
00035 var index = objLength;
00036 while (index--) {
00037 var key = objProps[index];
00038 if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
00039 return false;
00040 }
00041 }
00042
00043 var stacked = stack.get(object);
00044 if (stacked && stack.get(other)) {
00045 return stacked == other;
00046 }
00047 var result = true;
00048 stack.set(object, other);
00049 stack.set(other, object);
00050
00051 var skipCtor = isPartial;
00052 while (++index < objLength) {
00053 key = objProps[index];
00054 var objValue = object[key],
00055 othValue = other[key];
00056
00057 if (customizer) {
00058 var compared = isPartial
00059 ? customizer(othValue, objValue, key, other, object, stack)
00060 : customizer(objValue, othValue, key, object, other, stack);
00061 }
00062
00063 if (!(compared === undefined
00064 ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
00065 : compared
00066 )) {
00067 result = false;
00068 break;
00069 }
00070 skipCtor || (skipCtor = key == 'constructor');
00071 }
00072 if (result && !skipCtor) {
00073 var objCtor = object.constructor,
00074 othCtor = other.constructor;
00075
00076
00077 if (objCtor != othCtor &&
00078 ('constructor' in object && 'constructor' in other) &&
00079 !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
00080 typeof othCtor == 'function' && othCtor instanceof othCtor)) {
00081 result = false;
00082 }
00083 }
00084 stack['delete'](object);
00085 stack['delete'](other);
00086 return result;
00087 }
00088
00089 module.exports = equalObjects;