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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 286 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
287 int start, end; | 287 int start, end; |
288 // We have a fast integer-only case here to avoid a conversion to double in | 288 // We have a fast integer-only case here to avoid a conversion to double in |
289 // the common case where from and to are Smis. | 289 // the common case where from and to are Smis. |
290 if (args[1]->IsSmi() && args[2]->IsSmi()) { | 290 if (args[1]->IsSmi() && args[2]->IsSmi()) { |
291 CONVERT_SMI_ARG_CHECKED(from_number, 1); | 291 CONVERT_SMI_ARG_CHECKED(from_number, 1); |
292 CONVERT_SMI_ARG_CHECKED(to_number, 2); | 292 CONVERT_SMI_ARG_CHECKED(to_number, 2); |
293 start = from_number; | 293 start = from_number; |
294 end = to_number; | 294 end = to_number; |
295 } else { | 295 } else if (args[1]->IsNumber() && args[2]->IsNumber()) { |
296 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); | 296 CONVERT_DOUBLE_ARG_CHECKED(from_number, 1); |
297 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); | 297 CONVERT_DOUBLE_ARG_CHECKED(to_number, 2); |
298 start = FastD2IChecked(from_number); | 298 start = FastD2IChecked(from_number); |
299 end = FastD2IChecked(to_number); | 299 end = FastD2IChecked(to_number); |
| 300 } else { |
| 301 return isolate->ThrowIllegalOperation(); |
300 } | 302 } |
301 // The following condition is intentionally robust because the SubStringStub | 303 // The following condition is intentionally robust because the SubStringStub |
302 // delegates here and we test this in cctest/test-strings/RobustSubStringStub. | 304 // delegates here and we test this in cctest/test-strings/RobustSubStringStub. |
303 if (end < start || start < 0 || end > string->length()) { | 305 if (end < start || start < 0 || end > string->length()) { |
304 return isolate->ThrowIllegalOperation(); | 306 return isolate->ThrowIllegalOperation(); |
305 } | 307 } |
306 isolate->counters()->sub_string_runtime()->Increment(); | 308 isolate->counters()->sub_string_runtime()->Increment(); |
307 | 309 |
308 return *isolate->factory()->NewSubString(string, start, end); | 310 return *isolate->factory()->NewSubString(string, start, end); |
309 } | 311 } |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 SealHandleScope shs(isolate); | 1210 SealHandleScope shs(isolate); |
1209 DCHECK(args.length() == 2); | 1211 DCHECK(args.length() == 2); |
1210 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1212 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
1211 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1213 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
1212 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1214 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
1213 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1215 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
1214 } | 1216 } |
1215 | 1217 |
1216 } // namespace internal | 1218 } // namespace internal |
1217 } // namespace v8 | 1219 } // namespace v8 |
OLD | NEW |