Skip to content

assert.deepEqual and assert.deepStrictEqual incorrectly compare Proxied arrays when using ownKeys trap #41714

@itaylor

Description

@itaylor

Version

v17.4.0

Platform

Darwin macbook-pro-5.lan 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64

Subsystem

assert

What steps will reproduce the bug?

assert.deepEqual(new Proxy(['foo'], {}), ['foo']); // works properly
assert.deepEqual(new Proxy(['foo'], { ownKeys: (target) => Reflect.ownKeys(target) }), ['foo']) // throws

assert.deepStrictEqual(new Proxy(['foo'], {}), ['foo']); // works properly
assert.deepStrictEqual(new Proxy(['foo'], { ownKeys: (target) => Reflect.ownKeys(target) }), ['foo']) // throws

In the above, Reflect.ownKeys(target) should be the same as not setting an ownKeys trap, but it isn't. The trap works fine elsewhere

Indeed,

Reflect.ownKeys(['foo'])  // [ '0', 'length' ]
assert.deepEqual(new Proxy(['foo'], { ownKeys: (target) => ['0', 'length'] }), ['foo'])  // throws

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior?

Using a ownKeys trap shouldn't cause comparison errors.

The ownKeys trap seems to be working fine elsewhere. I traced the code to:

const keys1 = getOwnNonIndexProperties(val1, filter);

Where the GetOwnNonIndexProperties function is called. Perhaps it is incorrectly filtering or the filtering is broken for proxies somehow?

What do you see instead?

Comparison errors from assert.deepEquals and assert.deepStrictEquals when the Arrays compared have the same content, but are using Proxies with ownKeys traps.

Additional information

I tried this on node 14, 16, and 17, with the same results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.confirmed-bugIssues with confirmed bugs.utilIssues and PRs related to the built-in util module.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions