| 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 var $stringCharAt; | 5 (function(global, utils) { |
| 6 var $stringIndexOf; | |
| 7 var $stringSubstring; | |
| 8 | |
| 9 (function(global, shared, exports) { | |
| 10 | 6 |
| 11 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 12 | 8 |
| 13 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 14 // Imports | 10 // Imports |
| 15 | 11 |
| 16 var GlobalRegExp = global.RegExp; | 12 var GlobalRegExp = global.RegExp; |
| 17 var GlobalString = global.String; | 13 var GlobalString = global.String; |
| 18 var InternalArray = shared.InternalArray; | 14 var InternalArray = utils.InternalArray; |
| 19 var InternalPackedArray = shared.InternalPackedArray; | 15 var InternalPackedArray = utils.InternalPackedArray; |
| 16 |
| 17 var MathMax; |
| 18 var MathMin; |
| 19 |
| 20 utils.Import(function(from) { |
| 21 MathMax = from.MathMax; |
| 22 MathMin = from.MathMin; |
| 23 }); |
| 20 | 24 |
| 21 //------------------------------------------------------------------- | 25 //------------------------------------------------------------------- |
| 22 | 26 |
| 23 function StringConstructor(x) { | 27 function StringConstructor(x) { |
| 24 if (%_ArgumentsLength() == 0) x = ''; | 28 if (%_ArgumentsLength() == 0) x = ''; |
| 25 if (%_IsConstructCall()) { | 29 if (%_IsConstructCall()) { |
| 26 %_SetValueOf(this, TO_STRING_INLINE(x)); | 30 %_SetValueOf(this, TO_STRING_INLINE(x)); |
| 27 } else { | 31 } else { |
| 28 return IS_SYMBOL(x) ? | 32 return IS_SYMBOL(x) ? |
| 29 %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x); | 33 %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x); |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 } | 965 } |
| 962 | 966 |
| 963 var ss = TO_STRING_INLINE(searchString); | 967 var ss = TO_STRING_INLINE(searchString); |
| 964 var pos = 0; | 968 var pos = 0; |
| 965 if (%_ArgumentsLength() > 1) { | 969 if (%_ArgumentsLength() > 1) { |
| 966 pos = %_Arguments(1); // position | 970 pos = %_Arguments(1); // position |
| 967 pos = $toInteger(pos); | 971 pos = $toInteger(pos); |
| 968 } | 972 } |
| 969 | 973 |
| 970 var s_len = s.length; | 974 var s_len = s.length; |
| 971 var start = $min($max(pos, 0), s_len); | 975 var start = MathMin(MathMax(pos, 0), s_len); |
| 972 var ss_len = ss.length; | 976 var ss_len = ss.length; |
| 973 if (ss_len + start > s_len) { | 977 if (ss_len + start > s_len) { |
| 974 return false; | 978 return false; |
| 975 } | 979 } |
| 976 | 980 |
| 977 return %StringIndexOf(s, ss, start) === start; | 981 return %StringIndexOf(s, ss, start) === start; |
| 978 } | 982 } |
| 979 | 983 |
| 980 | 984 |
| 981 // ES6 draft 04-05-14, section 21.1.3.7 | 985 // ES6 draft 04-05-14, section 21.1.3.7 |
| 982 function StringEndsWith(searchString /* position */) { // length == 1 | 986 function StringEndsWith(searchString /* position */) { // length == 1 |
| 983 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); | 987 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); |
| 984 | 988 |
| 985 var s = TO_STRING_INLINE(this); | 989 var s = TO_STRING_INLINE(this); |
| 986 | 990 |
| 987 if (IS_REGEXP(searchString)) { | 991 if (IS_REGEXP(searchString)) { |
| 988 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); | 992 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); |
| 989 } | 993 } |
| 990 | 994 |
| 991 var ss = TO_STRING_INLINE(searchString); | 995 var ss = TO_STRING_INLINE(searchString); |
| 992 var s_len = s.length; | 996 var s_len = s.length; |
| 993 var pos = s_len; | 997 var pos = s_len; |
| 994 if (%_ArgumentsLength() > 1) { | 998 if (%_ArgumentsLength() > 1) { |
| 995 var arg = %_Arguments(1); // position | 999 var arg = %_Arguments(1); // position |
| 996 if (!IS_UNDEFINED(arg)) { | 1000 if (!IS_UNDEFINED(arg)) { |
| 997 pos = $toInteger(arg); | 1001 pos = $toInteger(arg); |
| 998 } | 1002 } |
| 999 } | 1003 } |
| 1000 | 1004 |
| 1001 var end = $min($max(pos, 0), s_len); | 1005 var end = MathMin(MathMax(pos, 0), s_len); |
| 1002 var ss_len = ss.length; | 1006 var ss_len = ss.length; |
| 1003 var start = end - ss_len; | 1007 var start = end - ss_len; |
| 1004 if (start < 0) { | 1008 if (start < 0) { |
| 1005 return false; | 1009 return false; |
| 1006 } | 1010 } |
| 1007 | 1011 |
| 1008 return %StringLastIndexOf(s, ss, start) === start; | 1012 return %StringLastIndexOf(s, ss, start) === start; |
| 1009 } | 1013 } |
| 1010 | 1014 |
| 1011 | 1015 |
| 1012 // ES6 draft 04-05-14, section 21.1.3.6 | 1016 // ES6 draft 04-05-14, section 21.1.3.6 |
| 1013 function StringIncludes(searchString /* position */) { // length == 1 | 1017 function StringIncludes(searchString /* position */) { // length == 1 |
| 1014 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); | 1018 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
| 1015 | 1019 |
| 1016 var s = TO_STRING_INLINE(this); | 1020 var s = TO_STRING_INLINE(this); |
| 1017 | 1021 |
| 1018 if (IS_REGEXP(searchString)) { | 1022 if (IS_REGEXP(searchString)) { |
| 1019 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); | 1023 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); |
| 1020 } | 1024 } |
| 1021 | 1025 |
| 1022 var ss = TO_STRING_INLINE(searchString); | 1026 var ss = TO_STRING_INLINE(searchString); |
| 1023 var pos = 0; | 1027 var pos = 0; |
| 1024 if (%_ArgumentsLength() > 1) { | 1028 if (%_ArgumentsLength() > 1) { |
| 1025 pos = %_Arguments(1); // position | 1029 pos = %_Arguments(1); // position |
| 1026 pos = $toInteger(pos); | 1030 pos = $toInteger(pos); |
| 1027 } | 1031 } |
| 1028 | 1032 |
| 1029 var s_len = s.length; | 1033 var s_len = s.length; |
| 1030 var start = $min($max(pos, 0), s_len); | 1034 var start = MathMin(MathMax(pos, 0), s_len); |
| 1031 var ss_len = ss.length; | 1035 var ss_len = ss.length; |
| 1032 if (ss_len + start > s_len) { | 1036 if (ss_len + start > s_len) { |
| 1033 return false; | 1037 return false; |
| 1034 } | 1038 } |
| 1035 | 1039 |
| 1036 return %StringIndexOf(s, ss, start) !== -1; | 1040 return %StringIndexOf(s, ss, start) !== -1; |
| 1037 } | 1041 } |
| 1038 | 1042 |
| 1039 | 1043 |
| 1040 // ES6 Draft 05-22-2014, section 21.1.3.3 | 1044 // ES6 Draft 05-22-2014, section 21.1.3.3 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 "blink", StringBlink, | 1169 "blink", StringBlink, |
| 1166 "bold", StringBold, | 1170 "bold", StringBold, |
| 1167 "fixed", StringFixed, | 1171 "fixed", StringFixed, |
| 1168 "italics", StringItalics, | 1172 "italics", StringItalics, |
| 1169 "small", StringSmall, | 1173 "small", StringSmall, |
| 1170 "strike", StringStrike, | 1174 "strike", StringStrike, |
| 1171 "sub", StringSub, | 1175 "sub", StringSub, |
| 1172 "sup", StringSup | 1176 "sup", StringSup |
| 1173 ]); | 1177 ]); |
| 1174 | 1178 |
| 1175 $stringCharAt = StringCharAtJS; | 1179 // ------------------------------------------------------------------- |
| 1176 $stringIndexOf = StringIndexOfJS; | 1180 // Exports |
| 1177 $stringSubstring = StringSubstring; | 1181 |
| 1182 utils.Export(function(to) { |
| 1183 to.StringCharAt = StringCharAtJS; |
| 1184 to.StringIndexOf = StringIndexOfJS; |
| 1185 to.StringSubstring = StringSubstring; |
| 1186 }); |
| 1178 | 1187 |
| 1179 }) | 1188 }) |
| OLD | NEW |