Parents: #473, #493 Related: #480, #777, #780
Problem
String.prototype.repeat appended the receiver once per requested repetition. For an empty receiver every append was a no-op; the generic 32-bit toLen clamp turned "".repeat(Number.MAX_SAFE_INTEGER) into 4,294,967,295 useless loop iterations despite the required result being the empty string.
That clamp was also the wrong abstract operation: repeat requires ToIntegerOrInfinity, so a negative fraction such as -0.5 truncates to negative zero and must return "", not throw. For non-empty strings the repeated ArrayList growth performed multiple allocations and copies before constructing the final StringCell, while count 1 rebuilt immutable content that was already final.
Scope
- Preserve ToString and exact ToIntegerOrInfinity count coercion/error ordering.
- Return immediately for count 0 and for an empty receiver after count validation.
- Retain the existing StringData cell for count 1.
- Enforce the engine string-size ceiling before allocation with checked exact sizing.
- Allocate the canonical result buffer exactly once and fill ordinary strings with logarithmically many doubling copies.
- Stream flat Latin-1 input without a source transcode and canonicalize cross-copy surrogate pairs exactly.
- Preserve lone-surrogate, astral, OOM, heap-limit, and moving-GC behavior.
No-workaround rules
- No arbitrary count clamp, silent truncation, precomputed input result, changed RangeError boundary, host string library, or weakened allocation failure.
- No stacks, queues, jobs, Promise, Worker, or Map/Set iterator changes.
Acceptance
- Empty input is O(1) after required count coercion, including maximum finite counts.
- Count 1 retains the exact StringData cell without transcode or allocation.
- Non-empty output uses checked exact sizing and bounded copy rounds.
- Focused normal/TSan/OOM units, exact-parent String Test262, threadfuzz, and the full unit gate pass without regressions.