Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / baseIsEqualDeep.js
1 var equalArrays = require('./equalArrays'),
2     equalByTag = require('./equalByTag'),
3     equalObjects = require('./equalObjects'),
4     isArray = require('../lang/isArray'),
5     isTypedArray = require('../lang/isTypedArray');
6
7 /** `Object#toString` result references. */
8 var argsTag = '[object Arguments]',
9     arrayTag = '[object Array]',
10     objectTag = '[object Object]';
11
12 /** Used for native method references. */
13 var objectProto = Object.prototype;
14
15 /** Used to check objects for own properties. */
16 var hasOwnProperty = objectProto.hasOwnProperty;
17
18 /**
19  * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
20  * of values.
21  */
22 var objToString = objectProto.toString;
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 comparing objects.
34  * @param {boolean} [isLoose] Specify performing partial comparisons.
35  * @param {Array} [stackA=[]] Tracks traversed `value` objects.
36  * @param {Array} [stackB=[]] Tracks traversed `other` objects.
37  * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
38  */
39 function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
40   var objIsArr = isArray(object),
41       othIsArr = isArray(other),
42       objTag = arrayTag,
43       othTag = arrayTag;
44
45   if (!objIsArr) {
46     objTag = objToString.call(object);
47     if (objTag == argsTag) {
48       objTag = objectTag;
49     } else if (objTag != objectTag) {
50       objIsArr = isTypedArray(object);
51     }
52   }
53   if (!othIsArr) {
54     othTag = objToString.call(other);
55     if (othTag == argsTag) {
56       othTag = objectTag;
57     } else if (othTag != objectTag) {
58       othIsArr = isTypedArray(other);
59     }
60   }
61   var objIsObj = objTag == objectTag,
62       othIsObj = othTag == objectTag,
63       isSameTag = objTag == othTag;
64
65   if (isSameTag && !(objIsArr || objIsObj)) {
66     return equalByTag(object, other, objTag);
67   }
68   if (!isLoose) {
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, isLoose, stackA, stackB);
74     }
75   }
76   if (!isSameTag) {
77     return false;
78   }
79   // Assume cyclic values are equal.
80   // For more information on detecting circular references see https://es5.github.io/#JO.
81   stackA || (stackA = []);
82   stackB || (stackB = []);
83
84   var length = stackA.length;
85   while (length--) {
86     if (stackA[length] == object) {
87       return stackB[length] == other;
88     }
89   }
90   // Add `object` and `other` to the stack of traversed objects.
91   stackA.push(object);
92   stackB.push(other);
93
94   var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
95
96   stackA.pop();
97   stackB.pop();
98
99   return result;
100 }
101
102 module.exports = baseIsEqualDeep;