OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/regexp/jsregexp-inl.h" | 8 #include "src/regexp/jsregexp-inl.h" |
9 #include "src/string-builder.h" | 9 #include "src/string-builder.h" |
10 #include "src/string-search.h" | 10 #include "src/string-search.h" |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 while ( | 1114 while ( |
1115 right > left && | 1115 right > left && |
1116 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) { | 1116 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) { |
1117 right--; | 1117 right--; |
1118 } | 1118 } |
1119 } | 1119 } |
1120 | 1120 |
1121 return *isolate->factory()->NewSubString(string, left, right); | 1121 return *isolate->factory()->NewSubString(string, left, right); |
1122 } | 1122 } |
1123 | 1123 |
1124 | |
1125 RUNTIME_FUNCTION(Runtime_TruncateString) { | |
1126 HandleScope scope(isolate); | |
1127 DCHECK(args.length() == 2); | |
1128 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); | |
1129 CONVERT_INT32_ARG_CHECKED(new_length, 1); | |
1130 RUNTIME_ASSERT(new_length >= 0); | |
1131 return *SeqString::Truncate(string, new_length); | |
1132 } | |
1133 | |
1134 | |
1135 RUNTIME_FUNCTION(Runtime_NewString) { | |
1136 HandleScope scope(isolate); | |
1137 DCHECK(args.length() == 2); | |
1138 CONVERT_INT32_ARG_CHECKED(length, 0); | |
1139 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); | |
1140 if (length == 0) return isolate->heap()->empty_string(); | |
1141 if (is_one_byte) { | |
1142 RETURN_RESULT_OR_FAILURE(isolate, | |
1143 isolate->factory()->NewRawOneByteString(length)); | |
1144 } else { | |
1145 RETURN_RESULT_OR_FAILURE(isolate, | |
1146 isolate->factory()->NewRawTwoByteString(length)); | |
1147 } | |
1148 } | |
1149 | |
1150 | |
1151 RUNTIME_FUNCTION(Runtime_StringLessThan) { | 1124 RUNTIME_FUNCTION(Runtime_StringLessThan) { |
1152 HandleScope handle_scope(isolate); | 1125 HandleScope handle_scope(isolate); |
1153 DCHECK_EQ(2, args.length()); | 1126 DCHECK_EQ(2, args.length()); |
1154 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); | 1127 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); |
1155 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); | 1128 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); |
1156 switch (String::Compare(x, y)) { | 1129 switch (String::Compare(x, y)) { |
1157 case ComparisonResult::kLessThan: | 1130 case ComparisonResult::kLessThan: |
1158 return isolate->heap()->true_value(); | 1131 return isolate->heap()->true_value(); |
1159 case ComparisonResult::kEqual: | 1132 case ComparisonResult::kEqual: |
1160 case ComparisonResult::kGreaterThan: | 1133 case ComparisonResult::kGreaterThan: |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 } | 1229 } |
1257 | 1230 |
1258 RUNTIME_FUNCTION(Runtime_ExternalStringGetChar) { | 1231 RUNTIME_FUNCTION(Runtime_ExternalStringGetChar) { |
1259 SealHandleScope shs(isolate); | 1232 SealHandleScope shs(isolate); |
1260 DCHECK_EQ(2, args.length()); | 1233 DCHECK_EQ(2, args.length()); |
1261 CONVERT_ARG_CHECKED(ExternalString, string, 0); | 1234 CONVERT_ARG_CHECKED(ExternalString, string, 0); |
1262 CONVERT_INT32_ARG_CHECKED(index, 1); | 1235 CONVERT_INT32_ARG_CHECKED(index, 1); |
1263 return Smi::FromInt(string->Get(index)); | 1236 return Smi::FromInt(string->Get(index)); |
1264 } | 1237 } |
1265 | 1238 |
1266 RUNTIME_FUNCTION(Runtime_OneByteSeqStringGetChar) { | |
1267 SealHandleScope shs(isolate); | |
1268 DCHECK(args.length() == 2); | |
1269 CONVERT_ARG_CHECKED(SeqOneByteString, string, 0); | |
1270 CONVERT_INT32_ARG_CHECKED(index, 1); | |
1271 return Smi::FromInt(string->SeqOneByteStringGet(index)); | |
1272 } | |
1273 | |
1274 | |
1275 RUNTIME_FUNCTION(Runtime_OneByteSeqStringSetChar) { | |
1276 SealHandleScope shs(isolate); | |
1277 DCHECK(args.length() == 3); | |
1278 CONVERT_INT32_ARG_CHECKED(index, 0); | |
1279 CONVERT_INT32_ARG_CHECKED(value, 1); | |
1280 CONVERT_ARG_CHECKED(SeqOneByteString, string, 2); | |
1281 string->SeqOneByteStringSet(index, value); | |
1282 return string; | |
1283 } | |
1284 | |
1285 | |
1286 RUNTIME_FUNCTION(Runtime_TwoByteSeqStringGetChar) { | |
1287 SealHandleScope shs(isolate); | |
1288 DCHECK(args.length() == 2); | |
1289 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 0); | |
1290 CONVERT_INT32_ARG_CHECKED(index, 1); | |
1291 return Smi::FromInt(string->SeqTwoByteStringGet(index)); | |
1292 } | |
1293 | |
1294 | |
1295 RUNTIME_FUNCTION(Runtime_TwoByteSeqStringSetChar) { | |
1296 SealHandleScope shs(isolate); | |
1297 DCHECK(args.length() == 3); | |
1298 CONVERT_INT32_ARG_CHECKED(index, 0); | |
1299 CONVERT_INT32_ARG_CHECKED(value, 1); | |
1300 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 2); | |
1301 string->SeqTwoByteStringSet(index, value); | |
1302 return string; | |
1303 } | |
1304 | |
1305 | |
1306 RUNTIME_FUNCTION(Runtime_StringCharCodeAt) { | 1239 RUNTIME_FUNCTION(Runtime_StringCharCodeAt) { |
1307 SealHandleScope shs(isolate); | 1240 SealHandleScope shs(isolate); |
1308 DCHECK(args.length() == 2); | 1241 DCHECK(args.length() == 2); |
1309 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1242 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
1310 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1243 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
1311 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1244 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
1312 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1245 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
1313 } | 1246 } |
1314 | 1247 |
1315 } // namespace internal | 1248 } // namespace internal |
1316 } // namespace v8 | 1249 } // namespace v8 |
OLD | NEW |