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 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 right > left && | 1117 right > left && |
1118 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) { | 1118 unicode_cache->IsWhiteSpaceOrLineTerminator(string->Get(right - 1))) { |
1119 right--; | 1119 right--; |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 return *isolate->factory()->NewSubString(string, left, right); | 1123 return *isolate->factory()->NewSubString(string, left, right); |
1124 } | 1124 } |
1125 | 1125 |
1126 | 1126 |
1127 RUNTIME_FUNCTION(Runtime_TruncateString) { | |
1128 HandleScope scope(isolate); | |
1129 DCHECK(args.length() == 2); | |
1130 CONVERT_ARG_HANDLE_CHECKED(SeqString, string, 0); | |
1131 CONVERT_INT32_ARG_CHECKED(new_length, 1); | |
1132 RUNTIME_ASSERT(new_length >= 0); | |
1133 return *SeqString::Truncate(string, new_length); | |
1134 } | |
1135 | |
1136 | |
1137 RUNTIME_FUNCTION(Runtime_NewString) { | |
1138 HandleScope scope(isolate); | |
1139 DCHECK(args.length() == 2); | |
1140 CONVERT_INT32_ARG_CHECKED(length, 0); | |
1141 CONVERT_BOOLEAN_ARG_CHECKED(is_one_byte, 1); | |
1142 if (length == 0) return isolate->heap()->empty_string(); | |
1143 Handle<String> result; | |
1144 if (is_one_byte) { | |
1145 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1146 isolate, result, isolate->factory()->NewRawOneByteString(length)); | |
1147 } else { | |
1148 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1149 isolate, result, isolate->factory()->NewRawTwoByteString(length)); | |
1150 } | |
1151 return *result; | |
1152 } | |
1153 | |
1154 | |
1155 RUNTIME_FUNCTION(Runtime_StringLessThan) { | 1127 RUNTIME_FUNCTION(Runtime_StringLessThan) { |
1156 HandleScope handle_scope(isolate); | 1128 HandleScope handle_scope(isolate); |
1157 DCHECK_EQ(2, args.length()); | 1129 DCHECK_EQ(2, args.length()); |
1158 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); | 1130 CONVERT_ARG_HANDLE_CHECKED(String, x, 0); |
1159 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); | 1131 CONVERT_ARG_HANDLE_CHECKED(String, y, 1); |
1160 switch (String::Compare(x, y)) { | 1132 switch (String::Compare(x, y)) { |
1161 case ComparisonResult::kLessThan: | 1133 case ComparisonResult::kLessThan: |
1162 return isolate->heap()->true_value(); | 1134 return isolate->heap()->true_value(); |
1163 case ComparisonResult::kEqual: | 1135 case ComparisonResult::kEqual: |
1164 case ComparisonResult::kGreaterThan: | 1136 case ComparisonResult::kGreaterThan: |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 } | 1244 } |
1273 | 1245 |
1274 RUNTIME_FUNCTION(Runtime_ExternalStringGetChar) { | 1246 RUNTIME_FUNCTION(Runtime_ExternalStringGetChar) { |
1275 SealHandleScope shs(isolate); | 1247 SealHandleScope shs(isolate); |
1276 DCHECK_EQ(2, args.length()); | 1248 DCHECK_EQ(2, args.length()); |
1277 CONVERT_ARG_CHECKED(ExternalString, string, 0); | 1249 CONVERT_ARG_CHECKED(ExternalString, string, 0); |
1278 CONVERT_INT32_ARG_CHECKED(index, 1); | 1250 CONVERT_INT32_ARG_CHECKED(index, 1); |
1279 return Smi::FromInt(string->Get(index)); | 1251 return Smi::FromInt(string->Get(index)); |
1280 } | 1252 } |
1281 | 1253 |
1282 RUNTIME_FUNCTION(Runtime_OneByteSeqStringGetChar) { | |
1283 SealHandleScope shs(isolate); | |
1284 DCHECK(args.length() == 2); | |
1285 CONVERT_ARG_CHECKED(SeqOneByteString, string, 0); | |
1286 CONVERT_INT32_ARG_CHECKED(index, 1); | |
1287 return Smi::FromInt(string->SeqOneByteStringGet(index)); | |
1288 } | |
1289 | |
1290 | |
1291 RUNTIME_FUNCTION(Runtime_OneByteSeqStringSetChar) { | |
1292 SealHandleScope shs(isolate); | |
1293 DCHECK(args.length() == 3); | |
1294 CONVERT_INT32_ARG_CHECKED(index, 0); | |
1295 CONVERT_INT32_ARG_CHECKED(value, 1); | |
1296 CONVERT_ARG_CHECKED(SeqOneByteString, string, 2); | |
1297 string->SeqOneByteStringSet(index, value); | |
1298 return string; | |
1299 } | |
1300 | |
1301 | |
1302 RUNTIME_FUNCTION(Runtime_TwoByteSeqStringGetChar) { | |
1303 SealHandleScope shs(isolate); | |
1304 DCHECK(args.length() == 2); | |
1305 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 0); | |
1306 CONVERT_INT32_ARG_CHECKED(index, 1); | |
1307 return Smi::FromInt(string->SeqTwoByteStringGet(index)); | |
1308 } | |
1309 | |
1310 | |
1311 RUNTIME_FUNCTION(Runtime_TwoByteSeqStringSetChar) { | |
1312 SealHandleScope shs(isolate); | |
1313 DCHECK(args.length() == 3); | |
1314 CONVERT_INT32_ARG_CHECKED(index, 0); | |
1315 CONVERT_INT32_ARG_CHECKED(value, 1); | |
1316 CONVERT_ARG_CHECKED(SeqTwoByteString, string, 2); | |
1317 string->SeqTwoByteStringSet(index, value); | |
1318 return string; | |
1319 } | |
1320 | |
1321 | |
1322 RUNTIME_FUNCTION(Runtime_StringCharCodeAt) { | 1254 RUNTIME_FUNCTION(Runtime_StringCharCodeAt) { |
1323 SealHandleScope shs(isolate); | 1255 SealHandleScope shs(isolate); |
1324 DCHECK(args.length() == 2); | 1256 DCHECK(args.length() == 2); |
1325 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1257 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
1326 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1258 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
1327 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1259 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
1328 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1260 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
1329 } | 1261 } |
1330 | 1262 |
1331 } // namespace internal | 1263 } // namespace internal |
1332 } // namespace v8 | 1264 } // namespace v8 |
OLD | NEW |