Commit c7ee7e0
fix(string): cleanup code in String.prototype.repeat (#5017)
Overview
This PR refactors the String.prototype.repeat implementation to strictly
align with Section 22.1.3.16 of the ECMA-262 specification. The previous
implementation used a generic error handling match; this update
introduces explicit checks for Infinity and negative values as required
by the abstract operations.
Spec Compliance Audit
I have mapped the implementation to the following specification steps:
Step 3: Let n be ? ToIntegerOrInfinity(count).
Step 4: If n < 0, throw a RangeError exception. (Implemented via
explicit match)
Step 5: If n is +∞, throw a RangeError exception. (Implemented via
PositiveInfinity check)
Changes
Replaced the catch-all error handling with an exhaustive match on the
IntegerOrInfinity enum.
Added specific RangeError messages that distinguish between negative
counts and infinite counts.
Used variable shadowing to simplify the logic flow from an Enum to a
primitive i64 after validation.
Verification
I have verified the fix using a local test script across the following
edge cases:
JavaScript
"abc".repeat(0); // Returns "" (Success)
"abc".repeat(-1); // Throws RangeError: count must be non-negative
(Success)
"abc".repeat(Infinity); // Throws RangeError: count must be less than
infinity (Success)
Note to Maintainers
I am a prospective GSoC 2026 applicant interested in the ECMAScript
Conformance project. I chose this task to demonstrate my ability to
translate ECMA-262 algorithms into idiomatic Rust using Boa's internal
types. I am eager to contribute more to the engine's compliance suite!
---------
Co-authored-by: José Julián Espina <jedel@startmail.com>1 parent 0253916 commit c7ee7e0
2 files changed
+48
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
692 | | - | |
693 | | - | |
694 | 692 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
| 693 | + | |
706 | 694 | | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
716 | 711 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
721 | 727 | | |
722 | 728 | | |
723 | 729 | | |
724 | 730 | | |
725 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
726 | 741 | | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
727 | 745 | | |
728 | 746 | | |
729 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | | - | |
| 145 | + | |
147 | 146 | | |
148 | 147 | | |
149 | 148 | | |
| |||
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
155 | | - | |
156 | | - | |
| 154 | + | |
157 | 155 | | |
158 | 156 | | |
159 | 157 | | |
| |||
0 commit comments