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 var $stringCharAt; |
6 var $stringIndexOf; | 6 var $stringIndexOf; |
7 var $stringSubstring; | 7 var $stringSubstring; |
8 | 8 |
9 (function() { | 9 (function() { |
10 | 10 |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 } | 929 } |
930 | 930 |
931 // ES6 draft 01-20-14, section 21.1.3.13 | 931 // ES6 draft 01-20-14, section 21.1.3.13 |
932 function StringRepeat(count) { | 932 function StringRepeat(count) { |
933 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat"); | 933 CHECK_OBJECT_COERCIBLE(this, "String.prototype.repeat"); |
934 | 934 |
935 var s = TO_STRING_INLINE(this); | 935 var s = TO_STRING_INLINE(this); |
936 var n = ToInteger(count); | 936 var n = ToInteger(count); |
937 // The maximum string length is stored in a smi, so a longer repeat | 937 // The maximum string length is stored in a smi, so a longer repeat |
938 // must result in a range error. | 938 // must result in a range error. |
939 if (n < 0 || n > %_MaxSmi()) { | 939 if (n < 0 || n > %_MaxSmi()) throw MakeRangeError(kInvalidCountValue); |
940 throw MakeRangeError("invalid_count_value", []); | |
941 } | |
942 | 940 |
943 var r = ""; | 941 var r = ""; |
944 while (true) { | 942 while (true) { |
945 if (n & 1) r += s; | 943 if (n & 1) r += s; |
946 n >>= 1; | 944 n >>= 1; |
947 if (n === 0) return r; | 945 if (n === 0) return r; |
948 s += s; | 946 s += s; |
949 } | 947 } |
950 } | 948 } |
951 | 949 |
952 | 950 |
953 // ES6 draft 04-05-14, section 21.1.3.18 | 951 // ES6 draft 04-05-14, section 21.1.3.18 |
954 function StringStartsWith(searchString /* position */) { // length == 1 | 952 function StringStartsWith(searchString /* position */) { // length == 1 |
955 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith"); | 953 CHECK_OBJECT_COERCIBLE(this, "String.prototype.startsWith"); |
956 | 954 |
957 var s = TO_STRING_INLINE(this); | 955 var s = TO_STRING_INLINE(this); |
958 | 956 |
959 if (IS_REGEXP(searchString)) { | 957 if (IS_REGEXP(searchString)) { |
960 throw MakeTypeError("first_argument_not_regexp", | 958 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.startsWith"); |
961 ["String.prototype.startsWith"]); | |
962 } | 959 } |
963 | 960 |
964 var ss = TO_STRING_INLINE(searchString); | 961 var ss = TO_STRING_INLINE(searchString); |
965 var pos = 0; | 962 var pos = 0; |
966 if (%_ArgumentsLength() > 1) { | 963 if (%_ArgumentsLength() > 1) { |
967 pos = %_Arguments(1); // position | 964 pos = %_Arguments(1); // position |
968 pos = ToInteger(pos); | 965 pos = ToInteger(pos); |
969 } | 966 } |
970 | 967 |
971 var s_len = s.length; | 968 var s_len = s.length; |
972 var start = $min($max(pos, 0), s_len); | 969 var start = $min($max(pos, 0), s_len); |
973 var ss_len = ss.length; | 970 var ss_len = ss.length; |
974 if (ss_len + start > s_len) { | 971 if (ss_len + start > s_len) { |
975 return false; | 972 return false; |
976 } | 973 } |
977 | 974 |
978 return %StringIndexOf(s, ss, start) === start; | 975 return %StringIndexOf(s, ss, start) === start; |
979 } | 976 } |
980 | 977 |
981 | 978 |
982 // ES6 draft 04-05-14, section 21.1.3.7 | 979 // ES6 draft 04-05-14, section 21.1.3.7 |
983 function StringEndsWith(searchString /* position */) { // length == 1 | 980 function StringEndsWith(searchString /* position */) { // length == 1 |
984 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); | 981 CHECK_OBJECT_COERCIBLE(this, "String.prototype.endsWith"); |
985 | 982 |
986 var s = TO_STRING_INLINE(this); | 983 var s = TO_STRING_INLINE(this); |
987 | 984 |
988 if (IS_REGEXP(searchString)) { | 985 if (IS_REGEXP(searchString)) { |
989 throw MakeTypeError("first_argument_not_regexp", | 986 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.endsWith"); |
990 ["String.prototype.endsWith"]); | |
991 } | 987 } |
992 | 988 |
993 var ss = TO_STRING_INLINE(searchString); | 989 var ss = TO_STRING_INLINE(searchString); |
994 var s_len = s.length; | 990 var s_len = s.length; |
995 var pos = s_len; | 991 var pos = s_len; |
996 if (%_ArgumentsLength() > 1) { | 992 if (%_ArgumentsLength() > 1) { |
997 var arg = %_Arguments(1); // position | 993 var arg = %_Arguments(1); // position |
998 if (!IS_UNDEFINED(arg)) { | 994 if (!IS_UNDEFINED(arg)) { |
999 pos = ToInteger(arg); | 995 pos = ToInteger(arg); |
1000 } | 996 } |
(...skipping 10 matching lines...) Expand all Loading... |
1011 } | 1007 } |
1012 | 1008 |
1013 | 1009 |
1014 // ES6 draft 04-05-14, section 21.1.3.6 | 1010 // ES6 draft 04-05-14, section 21.1.3.6 |
1015 function StringIncludes(searchString /* position */) { // length == 1 | 1011 function StringIncludes(searchString /* position */) { // length == 1 |
1016 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); | 1012 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); |
1017 | 1013 |
1018 var s = TO_STRING_INLINE(this); | 1014 var s = TO_STRING_INLINE(this); |
1019 | 1015 |
1020 if (IS_REGEXP(searchString)) { | 1016 if (IS_REGEXP(searchString)) { |
1021 throw MakeTypeError("first_argument_not_regexp", | 1017 throw MakeTypeError(kFirstArgumentNotRegExp, "String.prototype.includes"); |
1022 ["String.prototype.includes"]); | |
1023 } | 1018 } |
1024 | 1019 |
1025 var ss = TO_STRING_INLINE(searchString); | 1020 var ss = TO_STRING_INLINE(searchString); |
1026 var pos = 0; | 1021 var pos = 0; |
1027 if (%_ArgumentsLength() > 1) { | 1022 if (%_ArgumentsLength() > 1) { |
1028 pos = %_Arguments(1); // position | 1023 pos = %_Arguments(1); // position |
1029 pos = ToInteger(pos); | 1024 pos = ToInteger(pos); |
1030 } | 1025 } |
1031 | 1026 |
1032 var s_len = s.length; | 1027 var s_len = s.length; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 var code; | 1062 var code; |
1068 var length = %_ArgumentsLength(); | 1063 var length = %_ArgumentsLength(); |
1069 var index; | 1064 var index; |
1070 var result = ""; | 1065 var result = ""; |
1071 for (index = 0; index < length; index++) { | 1066 for (index = 0; index < length; index++) { |
1072 code = %_Arguments(index); | 1067 code = %_Arguments(index); |
1073 if (!%_IsSmi(code)) { | 1068 if (!%_IsSmi(code)) { |
1074 code = ToNumber(code); | 1069 code = ToNumber(code); |
1075 } | 1070 } |
1076 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { | 1071 if (code < 0 || code > 0x10FFFF || code !== TO_INTEGER(code)) { |
1077 throw MakeRangeError("invalid_code_point", [code]); | 1072 throw MakeRangeError(kInvalidCodePoint, code); |
1078 } | 1073 } |
1079 if (code <= 0xFFFF) { | 1074 if (code <= 0xFFFF) { |
1080 result += %_StringCharFromCode(code); | 1075 result += %_StringCharFromCode(code); |
1081 } else { | 1076 } else { |
1082 code -= 0x10000; | 1077 code -= 0x10000; |
1083 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); | 1078 result += %_StringCharFromCode((code >>> 10) & 0x3FF | 0xD800); |
1084 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); | 1079 result += %_StringCharFromCode(code & 0x3FF | 0xDC00); |
1085 } | 1080 } |
1086 } | 1081 } |
1087 return result; | 1082 return result; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 "strike", StringStrike, | 1168 "strike", StringStrike, |
1174 "sub", StringSub, | 1169 "sub", StringSub, |
1175 "sup", StringSup | 1170 "sup", StringSup |
1176 ]); | 1171 ]); |
1177 | 1172 |
1178 $stringCharAt = StringCharAtJS; | 1173 $stringCharAt = StringCharAtJS; |
1179 $stringIndexOf = StringIndexOfJS; | 1174 $stringIndexOf = StringIndexOfJS; |
1180 $stringSubstring = StringSubstring; | 1175 $stringSubstring = StringSubstring; |
1181 | 1176 |
1182 })(); | 1177 })(); |
OLD | NEW |