OLD | NEW |
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 Loading... |
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 Loading... |
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 }); |
OLD | NEW |