Skip to content

fix(wasm): the global isNaN / isFinite coerce their argument - #14619

Merged
TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/wasm-global-isnan-isfinite
Nov 13, 2026
Merged

TheHypnoo merged 2 commits into
PerryTS:mainfrom
raliclo:fix/wasm-global-isnan-isfinite

Conversation

@raliclo

@raliclo raliclo commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On --target web, the global isNaN and isFinite do not apply ToNumber: isNaN("abc") and isNaN(undefined) are false, isFinite("1") is false (Node: true for all three). Expr::IsNaN / Expr::IsFinite — produced only by the global functions — use the is_nan / is_finite bridges, which implement the non-coercing Number.isNaN / Number.isFinite. Listed in #14595.

Changes

  • wasm_runtime.js: global_is_nan / global_is_finite bridges that call the global functions.
  • emit/expr/regex_globals.rs: Expr::IsNaN / Expr::IsFinite call them. is_nan / is_finite keep their non-coercing meaning for IsUndefinedOrBareNan and for Number.isNaN / Number.isFinite (fix(wasm): Number.isNaN / isFinite / isInteger / isSafeInteger on the web target #14615).
  • emit/string_collection.rs: interns the two names.
  • emit/tests.rs: global_is_nan_and_is_finite_coerce_like_node.

Related issue

Refs #14595.

Test plan

Base 46b2339d82 (current main).

old bridges this branch
new test false false false true false / false false false true matches node --experimental-strip-types
cargo test -p perry-codegen-wasm — 47 passed
tests/integration/wasm/run_wasm_tests.sh 28 pass / 4 fail 28 pass / 4 fail, same set (no case uses isNaN / isFinite)

The integration suite ran before the final rebase onto 46b2339d82; the unit tests were re-run after it. Built on macOS (Apple M6), nightly from rust-toolchain.toml, LLVM 23.1.5, Node 26.13.1. rustfmt --check on the touched Rust files.

Checklist

  • I have NOT bumped the workspace version or edited CHANGELOG.md
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

🤖 Generated with Claude Code

https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p

Summary by CodeRabbit

  • Bug Fixes
    • Under the web target, global isNaN and isFinite now coerce inputs like their JavaScript counterparts, so values such as strings and undefined produce the expected results.

`Expr::IsNaN` and `Expr::IsFinite` (the global `isNaN` / `isFinite`, their
only producers) used the `is_nan` / `is_finite` bridges, which implement the
non-coercing `Number.isNaN` / `Number.isFinite`. So on the web target
`isNaN("abc")` and `isNaN(undefined)` were false and `isFinite("1")` was
false. They now call `global_is_nan` / `global_is_finite`, which apply
ToNumber. `is_nan` / `is_finite` keep their meaning for their other users
(`IsUndefinedOrBareNan`, and `Number.isNaN` / `isFinite`).

`global_is_nan_and_is_finite_coerce_like_node` prints the non-coercing answers
(`false false false true false` / `false false false true`) with the old
bridges.

Refs PerryTS#14595.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CUQanVsnitcrmYLAWWPc3p
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

For --target web, global isNaN and isFinite expressions now use dedicated runtime bridges that apply JavaScript’s coercing global functions. A semantics test covers string, undefined, NaN, Infinity, and finite-number inputs.

Changes: WASM global numeric checks

Layer / File(s) Summary
Add coercing runtime bridges
crates/perry-codegen-wasm/src/wasm_runtime.js, crates/perry-codegen-wasm/src/emit/string_collection.rs
The runtime dispatch adds global_is_nan and global_is_finite, and string collection interns both bridge names.
Use bridges for global expressions
crates/perry-codegen-wasm/src/emit/expr/regex_globals.rs, crates/perry-codegen-wasm/src/emit/tests.rs, changelog.d/14619-wasm-global-isnan-isfinite.md
Global isNaN and isFinite expressions call the new bridges. The semantics test checks coercion results, and the changelog records the bridge change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to 72632

With --target web, global isNaN and isFinite now coerce their arguments the way Node does. Number-specific checks keep their existing non-coercing behavior. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the WebAssembly target's global isNaN and isFinite now coerce their arguments. The changeset adds global_is_nan and global_is_finite bridges and routes Expr::IsNaN and…
Description check Passed The description covers the summary of the bug and fix, the changes per file, the related issue, and the test plan. It does not follow the template's structure exactly. It omits the template's checklis…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the WebAssembly target's global isNaN and isFinite now coerce their arguments. The changeset adds global_is_nan and global_is_finite bridges and routes Expr::IsNaN and Expr::IsFinite through them, so the title matches the change. The title follows the fix(wasm): prefix convention.

Full details: Description check

Explanation

The description covers the summary of the bug and fix, the changes per file, the related issue, and the test plan. It does not follow the template's structure exactly. It omits the template's checklist items for cargo build --release and the workspace test command with the exclusions, and it does not list whether a fixture under tests/fixtures/programs/ was added or whether docs/src/ was considered. The Related issue section says 'Refs #14595', which matches the template format. The Summary runs to about three sentences, which exceeds the template's one-or-two-sentence guidance. The description is mostly complete, so it passes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d23f8a6c-55ff-451e-bc7c-45b8b4c3e883
Commits

Reviewing files that changed from the base of the PR and between 46b2339 and e4fd945.

Files selected for processing: 5

  • changelog.d/14619-wasm-global-isnan-isfinite.md
  • crates/perry-codegen-wasm/src/emit/expr/regex_globals.rs
  • crates/perry-codegen-wasm/src/emit/string_collection.rs
  • crates/perry-codegen-wasm/src/emit/tests.rs
  • crates/perry-codegen-wasm/src/wasm_runtime.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@TheHypnoo
TheHypnoo merged commit fb73cb9 into PerryTS:main Nov 13, 2026
98 of 102 checks passed
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.

3 participants