MCPcopy Index your code
hub / github.com/nodejs/node / deepEquals

Function deepEquals

deps/v8/test/intl/assert.js:63–96  ·  view source on GitHub ↗

* Compares two JavaScript values for type and value equality. * It checks internals of arrays and objects.

(a, b)

Source from the content-addressed store, hash-verified

61 * It checks internals of arrays and objects.
62 */
63function deepEquals(a, b) {
64 if (a === b) {
65 // Check for -0.
66 if (a === 0) return (1 / a) === (1 / b);
67 return true;
68 }
69 if (typeof a != typeof b) return false;
70 if (typeof a == 'number') return isNaN(a) && isNaN(b);
71 if (typeof a !== 'object' && typeof a !== 'function') return false;
72 // Neither a nor b is primitive.
73 var objectClass = classOf(a);
74 if (objectClass !== classOf(b)) return false;
75 if (objectClass === 'RegExp') {
76 // For RegExp, just compare pattern and flags using its toString.
77 return (a.toString() === b.toString());
78 }
79 // Functions are only identical to themselves.
80 if (objectClass === 'Function') return false;
81 if (objectClass === 'Array') {
82 var elementCount = 0;
83 if (a.length != b.length) {
84 return false;
85 }
86 for (var i = 0; i < a.length; i++) {
87 if (!deepEquals(a[i], b[i])) return false;
88 }
89 return true;
90 }
91 if (objectClass == 'String' || objectClass == 'Number' ||
92 objectClass == 'Boolean' || objectClass == 'Date') {
93 if (a.valueOf() !== b.valueOf()) return false;
94 }
95 return deepObjectEquals(a, b);
96}
97
98/**
99 * Throws an exception containing the user_message (if any) and the values.

Callers 2

deepObjectEqualsFunction · 0.70
assertEqualsFunction · 0.70

Calls 3

classOfFunction · 0.70
deepObjectEqualsFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…