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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 parts[i + 1] = TO_STRING_INLINE(part); | 76 parts[i + 1] = TO_STRING_INLINE(part); |
77 } | 77 } |
78 return %StringBuilderConcat(parts, len + 1, ""); | 78 return %StringBuilderConcat(parts, len + 1, ""); |
79 } | 79 } |
80 | 80 |
81 // Match ES3 and Safari | 81 // Match ES3 and Safari |
82 %FunctionSetLength(StringConcat, 1); | 82 %FunctionSetLength(StringConcat, 1); |
83 | 83 |
84 | 84 |
85 // ECMA-262 section 15.5.4.7 | 85 // ECMA-262 section 15.5.4.7 |
86 function StringIndexOf(pattern /* position */) { // length == 1 | 86 function StringIndexOfJS(pattern /* position */) { // length == 1 |
87 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); | 87 CHECK_OBJECT_COERCIBLE(this, "String.prototype.indexOf"); |
88 | 88 |
89 var subject = TO_STRING_INLINE(this); | 89 var subject = TO_STRING_INLINE(this); |
90 pattern = TO_STRING_INLINE(pattern); | 90 pattern = TO_STRING_INLINE(pattern); |
91 var index = 0; | 91 var index = 0; |
92 if (%_ArgumentsLength() > 1) { | 92 if (%_ArgumentsLength() > 1) { |
93 index = %_Arguments(1); // position | 93 index = %_Arguments(1); // position |
94 index = TO_INTEGER(index); | 94 index = TO_INTEGER(index); |
95 if (index < 0) index = 0; | 95 if (index < 0) index = 0; |
96 if (index > subject.length) index = subject.length; | 96 if (index > subject.length) index = subject.length; |
97 } | 97 } |
98 return %StringIndexOf(subject, pattern, index); | 98 return %StringIndexOf(subject, pattern, index); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 // ECMA-262 section 15.5.4.8 | 102 // ECMA-262 section 15.5.4.8 |
103 function StringLastIndexOf(pat /* position */) { // length == 1 | 103 function StringLastIndexOfJS(pat /* position */) { // length == 1 |
104 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); | 104 CHECK_OBJECT_COERCIBLE(this, "String.prototype.lastIndexOf"); |
105 | 105 |
106 var sub = TO_STRING_INLINE(this); | 106 var sub = TO_STRING_INLINE(this); |
107 var subLength = sub.length; | 107 var subLength = sub.length; |
108 var pat = TO_STRING_INLINE(pat); | 108 var pat = TO_STRING_INLINE(pat); |
109 var patLength = pat.length; | 109 var patLength = pat.length; |
110 var index = subLength - patLength; | 110 var index = subLength - patLength; |
111 if (%_ArgumentsLength() > 1) { | 111 if (%_ArgumentsLength() > 1) { |
112 var position = ToNumber(%_Arguments(1)); | 112 var position = ToNumber(%_Arguments(1)); |
113 if (!NUMBER_IS_NAN(position)) { | 113 if (!NUMBER_IS_NAN(position)) { |
(...skipping 10 matching lines...) Expand all Loading... |
124 return -1; | 124 return -1; |
125 } | 125 } |
126 return %StringLastIndexOf(sub, pat, index); | 126 return %StringLastIndexOf(sub, pat, index); |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 // ECMA-262 section 15.5.4.9 | 130 // ECMA-262 section 15.5.4.9 |
131 // | 131 // |
132 // This function is implementation specific. For now, we do not | 132 // This function is implementation specific. For now, we do not |
133 // do anything locale specific. | 133 // do anything locale specific. |
134 function StringLocaleCompare(other) { | 134 function StringLocaleCompareJS(other) { |
135 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); | 135 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); |
136 | 136 |
137 return %StringLocaleCompare(TO_STRING_INLINE(this), | 137 return %StringLocaleCompare(TO_STRING_INLINE(this), |
138 TO_STRING_INLINE(other)); | 138 TO_STRING_INLINE(other)); |
139 } | 139 } |
140 | 140 |
141 | 141 |
142 // ECMA-262 section 15.5.4.10 | 142 // ECMA-262 section 15.5.4.10 |
143 function StringMatch(regexp) { | 143 function StringMatchJS(regexp) { |
144 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 144 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
145 | 145 |
146 var subject = TO_STRING_INLINE(this); | 146 var subject = TO_STRING_INLINE(this); |
147 if (IS_REGEXP(regexp)) { | 147 if (IS_REGEXP(regexp)) { |
148 // Emulate RegExp.prototype.exec's side effect in step 5, even though | 148 // Emulate RegExp.prototype.exec's side effect in step 5, even though |
149 // value is discarded. | 149 // value is discarded. |
150 var lastIndex = regexp.lastIndex; | 150 var lastIndex = regexp.lastIndex; |
151 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); | 151 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); |
152 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); | 152 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); |
153 // lastMatchInfo is defined in regexp.js. | 153 // lastMatchInfo is defined in regexp.js. |
154 var result = %StringMatch(subject, regexp, lastMatchInfo); | 154 var result = %StringMatch(subject, regexp, lastMatchInfo); |
155 if (result !== null) lastMatchInfoOverride = null; | 155 if (result !== null) lastMatchInfoOverride = null; |
156 regexp.lastIndex = 0; | 156 regexp.lastIndex = 0; |
157 return result; | 157 return result; |
158 } | 158 } |
159 // Non-regexp argument. | 159 // Non-regexp argument. |
160 regexp = new $RegExp(regexp); | 160 regexp = new $RegExp(regexp); |
161 return RegExpExecNoTests(regexp, subject, 0); | 161 return RegExpExecNoTests(regexp, subject, 0); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; | 165 var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD']; |
166 | 166 |
167 | 167 |
168 // ECMA-262 v6, section 21.1.3.12 | 168 // ECMA-262 v6, section 21.1.3.12 |
169 // | 169 // |
170 // For now we do nothing, as proper normalization requires big tables. | 170 // For now we do nothing, as proper normalization requires big tables. |
171 // If Intl is enabled, then i18n.js will override it and provide the the | 171 // If Intl is enabled, then i18n.js will override it and provide the the |
172 // proper functionality. | 172 // proper functionality. |
173 function StringNormalize(form) { | 173 function StringNormalizeJS(form) { |
174 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); | 174 CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize"); |
175 | 175 |
176 var form = form ? TO_STRING_INLINE(form) : 'NFC'; | 176 var form = form ? TO_STRING_INLINE(form) : 'NFC'; |
177 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); | 177 var normalizationForm = NORMALIZATION_FORMS.indexOf(form); |
178 if (normalizationForm === -1) { | 178 if (normalizationForm === -1) { |
179 throw new $RangeError('The normalization form should be one of ' | 179 throw new $RangeError('The normalization form should be one of ' |
180 + NORMALIZATION_FORMS.join(', ') + '.'); | 180 + NORMALIZATION_FORMS.join(', ') + '.'); |
181 } | 181 } |
182 | 182 |
183 return %_ValueOf(this); | 183 return %_ValueOf(this); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 578 |
579 if (end_i <= start_i) { | 579 if (end_i <= start_i) { |
580 return ''; | 580 return ''; |
581 } | 581 } |
582 | 582 |
583 return %_SubString(s, start_i, end_i); | 583 return %_SubString(s, start_i, end_i); |
584 } | 584 } |
585 | 585 |
586 | 586 |
587 // ECMA-262 section 15.5.4.14 | 587 // ECMA-262 section 15.5.4.14 |
588 function StringSplit(separator, limit) { | 588 function StringSplitJS(separator, limit) { |
589 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split"); | 589 CHECK_OBJECT_COERCIBLE(this, "String.prototype.split"); |
590 | 590 |
591 var subject = TO_STRING_INLINE(this); | 591 var subject = TO_STRING_INLINE(this); |
592 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); | 592 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); |
593 | 593 |
594 var length = subject.length; | 594 var length = subject.length; |
595 if (!IS_REGEXP(separator)) { | 595 if (!IS_REGEXP(separator)) { |
596 var separator_string = TO_STRING_INLINE(separator); | 596 var separator_string = TO_STRING_INLINE(separator); |
597 | 597 |
598 if (limit === 0) return []; | 598 if (limit === 0) return []; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 } | 749 } |
750 | 750 |
751 var end = start + len; | 751 var end = start + len; |
752 if (end > s.length) end = s.length; | 752 if (end > s.length) end = s.length; |
753 | 753 |
754 return %_SubString(s, start, end); | 754 return %_SubString(s, start, end); |
755 } | 755 } |
756 | 756 |
757 | 757 |
758 // ECMA-262, 15.5.4.16 | 758 // ECMA-262, 15.5.4.16 |
759 function StringToLowerCase() { | 759 function StringToLowerCaseJS() { |
760 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); | 760 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase"); |
761 | 761 |
762 return %StringToLowerCase(TO_STRING_INLINE(this)); | 762 return %StringToLowerCase(TO_STRING_INLINE(this)); |
763 } | 763 } |
764 | 764 |
765 | 765 |
766 // ECMA-262, 15.5.4.17 | 766 // ECMA-262, 15.5.4.17 |
767 function StringToLocaleLowerCase() { | 767 function StringToLocaleLowerCase() { |
768 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); | 768 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase"); |
769 | 769 |
770 return %StringToLowerCase(TO_STRING_INLINE(this)); | 770 return %StringToLowerCase(TO_STRING_INLINE(this)); |
771 } | 771 } |
772 | 772 |
773 | 773 |
774 // ECMA-262, 15.5.4.18 | 774 // ECMA-262, 15.5.4.18 |
775 function StringToUpperCase() { | 775 function StringToUpperCaseJS() { |
776 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); | 776 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase"); |
777 | 777 |
778 return %StringToUpperCase(TO_STRING_INLINE(this)); | 778 return %StringToUpperCase(TO_STRING_INLINE(this)); |
779 } | 779 } |
780 | 780 |
781 | 781 |
782 // ECMA-262, 15.5.4.19 | 782 // ECMA-262, 15.5.4.19 |
783 function StringToLocaleUpperCase() { | 783 function StringToLocaleUpperCase() { |
784 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); | 784 CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase"); |
785 | 785 |
786 return %StringToUpperCase(TO_STRING_INLINE(this)); | 786 return %StringToUpperCase(TO_STRING_INLINE(this)); |
787 } | 787 } |
788 | 788 |
789 // ES5, 15.5.4.20 | 789 // ES5, 15.5.4.20 |
790 function StringTrim() { | 790 function StringTrimJS() { |
791 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim"); | 791 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trim"); |
792 | 792 |
793 return %StringTrim(TO_STRING_INLINE(this), true, true); | 793 return %StringTrim(TO_STRING_INLINE(this), true, true); |
794 } | 794 } |
795 | 795 |
796 function StringTrimLeft() { | 796 function StringTrimLeft() { |
797 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft"); | 797 CHECK_OBJECT_COERCIBLE(this, "String.prototype.trimLeft"); |
798 | 798 |
799 return %StringTrim(TO_STRING_INLINE(this), true, false); | 799 return %StringTrim(TO_STRING_INLINE(this), true, false); |
800 } | 800 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 "fromCharCode", StringFromCharCode | 928 "fromCharCode", StringFromCharCode |
929 )); | 929 )); |
930 | 930 |
931 // Set up the non-enumerable functions on the String prototype object. | 931 // Set up the non-enumerable functions on the String prototype object. |
932 InstallFunctions($String.prototype, DONT_ENUM, $Array( | 932 InstallFunctions($String.prototype, DONT_ENUM, $Array( |
933 "valueOf", StringValueOf, | 933 "valueOf", StringValueOf, |
934 "toString", StringToString, | 934 "toString", StringToString, |
935 "charAt", StringCharAt, | 935 "charAt", StringCharAt, |
936 "charCodeAt", StringCharCodeAt, | 936 "charCodeAt", StringCharCodeAt, |
937 "concat", StringConcat, | 937 "concat", StringConcat, |
938 "indexOf", StringIndexOf, | 938 "indexOf", StringIndexOfJS, |
939 "lastIndexOf", StringLastIndexOf, | 939 "lastIndexOf", StringLastIndexOfJS, |
940 "localeCompare", StringLocaleCompare, | 940 "localeCompare", StringLocaleCompareJS, |
941 "match", StringMatch, | 941 "match", StringMatchJS, |
942 "normalize", StringNormalize, | 942 "normalize", StringNormalizeJS, |
943 "replace", StringReplace, | 943 "replace", StringReplace, |
944 "search", StringSearch, | 944 "search", StringSearch, |
945 "slice", StringSlice, | 945 "slice", StringSlice, |
946 "split", StringSplit, | 946 "split", StringSplitJS, |
947 "substring", StringSubstring, | 947 "substring", StringSubstring, |
948 "substr", StringSubstr, | 948 "substr", StringSubstr, |
949 "toLowerCase", StringToLowerCase, | 949 "toLowerCase", StringToLowerCaseJS, |
950 "toLocaleLowerCase", StringToLocaleLowerCase, | 950 "toLocaleLowerCase", StringToLocaleLowerCase, |
951 "toUpperCase", StringToUpperCase, | 951 "toUpperCase", StringToUpperCaseJS, |
952 "toLocaleUpperCase", StringToLocaleUpperCase, | 952 "toLocaleUpperCase", StringToLocaleUpperCase, |
953 "trim", StringTrim, | 953 "trim", StringTrimJS, |
954 "trimLeft", StringTrimLeft, | 954 "trimLeft", StringTrimLeft, |
955 "trimRight", StringTrimRight, | 955 "trimRight", StringTrimRight, |
956 "link", StringLink, | 956 "link", StringLink, |
957 "anchor", StringAnchor, | 957 "anchor", StringAnchor, |
958 "fontcolor", StringFontcolor, | 958 "fontcolor", StringFontcolor, |
959 "fontsize", StringFontsize, | 959 "fontsize", StringFontsize, |
960 "big", StringBig, | 960 "big", StringBig, |
961 "blink", StringBlink, | 961 "blink", StringBlink, |
962 "bold", StringBold, | 962 "bold", StringBold, |
963 "fixed", StringFixed, | 963 "fixed", StringFixed, |
964 "italics", StringItalics, | 964 "italics", StringItalics, |
965 "small", StringSmall, | 965 "small", StringSmall, |
966 "strike", StringStrike, | 966 "strike", StringStrike, |
967 "sub", StringSub, | 967 "sub", StringSub, |
968 "sup", StringSup | 968 "sup", StringSup |
969 )); | 969 )); |
970 } | 970 } |
971 | 971 |
972 SetUpString(); | 972 SetUpString(); |
OLD | NEW |