Skip to content

feat(intl): implement Number.prototype.toLocaleString with Intl support#5078

Merged
jedel1043 merged 1 commit intoboa-dev:mainfrom
alienx5499:feat/5074-number-tolocalestring
Mar 16, 2026
Merged

feat(intl): implement Number.prototype.toLocaleString with Intl support#5078
jedel1043 merged 1 commit intoboa-dev:mainfrom
alienx5499:feat/5074-number-tolocalestring

Conversation

@alienx5499
Copy link
Contributor

This Pull Request fixes/closes #5074.

It changes the following:

  • Implement Number.prototype.toLocaleString([locales [, options]]) using Intl.NumberFormat when the intl feature is enabled, following the same pattern as BigInt.prototype.toLocaleString.
  • Return "NaN", "Infinity", and "-Infinity" for non-finite values instead of going through Decimal::try_from_f64.
  • Keep the existing fallback behaviour (simple number string conversion) when the intl feature is disabled.
  • Add shared tests for 0, 5, -25, NaN, Infinity, -Infinity.
  • Add #[cfg(feature = "intl")] tests for locale formatting (en-US, de-DE) and options (useGrouping, minimumFractionDigits).

Testing:

  • cargo test -p boa_engine --lib -- number::tests::to_locale_string (without intl)
  • cargo test -p boa_engine --features intl_bundled --lib -- number::tests::to_locale_string (with intl)

@alienx5499 alienx5499 requested a review from a team as a code owner March 14, 2026 22:20
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 14, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 14, 2026
@github-actions github-actions bot added C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics labels Mar 14, 2026
@github-actions
Copy link

github-actions bot commented Mar 14, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,070 49,936 -134
Ignored 2,072 2,207 +135
Failed 821 820 -1
Panics 0 0 0
Conformance 94.54% 94.28% -0.25%
Fixed tests (1):
test/intl402/Number/prototype/toLocaleString/throws-same-exceptions-as-NumberFormat.js (previously Failed)

Tested main commit: baaadfeeaf4a64f34e82cbbb9fee3ed4013495c0
Tested PR commit: 5e7c73ebe26721092c75374c1ea7ce3ad6dea416
Compare commits: baaadfe...5e7c73e

@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.35%. Comparing base (6ddc2b4) to head (5e7c73e).
⚠️ Report is 867 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5078       +/-   ##
===========================================
+ Coverage   47.24%   59.35%   +12.11%     
===========================================
  Files         476      563       +87     
  Lines       46892    62678    +15786     
===========================================
+ Hits        22154    37205    +15051     
- Misses      24738    25473      +735     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alienx5499 alienx5499 force-pushed the feat/5074-number-tolocalestring branch from c83a5a6 to 5e7c73e Compare March 16, 2026 07:20
@alienx5499
Copy link
Contributor Author

Hi @jedel1043,

Whenever you have a moment, could you please take a look at this PR? I’d really appreciate your review.

Thanks!

Comment on lines +319 to +321
if !x.is_finite() {
return Ok(JsValue::new(js_string!(x)));
}
Copy link
Member

Choose a reason for hiding this comment

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

Note for the future: there are technically internationalized versions of non-finite f64 values, but supporting this might be blocked by unicode-org/icu4x#862.

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Looks good!

@jedel1043 jedel1043 added this pull request to the merge queue Mar 16, 2026
Merged via the queue into boa-dev:main with commit b1d4ba0 Mar 16, 2026
22 checks passed
@github-actions github-actions bot removed the Waiting On Review Waiting on reviews from the maintainers label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Intl support for Number.prototype.toLocaleString

2 participants