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

Function keyCheck

lib/internal/util/comparisons.js:470–521  ·  view source on GitHub ↗
(val1, val2, mode, memos, iterationType, keys2)

Source from the content-addressed store, hash-verified

468}
469
470function keyCheck(val1, val2, mode, memos, iterationType, keys2) {
471 // For all remaining Object pairs, including Array, objects and Maps,
472 // equivalence is determined by having:
473 // a) The same number of owned enumerable properties
474 // b) The same set of keys/indexes (although not necessarily the same order)
475 // c) Equivalent values for every corresponding key/index
476 // d) For Sets and Maps, equal contents
477 // Note: this accounts for both named and indexed properties on Arrays.
478 const isArrayLikeObject = keys2 !== undefined;
479
480 if (keys2 === undefined) {
481 keys2 = ObjectKeys(val2);
482 }
483 let keys1;
484
485 if (!isArrayLikeObject) {
486 // The pair must have the same number of owned properties.
487 if (mode === kPartial) {
488 if (!partialSymbolEquiv(val1, val2, keys2)) {
489 return false;
490 }
491 } else if (keys2.length !== (keys1 = ObjectKeys(val1)).length) {
492 return false;
493 } else if (mode === kStrict || mode === kStrictWithoutPrototypes) {
494 for (const key of getOwnSymbols(val1)) {
495 if (hasEnumerable(val1, key)) {
496 ArrayPrototypePush(keys1, key);
497 }
498 }
499 for (const key of getOwnSymbols(val2)) {
500 if (hasEnumerable(val2, key)) {
501 ArrayPrototypePush(keys2, key);
502 }
503 }
504 if (keys1.length !== keys2.length) {
505 return false;
506 }
507 }
508 }
509
510 if (keys2.length === 0 &&
511 (iterationType === kNoIterator ||
512 (iterationType === kIsArray && val2.length === 0) ||
513 val2.size === 0)) {
514 return true;
515 }
516
517 if (memos === null) {
518 return objEquiv(val1, val2, mode, keys1, keys2, memos, iterationType);
519 }
520 return handleCycles(val1, val2, mode, keys1, keys2, memos, iterationType);
521}
522
523function handleCycles(val1, val2, mode, keys1, keys2, memos, iterationType) {
524 // Use memos to handle cycles.

Callers 1

objectComparisonStartFunction · 0.85

Calls 3

partialSymbolEquivFunction · 0.85
objEquivFunction · 0.85
handleCyclesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…