Skip to content

util.isDeepStrictEqual would be better to return false to compare WeakMap/WeakSet #18227

Closed
@yosuke-furukawa

Description

@yosuke-furukawa
  • Version:
    v9.4.0

  • Platform:
    OSX, Linux, Windows

  • Subsystem:
    N/A

util.isDeepStrictEqual always returns true when WeakMap/WeakSet comparison.

const util = require('util');
const wm1 = new WeakMap();
const wm2 = new WeakMap();
const key = {};
wm1.set(key, 1);
wm2.set(key, 2);
console.log(util.isDeepStrictEqual(wm1, wm2)); // true

this is because WeakMap|WeakSet.prototype.valueOf always returns empty object.
I know WeakMap / WeakSet do not have an API to show the full content, and they depends on GC so those collection comparison is very difficult.

However, this behavior (always return true) seems to be curious for me. I think it would be better to always return false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions