Skip to content

String.prototype.repeat throws RangeError for a count the spec allows #1735

Closed

Description

@d01c2

Reproduction

"".repeat(Number.MAX_SAFE_INTEGER);

Expected

The empty String.

V8 (15.6.20):

d8> "".repeat(Number.MAX_SAFE_INTEGER);
""

Actual (QuickJS-ng)

qjs > "".repeat(Number.MAX_SAFE_INTEGER);
RangeError: invalid repeat count

Spec

String.prototype.repeat throws a RangeError only when n < 0 or n = +∞. Here n is 2^53 - 1, so neither test applies.

The receiver is the empty String, so the final step produces n copies of an empty String, which is the empty String. No allocation of that size is required.

JavaScriptCore, SpiderMonkey, GraalJS and V8 all return "".

Versions

  • QuickJS-ng: 0.17.0
  • V8: 15.6.20

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions