Commit daf86d3
authored
typedarray: use locale-sensitive separator in %TypedArray%.prototype.toLocaleString (#5089)
## Summary
Update `%TypedArray%.prototype.toLocaleString` to use a locale-sensitive
separator when the `intl` feature is enabled, aligning its behavior with
`Array.prototype.toLocaleString`.
### ref - #5081
Previously, the TypedArray implementation always used the hardcoded
separator `", "`. When the `intl` feature is enabled,
`Array.prototype.toLocaleString` already derives the separator using
ICU's `ListFormatter`. This PR updates the TypedArray implementation to
use the same locale-aware separator logic.
When the `intl` feature is disabled, the implementation correctly falls
back to `", "`.
## Changes
- Use ICU `ListFormatter` via the `intl_provider` to compute a
locale-sensitive separator when the `intl` feature is enabled.
- Fall back to the default separator `", "` when `intl` is disabled.
- Hoist extraction of `locales` and `options` arguments outside the
iteration loop to avoid repeated lookups.
- Remove the unused `utf16` import from the module.
## Specification
This aligns the implementation with:
- **ECMAScript §23.2.3.31**
`%TypedArray%.prototype.toLocaleString`
which specifies that the algorithm should behave the same as:
- **ECMAScript §23.1.3.32**
`Array.prototype.toLocaleString`
except that `TypedArrayLength` is used instead of `LengthOfArrayLike`.
## Verification
The following checks were performed:
- `cargo fmt`
- `cargo clippy`
- `cargo test`
- Test262 tests for TypedArray locale string conversion:
<img width="760" height="184" alt="Screenshot 2026-03-15 at 8 27 06 AM"
src="https://github.com/user-attachments/assets/e75a497e-3fab-44ce-85ae-3c3c33e01149"
/>
All existing tests pass and no regressions were introduced.
## Notes
The behavior now matches the locale-sensitive list separator behavior
used by `Array.prototype.toLocaleString` when `intl` support is enabled.
---------
Signed-off-by: mrhapile <allinonegaming3456@gmail.com>1 parent e4bbd39 commit daf86d3
File tree
2 files changed
+31
-12
lines changed- core/engine/src/builtins
- intl/number_format
- typed_array
2 files changed
+31
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
761 | 761 | | |
762 | 762 | | |
763 | 763 | | |
764 | | - | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
765 | 768 | | |
766 | 769 | | |
767 | 770 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
1211 | 1210 | | |
1212 | 1211 | | |
1213 | 1212 | | |
1214 | | - | |
| 1213 | + | |
1215 | 1214 | | |
1216 | 1215 | | |
1217 | 1216 | | |
| |||
2503 | 2502 | | |
2504 | 2503 | | |
2505 | 2504 | | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
2506 | 2508 | | |
2507 | 2509 | | |
2508 | 2510 | | |
2509 | | - | |
2510 | | - | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
2511 | 2530 | | |
2512 | 2531 | | |
2513 | 2532 | | |
2514 | 2533 | | |
2515 | | - | |
| 2534 | + | |
2516 | 2535 | | |
2517 | 2536 | | |
2518 | 2537 | | |
2519 | | - | |
| 2538 | + | |
2520 | 2539 | | |
2521 | 2540 | | |
2522 | 2541 | | |
2523 | | - | |
| 2542 | + | |
2524 | 2543 | | |
2525 | 2544 | | |
2526 | 2545 | | |
| |||
2531 | 2550 | | |
2532 | 2551 | | |
2533 | 2552 | | |
2534 | | - | |
2535 | | - | |
2536 | | - | |
2537 | | - | |
| 2553 | + | |
2538 | 2554 | | |
2539 | 2555 | | |
2540 | 2556 | | |
| |||
0 commit comments