GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert,util: change WeakMap and WeakSet comparison handling · nodejs/node@764b13d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • assert.md
  • lib/internal/util
    • comparisons.js
  • test/parallel
    • test-assert-deep.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/assert.md‎

Copy file name to clipboardExpand all lines: doc/api/assert.md
+2-1Lines changed: 2 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ are also recursively evaluated by the following rules.
636636
* Implementation does not test the [`[[Prototype]]`][prototype-spec] of
637637
objects.
638638
* [`Symbol`][] properties are not compared.
639-
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values.
639+
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values
640+
but only on their instances.
640641
* [`RegExp`][] lastIndex, flags, and source are always compared, even if these
641642
are not enumerable properties.
642643

Collapse file

‎lib/internal/util/comparisons.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const {
4646
isFloat64Array,
4747
isKeyObject,
4848
isCryptoKey,
49+
isWeakMap,
50+
isWeakSet,
4951
} = types;
5052
const {
5153
constants: {
@@ -283,7 +285,10 @@ function innerDeepEqual(val1, val2, strict, memos) {
283285
) {
284286
return false;
285287
}
288+
} else if (isWeakMap(val1) || isWeakSet(val1)) {
289+
return false;
286290
}
291+
287292
return keyCheck(val1, val2, strict, memos, kNoIterator);
288293
}
289294

Collapse file

‎test/parallel/test-assert-deep.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,3 +1304,35 @@ if (common.hasCrypto) {
13041304
}
13051305
})().then(common.mustCall());
13061306
}
1307+
1308+
// Comparing two identical WeakMap instances
1309+
{
1310+
const weakMap = new WeakMap();
1311+
assertDeepAndStrictEqual(weakMap, weakMap);
1312+
}
1313+
1314+
// Comparing two different WeakMap instances
1315+
{
1316+
const weakMap1 = new WeakMap();
1317+
const objA = {};
1318+
weakMap1.set(objA, 'ok');
1319+
1320+
const weakMap2 = new WeakMap();
1321+
const objB = {};
1322+
weakMap2.set(objB, 'ok');
1323+
1324+
assertNotDeepOrStrict(weakMap1, weakMap2);
1325+
}
1326+
1327+
// Comparing two identical WeakSet instances
1328+
{
1329+
const weakSet = new WeakSet();
1330+
assertDeepAndStrictEqual(weakSet, weakSet);
1331+
}
1332+
1333+
// Comparing two different WeakSet instances
1334+
{
1335+
const weakSet1 = new WeakSet();
1336+
const weakSet2 = new WeakSet();
1337+
assertNotDeepOrStrict(weakSet1, weakSet2);
1338+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.