Skip to content

Add support for NaN - #190

Closed
vagos wants to merge 3 commits into
yahoo:mainfrom
vagos:main
Closed

vagos wants to merge 3 commits into
yahoo:mainfrom
vagos:main

Conversation

@vagos

@vagos vagos commented Nov 8, 2024

Copy link
Copy Markdown

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@vagos
vagos force-pushed the main branch 2 times, most recently from f3e379d to 8878890 Compare November 13, 2024 00:48
Comment thread index.js
Comment on lines +87 to +89
if (typeof value === 'number' && isNaN(value)) {
return '@__N-' + UID + '-' + (nans.push(value) - 1) + '__@';
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it might be better to combine this if statement with the number if statement.

if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
}

Signed-off-by: Evangelos Lamprou <vagos@lamprou.xyz>
Comment thread index.js
deleteFunctions(value);
}

if (typeof value === 'number' && isNaN(value)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This test can be simplified to if (Number.isNaN(value)).

Number.isNaN automatically returns false for non-number values.

@redonkulus

Copy link
Copy Markdown
Collaborator

Thanks for this, and sorry for the slow review. The NaN support is good and still missing on main (serialize(NaN) currently gives null). A few things before we can merge:

  1. Please rebase onto main. The branch conflicts in index.js, and main no longer uses randombytes.
  2. Port the tests to node:test. The suite moved from mocha/chai to the built-in runner, so the new tests currently fail with ReferenceError: expect is not defined. Use strictEqual from node:assert like the surrounding tests.
  3. Please drop the Error support from this PR (or fix it in a separate one). As written, new Error({"name":…,"message":…}) passes an object as the message, so it deserializes with message "[object Object]", and subclasses like TypeError come back as plain Error. It also has no tests. If you'd like to tackle Errors separately, it would need to emit something like new Error(<serialized message>), restore name, and include round-trip tests.

With the NaN part on its own and the tests ported, this should be ready to go.

@redonkulus redonkulus closed this Oct 23, 2026
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.

6 participants