fix(string): cleanup code in String.prototype.repeat#5017
fix(string): cleanup code in String.prototype.repeat#5017jedel1043 merged 6 commits intoboa-dev:mainfrom
Conversation
Test262 conformance changes
Broken tests (3):Tested main commit: |
|
Hi @jedel1043 ! I hope you had a great weekend! |
1922eaa to
dc51cdb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5017 +/- ##
===========================================
+ Coverage 47.24% 59.15% +11.90%
===========================================
Files 476 563 +87
Lines 46892 62779 +15887
===========================================
+ Hits 22154 37134 +14980
- Misses 24738 25645 +907 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Head branch was pushed to by a user without write access
|
Hey @jedel1043, I pulled down your web edits, fixed the minor syntax/doc comment error, ran cargo fmt, and pushed it back up. The CI checks are all green and good to go! |
|
yeah that's what I get for trying to fix this through my phone 🤣🤣🤣 |
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!