Commit 8e2e69a4 authored by adamk's avatar adamk Committed by Commit bot

[es6] Allow any valid repeat of empty string in String.prototype.repeat

This lets us pass one test262 test (and seems to match what other
implementations do to handle this case).

R=littledan@chromium.org
BUG=v8:4362
LOG=n

Review URL: https://codereview.chromium.org/1454543003

Cr-Commit-Position: refs/heads/master@{#32155}
parent cf7614d5
......@@ -843,15 +843,21 @@ function StringSup() {
return "<sup>" + TO_STRING(this) + "</sup>";
}
// ES6 draft 01-20-14, section 21.1.3.13
// ES6, section 21.1.3.13
function StringRepeat(count) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat");
var s = TO_STRING(this);
var n = TO_INTEGER(count);
if (n < 0 || n === INFINITY) throw MakeRangeError(kInvalidCountValue);
// Early return to allow an arbitrarily-large repeat of the empty string.
if (s.length === 0) return "";
// The maximum string length is stored in a smi, so a longer repeat
// must result in a range error.
if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
if (n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
var r = "";
while (true) {
......
......@@ -65,6 +65,12 @@ assertThrows('"a".repeat(Number.POSITIVE_INFINITY)', RangeError);
assertThrows('"a".repeat(Math.pow(2, 30))', RangeError);
assertThrows('"a".repeat(Math.pow(2, 40))', RangeError);
// Handling empty strings
assertThrows('"".repeat(-1)', RangeError);
assertThrows('"".repeat(Number.POSITIVE_INFINITY)', RangeError);
assertEquals("", "".repeat(Math.pow(2, 30)));
assertEquals("", "".repeat(Math.pow(2, 40)));
var myobj = {
toString: function() {
return "abc";
......
......@@ -368,9 +368,6 @@
# https://code.google.com/p/v8/issues/detail?id=4361
'intl402/Collator/10.1.1_a': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=4362
'built-ins/String/prototype/repeat/empty-string-returns-empty': [PASS, FAIL],
# https://code.google.com/p/v8/issues/detail?id=4447
'built-ins/Function/prototype/Symbol.hasInstance/*': [SKIP],
'built-ins/Symbol/hasInstance/prop-desc': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment