Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / _baseIsEqualDeep.js
1 var Stack = require('./_Stack'),
2     equalArrays = require('./_equalArrays'),
3     equalByTag = require('./_equalByTag'),
4     equalObjects = require('./_equalObjects'),
5     getTag = require('./_getTag'),
6     isArray = require('./isArray'),
7     isBuffer = require('./isBuffer'),
8     isTypedArray = require('./isTypedArray');
9
10 /** Used to compose bitmasks for comparison styles. */
11 var PARTIAL_COMPARE_FLAG = 2;
12
13 /** `Object#toString` result references. */
14 var argsTag = '[object Arguments]',
15     arrayTag = '[object Array]',
16     objectTag = '[object Object]';
17
18 /** Used for built-in method references. */
19 var objectProto = Object.prototype;
20
21 /** Used to check objects for own properties. */
22 var hasOwnProperty = objectProto.hasOwnProperty;
23
24 /**
25  * A specialized version of `baseIsEqual` for arrays and objects which performs
26  * deep comparisons and tracks traversed objects enabling objects with circular
27  * references to be compared.
28  *
29  * @private
30  * @param {Object} object The object to compare.
31  * @param {Object} other The other object to compare.
32  * @param {Function} equalFunc The function to determine equivalents of values.
33  * @param {Function} [customizer] The function to customize comparisons.
34  * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
35  *  for more details.
36  * @param {Object} [stack] Tracks traversed `object` and `other` objects.
37  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
38  */
39 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
40   var objIsArr = isArray(object),
41       othIsArr = isArray(other),
42       objTag = arrayTag,
43       othTag = arrayTag;
44
45   if (!objIsArr) {
46     objTag = getTag(object);
47     objTag = objTag == argsTag ? objectTag : objTag;
48   }
49   if (!othIsArr) {
50     othTag = getTag(other);
51     othTag = othTag == argsTag ? objectTag : othTag;
52   }
53   var objIsObj = objTag == objectTag,
54       othIsObj = othTag == objectTag,
55       isSameTag = objTag == othTag;
56
57   if (isSameTag && isBuffer(object)) {
58     if (!isBuffer(other)) {
59       return false;
60     }
61     objIsArr = true;
62     objIsObj = false;
63   }
64   if (isSameTag && !objIsObj) {
65     stack || (stack = new Stack);
66     return (objIsArr || isTypedArray(object))
67       ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
68       : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
69   }
70   if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
71     var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
72         othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
73
74     if (objIsWrapped || othIsWrapped) {
75       var objUnwrapped = objIsWrapped ? object.value() : object,
76           othUnwrapped = othIsWrapped ? other.value() : other;
77
78       stack || (stack = new Stack);
79       return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
80     }
81   }
82   if (!isSameTag) {
83     return false;
84   }
85   stack || (stack = new Stack);
86   return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
87 }
88
89 module.exports = baseIsEqualDeep;