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

Side by Side 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 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/es6/string-repeat.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 return "<sub>" + TO_STRING(this) + "</sub>"; 836 return "<sub>" + TO_STRING(this) + "</sub>";
837 } 837 }
838 838
839 839
840 // ES6 draft, revision 26 (2014-07-18), section B.2.3.14 840 // ES6 draft, revision 26 (2014-07-18), section B.2.3.14
841 function StringSup() { 841 function StringSup() {
842 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup"); 842 CHECK_OBJECT_COERCIBLE(this, "String.prototype.sup");
843 return "<sup>" + TO_STRING(this) + "</sup>"; 843 return "<sup>" + TO_STRING(this) + "</sup>";
844 } 844 }
845 845
846 // ES6 draft 01-20-14, section 21.1.3.13 846 // ES6, section 21.1.3.13
847 function StringRepeat(count) { 847 function StringRepeat(count) {
848 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat"); 848 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat");
849 849
850 var s = TO_STRING(this); 850 var s = TO_STRING(this);
851 var n = TO_INTEGER(count); 851 var n = TO_INTEGER(count);
852
853 if (n < 0 || n === INFINITY) throw MakeRangeError(kInvalidCountValue);
854
855 // Early return to allow an arbitrarily-large repeat of the empty string.
856 if (s.length === 0) return "";
857
852 // The maximum string length is stored in a smi, so a longer repeat 858 // The maximum string length is stored in a smi, so a longer repeat
853 // must result in a range error. 859 // must result in a range error.
854 if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue); 860 if (n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue);
855 861
856 var r = ""; 862 var r = "";
857 while (true) { 863 while (true) {
858 if (n & 1) r += s; 864 if (n & 1) r += s;
859 n >>= 1; 865 n >>= 1;
860 if (n === 0) return r; 866 if (n === 0) return r;
861 s += s; 867 s += s;
862 } 868 }
863 } 869 }
864 870
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 to.StringLastIndexOf = StringLastIndexOfJS; 1103 to.StringLastIndexOf = StringLastIndexOfJS;
1098 to.StringMatch = StringMatchJS; 1104 to.StringMatch = StringMatchJS;
1099 to.StringReplace = StringReplace; 1105 to.StringReplace = StringReplace;
1100 to.StringSlice = StringSlice; 1106 to.StringSlice = StringSlice;
1101 to.StringSplit = StringSplitJS; 1107 to.StringSplit = StringSplitJS;
1102 to.StringSubstr = StringSubstr; 1108 to.StringSubstr = StringSubstr;
1103 to.StringSubstring = StringSubstring; 1109 to.StringSubstring = StringSubstring;
1104 }); 1110 });
1105 1111
1106 }) 1112 })
OLDNEW
« 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