Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: src/js/string.js

Issue 1454543003: [es6] Allow any valid repeat of empty string in String.prototype.repeat (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/string-repeat.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/string.js
diff --git a/src/js/string.js b/src/js/string.js
index 489ff983f787c25b9800e969c3ba3ba45e317f33..d58a91883e6d30b01158a5ff3a6a15790a6c05af 100644
--- a/src/js/string.js
+++ b/src/js/string.js
@@ -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) {
« no previous file with comments | « no previous file | test/mjsunit/es6/string-repeat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698