| 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 25 matching lines...) Expand all Loading... |
| 36 Handle<String> new_second; | 36 Handle<String> new_second; |
| 37 if (!StringReplaceOneCharWithString(isolate, second, search, replace, found, | 37 if (!StringReplaceOneCharWithString(isolate, second, search, replace, found, |
| 38 recursion_limit) | 38 recursion_limit) |
| 39 .ToHandle(&new_second)) { | 39 .ToHandle(&new_second)) { |
| 40 return MaybeHandle<String>(); | 40 return MaybeHandle<String>(); |
| 41 } | 41 } |
| 42 if (*found) return isolate->factory()->NewConsString(first, new_second); | 42 if (*found) return isolate->factory()->NewConsString(first, new_second); |
| 43 | 43 |
| 44 return subject; | 44 return subject; |
| 45 } else { | 45 } else { |
| 46 int index = String::IndexOf(isolate, subject, search, 0); | 46 Object* index = String::IndexOf(isolate, subject, search, |
| 47 if (index == -1) return subject; | 47 isolate->factory()->undefined_value()); |
| 48 int index_int = -1; |
| 49 index->ToInt32(&index_int); |
| 50 |
| 51 if (index_int == -1) return subject; |
| 48 *found = true; | 52 *found = true; |
| 49 Handle<String> first = isolate->factory()->NewSubString(subject, 0, index); | 53 Handle<String> first = |
| 54 isolate->factory()->NewSubString(subject, 0, index_int); |
| 50 Handle<String> cons1; | 55 Handle<String> cons1; |
| 51 ASSIGN_RETURN_ON_EXCEPTION( | 56 ASSIGN_RETURN_ON_EXCEPTION( |
| 52 isolate, cons1, isolate->factory()->NewConsString(first, replace), | 57 isolate, cons1, isolate->factory()->NewConsString(first, replace), |
| 53 String); | 58 String); |
| 54 Handle<String> second = | 59 Handle<String> second = isolate->factory()->NewSubString( |
| 55 isolate->factory()->NewSubString(subject, index + 1, subject->length()); | 60 subject, index_int + 1, subject->length()); |
| 56 return isolate->factory()->NewConsString(cons1, second); | 61 return isolate->factory()->NewConsString(cons1, second); |
| 57 } | 62 } |
| 58 } | 63 } |
| 59 | 64 |
| 60 | 65 |
| 61 RUNTIME_FUNCTION(Runtime_StringReplaceOneCharWithString) { | 66 RUNTIME_FUNCTION(Runtime_StringReplaceOneCharWithString) { |
| 62 HandleScope scope(isolate); | 67 HandleScope scope(isolate); |
| 63 DCHECK(args.length() == 3); | 68 DCHECK(args.length() == 3); |
| 64 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 69 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 65 CONVERT_ARG_HANDLE_CHECKED(String, search, 1); | 70 CONVERT_ARG_HANDLE_CHECKED(String, search, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 } | 88 } |
| 84 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 89 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
| 85 // In case of empty handle and no pending exception we have stack overflow. | 90 // In case of empty handle and no pending exception we have stack overflow. |
| 86 return isolate->StackOverflow(); | 91 return isolate->StackOverflow(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 | 94 |
| 90 RUNTIME_FUNCTION(Runtime_StringIndexOf) { | 95 RUNTIME_FUNCTION(Runtime_StringIndexOf) { |
| 91 HandleScope scope(isolate); | 96 HandleScope scope(isolate); |
| 92 DCHECK(args.length() == 3); | 97 DCHECK(args.length() == 3); |
| 93 | 98 return String::IndexOf(isolate, args.at<Object>(0), args.at<Object>(1), |
| 94 CONVERT_ARG_HANDLE_CHECKED(String, sub, 0); | 99 args.at<Object>(2)); |
| 95 CONVERT_ARG_HANDLE_CHECKED(String, pat, 1); | |
| 96 CONVERT_ARG_HANDLE_CHECKED(Object, index, 2); | |
| 97 | |
| 98 uint32_t start_index = 0; | |
| 99 if (!index->ToArrayIndex(&start_index)) return Smi::FromInt(-1); | |
| 100 | |
| 101 CHECK(start_index <= static_cast<uint32_t>(sub->length())); | |
| 102 int position = String::IndexOf(isolate, sub, pat, start_index); | |
| 103 return Smi::FromInt(position); | |
| 104 } | 100 } |
| 105 | 101 |
| 106 RUNTIME_FUNCTION(Runtime_StringLastIndexOf) { | 102 RUNTIME_FUNCTION(Runtime_StringLastIndexOf) { |
| 107 HandleScope handle_scope(isolate); | 103 HandleScope handle_scope(isolate); |
| 108 return String::LastIndexOf(isolate, args.at<Object>(0), args.at<Object>(1), | 104 return String::LastIndexOf(isolate, args.at<Object>(0), args.at<Object>(1), |
| 109 isolate->factory()->undefined_value()); | 105 isolate->factory()->undefined_value()); |
| 110 } | 106 } |
| 111 | 107 |
| 112 RUNTIME_FUNCTION(Runtime_SubString) { | 108 RUNTIME_FUNCTION(Runtime_SubString) { |
| 113 HandleScope scope(isolate); | 109 HandleScope scope(isolate); |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 SealHandleScope shs(isolate); | 1042 SealHandleScope shs(isolate); |
| 1047 DCHECK(args.length() == 2); | 1043 DCHECK(args.length() == 2); |
| 1048 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1044 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
| 1049 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1045 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
| 1050 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1046 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
| 1051 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1047 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
| 1052 } | 1048 } |
| 1053 | 1049 |
| 1054 } // namespace internal | 1050 } // namespace internal |
| 1055 } // namespace v8 | 1051 } // namespace v8 |
| OLD | NEW |