MCPcopy Index your code
hub / github.com/caolan/nodeunit / objEquiv

Function objEquiv

examples/browser/nodeunit.js:1317–1358  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

1315}
1316
1317function objEquiv (a, b) {
1318 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
1319 return false;
1320 // an identical "prototype" property.
1321 if (a.prototype !== b.prototype) return false;
1322 //~~~I've managed to break Object.keys through screwy arguments passing.
1323 // Converting to array solves the problem.
1324 if (isArguments(a)) {
1325 if (!isArguments(b)) {
1326 return false;
1327 }
1328 a = pSlice.call(a);
1329 b = pSlice.call(b);
1330 return _deepEqual(a, b);
1331 }
1332 try{
1333 var ka = _keys(a),
1334 kb = _keys(b),
1335 key, i;
1336 } catch (e) {//happens when one is a string literal and the other isn't
1337 return false;
1338 }
1339 // having the same number of owned properties (keys incorporates hasOwnProperty)
1340 if (ka.length != kb.length)
1341 return false;
1342 //the same set of keys (although not necessarily the same order),
1343 ka.sort();
1344 kb.sort();
1345 //~~~cheap key test
1346 for (i = ka.length - 1; i >= 0; i--) {
1347 if (ka[i] != kb[i])
1348 return false;
1349 }
1350 //equivalent values for every corresponding key, and
1351 //~~~possibly expensive deep test
1352 for (i = ka.length - 1; i >= 0; i--) {
1353 key = ka[i];
1354 if (!_deepEqual(a[key], b[key] ))
1355 return false;
1356 }
1357 return true;
1358}
1359
1360// 8. The non-equivalence assertion tests for any deep inequality.
1361// assert.notDeepEqual(actual, expected, message_opt);

Callers 1

_deepEqualFunction · 0.70

Calls 4

isUndefinedOrNullFunction · 0.70
isArgumentsFunction · 0.70
_deepEqualFunction · 0.70
_keysFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…