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

Side by Side Diff: src/js/harmony-string-padding.js

Issue 1926773003: [esnext] implement StringPad spec changes from March TC39 meeting (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months 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/harmony/harmony-string-pad-end.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 12 matching lines...) Expand all
23 maxLength = TO_LENGTH(maxLength); 23 maxLength = TO_LENGTH(maxLength);
24 var stringLength = thisString.length; 24 var stringLength = thisString.length;
25 25
26 if (maxLength <= stringLength) return ""; 26 if (maxLength <= stringLength) return "";
27 27
28 if (IS_UNDEFINED(fillString)) { 28 if (IS_UNDEFINED(fillString)) {
29 fillString = " "; 29 fillString = " ";
30 } else { 30 } else {
31 fillString = TO_STRING(fillString); 31 fillString = TO_STRING(fillString);
32 if (fillString === "") { 32 if (fillString === "") {
33 fillString = " "; 33 // If filler is the empty String, return S.
34 return "";
34 } 35 }
35 } 36 }
36 37
37 var fillLength = maxLength - stringLength; 38 var fillLength = maxLength - stringLength;
38 var repetitions = (fillLength / fillString.length) | 0; 39 var repetitions = (fillLength / fillString.length) | 0;
39 var remainingChars = (fillLength - fillString.length * repetitions) | 0; 40 var remainingChars = (fillLength - fillString.length * repetitions) | 0;
40 41
41 var filler = ""; 42 var filler = "";
42 while (true) { 43 while (true) {
43 if (repetitions & 1) filler += fillString; 44 if (repetitions & 1) filler += fillString;
(...skipping 24 matching lines...) Expand all
68 return thisString + StringPad(thisString, maxLength, fillString); 69 return thisString + StringPad(thisString, maxLength, fillString);
69 } 70 }
70 %FunctionSetLength(StringPadEnd, 1); 71 %FunctionSetLength(StringPadEnd, 1);
71 72
72 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [ 73 utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
73 "padStart", StringPadStart, 74 "padStart", StringPadStart,
74 "padEnd", StringPadEnd 75 "padEnd", StringPadEnd
75 ]); 76 ]);
76 77
77 }); 78 });
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/harmony-string-pad-end.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698