Skip to content

fix(node/assert): deepStrictEqual now correctly handles Number objects#31233

Merged
Tango992 merged 5 commits intodenoland:mainfrom
ish1416:fix-deepStrictEqual-number-objects
Nov 18, 2025
Merged

fix(node/assert): deepStrictEqual now correctly handles Number objects#31233
Tango992 merged 5 commits intodenoland:mainfrom
ish1416:fix-deepStrictEqual-number-objects

Conversation

@ish1416
Copy link
Copy Markdown
Contributor

@ish1416 ish1416 commented Nov 9, 2025

Fixes #31172

Description

The deepStrictEqual function was using asserts.equal() which doesn't properly handle boxed primitives like Number objects. Changed it to use isDeepStrictEqual() from comparisons.ts which correctly handles Number, String, Boolean, BigInt, and Symbol objects.

Changes

  • Modified ext/node/polyfills/assert.ts:

    • Added import for isDeepStrictEqual from ext:deno_node/internal/util/comparisons.ts
    • Updated deepStrictEqual function to use isDeepStrictEqual() instead of asserts.equal()
  • Added test cases in tests/unit_node/assert_test.ts:

    • Test that deepStrictEqual throws AssertionError for different Number objects
    • Test that deepStrictEqual passes for equal Number objects

Testing

Added unit tests to verify:

  • deepStrictEqual throws AssertionError for different Number objects (e.g., new Number(1) vs new Number(2))
  • deepStrictEqual passes for equal Number objects (e.g., new Number(1) vs new Number(1))

Related Issue

#31172 - assert.deepStrictEqual does not throw exception for Number objects

Fixes denoland#31172

The deepStrictEqual function was using asserts.equal() which doesn't
properly handle boxed primitives like Number objects. Changed it to use
isDeepStrictEqual() from comparisons.ts which correctly handles Number,
String, Boolean, BigInt, and Symbol objects.

Added test cases to verify:
- deepStrictEqual throws AssertionError for different Number objects
- deepStrictEqual passes for equal Number objects
@ish1416
Copy link
Copy Markdown
Contributor Author

ish1416 commented Nov 9, 2025

@Tango992 The failures likely indicate a pre-existing issue with how parseArgs creates objects or how the tests compare them.
Since this is a separate issue from the Number objects fix, we should address this in another PR. The fix for Number objects is correct and complete.
The fix for Number objects is correct — isDeepStrictEqual properly handles boxed primitives
The failing parse-args tests appear to be a pre-existing issue, not caused by this change
The change makes deepStrictEqual more Node.js-compatible, which may expose existing test issues.

Can you please review it and merge if possible?

…totypes

Fix hasOwnProperty and propertyIsEnumerable calls to use Object.prototype
methods with .call() to work correctly with objects that have __proto__: null.
This fixes the parse-args test failures that occurred after switching
deepStrictEqual to use isDeepStrictEqual.
@ish1416
Copy link
Copy Markdown
Contributor Author

ish1416 commented Nov 9, 2025

@Tango992 This is fixed now can you review it?

Copy link
Copy Markdown
Contributor

@Tango992 Tango992 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Though I have a minor review:

Comment thread ext/node/polyfills/internal/util/comparisons.ts
@Tango992 Tango992 requested a review from bartlomieju November 17, 2025 10:37
@Tango992 Tango992 enabled auto-merge (squash) November 17, 2025 14:08
@Tango992 Tango992 merged commit ccc9aba into denoland:main Nov 18, 2025
19 checks passed
@ish1416
Copy link
Copy Markdown
Contributor Author

ish1416 commented Nov 18, 2025

Thanks! Though I have a minor review:

Thanks @Tango992

bartlomieju pushed a commit that referenced this pull request Jan 22, 2026
#31233)

Fixes #31172

## Description

The `deepStrictEqual` function was using `asserts.equal()` which doesn't
properly handle boxed primitives like Number objects. Changed it to use
`isDeepStrictEqual()` from `comparisons.ts` which correctly handles
Number, String, Boolean, BigInt, and Symbol objects.

## Changes

- Modified `ext/node/polyfills/assert.ts`:
- Added import for `isDeepStrictEqual` from
`ext:deno_node/internal/util/comparisons.ts`
- Updated `deepStrictEqual` function to use `isDeepStrictEqual()`
instead of `asserts.equal()`

- Added test cases in `tests/unit_node/assert_test.ts`:
- Test that `deepStrictEqual` throws `AssertionError` for different
Number objects
  - Test that `deepStrictEqual` passes for equal Number objects

## Testing

Added unit tests to verify:
- `deepStrictEqual` throws `AssertionError` for different Number objects
(e.g., `new Number(1)` vs `new Number(2)`)
- `deepStrictEqual` passes for equal Number objects (e.g., `new
Number(1)` vs `new Number(1)`)

## Related Issue

#31172 - `assert.deepStrictEqual` does not throw exception for Number
objects

---------

Co-authored-by: Daniel Rahmanto <daniel.rahmanto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert.deepStrictEqual does not throw exception for Number objects

3 participants