Security update for Core, with self-updated composer
[yaffs-website] / node_modules / grunt-legacy-util / 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     isHostObject = require('./_isHostObject'),
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` for more details.
35  * @param {Object} [stack] Tracks traversed `object` and `other` objects.
36  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
37  */
38 function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
39   var objIsArr = isArray(object),
40       othIsArr = isArray(other),
41       objTag = arrayTag,
42       othTag = arrayTag;
43
44   if (!objIsArr) {
45     objTag = getTag(object);
46     if (objTag == argsTag) {
47       objTag = objectTag;
48     } else if (objTag != objectTag) {
49       objIsArr = isTypedArray(object);
50     }
51   }
52   if (!othIsArr) {
53     othTag = getTag(other);
54     if (othTag == argsTag) {
55       othTag = objectTag;
56     } else if (othTag != objectTag) {
57       othIsArr = isTypedArray(other);
58     }
59   }
60   var objIsObj = objTag == objectTag && !isHostObject(object),
61       othIsObj = othTag == objectTag && !isHostObject(other),
62       isSameTag = objTag == othTag;
63
64   if (isSameTag && !(objIsArr || objIsObj)) {
65     return equalByTag(object, other, objTag, equalFunc, customizer, bitmask);
66   }
67   var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
68   if (!isPartial) {
69     var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
70         othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
71
72     if (objIsWrapped || othIsWrapped) {
73       return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, bitmask, stack);
74     }
75   }
76   if (!isSameTag) {
77     return false;
78   }
79   stack || (stack = new Stack);
80   return (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, bitmask, stack);
81 }
82
83 module.exports = baseIsEqualDeep;