| OLD | NEW |
| 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 // This file relies on the fact that the following declaration has been made | 5 // This file relies on the fact that the following declaration has been made |
| 6 // in runtime.js: | 6 // in runtime.js: |
| 7 // var $String = global.String; | 7 // var $String = global.String; |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 | 704 |
| 705 return %_SubString(s, start_i, end_i); | 705 return %_SubString(s, start_i, end_i); |
| 706 } | 706 } |
| 707 | 707 |
| 708 | 708 |
| 709 // This is not a part of ECMA-262. | 709 // This is not a part of ECMA-262. |
| 710 function StringSubstr(start, n) { | 710 function StringSubstr(start, n) { |
| 711 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); | 711 CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr"); |
| 712 | 712 |
| 713 var s = TO_STRING_INLINE(this); | 713 var s = TO_STRING_INLINE(this); |
| 714 var s_len = s.length; |
| 714 var len; | 715 var len; |
| 715 | 716 |
| 716 // Correct n: If not given, set to string length; if explicitly | 717 // Correct n: If not given, set to string length; if explicitly |
| 717 // set to undefined, zero, or negative, returns empty string. | 718 // set to undefined, zero, or negative, returns empty string. |
| 718 if (IS_UNDEFINED(n)) { | 719 if (IS_UNDEFINED(n)) { |
| 719 len = s.length; | 720 len = s_len; |
| 720 } else { | 721 } else { |
| 721 len = TO_INTEGER(n); | 722 len = TO_INTEGER(n); |
| 722 if (len <= 0) return ''; | 723 if (len <= 0) return ''; |
| 723 } | 724 } |
| 724 | 725 |
| 725 // Correct start: If not given (or undefined), set to zero; otherwise | 726 // Correct start: If not given (or undefined), set to zero; otherwise |
| 726 // convert to integer and handle negative case. | 727 // convert to integer and handle negative case. |
| 727 if (IS_UNDEFINED(start)) { | 728 if (IS_UNDEFINED(start)) { |
| 728 start = 0; | 729 start = 0; |
| 729 } else { | 730 } else { |
| 730 start = TO_INTEGER(start); | 731 start = TO_INTEGER(start); |
| 731 // If positive, and greater than or equal to the string length, | 732 // If positive, and greater than or equal to the string length, |
| 732 // return empty string. | 733 // return empty string. |
| 733 if (start >= s.length) return ''; | 734 if (start >= s_len) return ''; |
| 734 // If negative and absolute value is larger than the string length, | 735 // If negative and absolute value is larger than the string length, |
| 735 // use zero. | 736 // use zero. |
| 736 if (start < 0) { | 737 if (start < 0) { |
| 737 start += s.length; | 738 start += s_len; |
| 738 if (start < 0) start = 0; | 739 if (start < 0) start = 0; |
| 739 } | 740 } |
| 740 } | 741 } |
| 741 | 742 |
| 742 var end = start + len; | 743 var end = start + len; |
| 743 if (end > s.length) end = s.length; | 744 if (end > s_len) end = s_len; |
| 744 | 745 |
| 745 return %_SubString(s, start, end); | 746 return %_SubString(s, start, end); |
| 746 } | 747 } |
| 747 | 748 |
| 748 | 749 |
| 749 // ECMA-262, 15.5.4.16 | 750 // ECMA-262, 15.5.4.16 |
| 750 function StringToLowerCaseJS() { | 751 function StringToLowerCaseJS() { |
| 751 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); | 752 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); |
| 752 | 753 |
| 753 return %StringToLowerCase(TO_STRING_INLINE(this)); | 754 return %StringToLowerCase(TO_STRING_INLINE(this)); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 "fixed", StringFixed, | 955 "fixed", StringFixed, |
| 955 "italics", StringItalics, | 956 "italics", StringItalics, |
| 956 "small", StringSmall, | 957 "small", StringSmall, |
| 957 "strike", StringStrike, | 958 "strike", StringStrike, |
| 958 "sub", StringSub, | 959 "sub", StringSub, |
| 959 "sup", StringSup | 960 "sup", StringSup |
| 960 )); | 961 )); |
| 961 } | 962 } |
| 962 | 963 |
| 963 SetUpString(); | 964 SetUpString(); |
| OLD | NEW |