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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 subject = String::Flatten(subject); | 79 subject = String::Flatten(subject); |
80 if (StringReplaceOneCharWithString(isolate, subject, search, replace, &found, | 80 if (StringReplaceOneCharWithString(isolate, subject, search, replace, &found, |
81 kRecursionLimit).ToHandle(&result)) { | 81 kRecursionLimit).ToHandle(&result)) { |
82 return *result; | 82 return *result; |
83 } | 83 } |
84 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 84 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
85 // In case of empty handle and no pending exception we have stack overflow. | 85 // In case of empty handle and no pending exception we have stack overflow. |
86 return isolate->StackOverflow(); | 86 return isolate->StackOverflow(); |
87 } | 87 } |
88 | 88 |
89 | 89 // ES6 #sec-string.prototype.indexof |
| 90 // String.prototype.indexOf(searchString [, position]) |
90 RUNTIME_FUNCTION(Runtime_StringIndexOf) { | 91 RUNTIME_FUNCTION(Runtime_StringIndexOf) { |
91 HandleScope scope(isolate); | 92 HandleScope scope(isolate); |
92 DCHECK(args.length() == 3); | 93 DCHECK(args.length() == 3); |
93 return String::IndexOf(isolate, args.at<Object>(0), args.at<Object>(1), | 94 return String::IndexOf(isolate, args.at(0), args.at(1), args.at(2)); |
94 args.at<Object>(2)); | 95 } |
| 96 |
| 97 // ES6 #sec-string.prototype.indexof |
| 98 // String.prototype.indexOf(searchString, position) |
| 99 // Fast version that assumes that does not perform conversions of the incoming |
| 100 // arguments. |
| 101 RUNTIME_FUNCTION(Runtime_StringIndexOfUnchecked) { |
| 102 HandleScope scope(isolate); |
| 103 DCHECK(args.length() == 3); |
| 104 Handle<String> receiver_string = args.at<String>(0); |
| 105 Handle<String> search_string = args.at<String>(1); |
| 106 int index = std::min(std::max(args.smi_at(2), 0), receiver_string->length()); |
| 107 |
| 108 return Smi::FromInt(String::IndexOf(isolate, receiver_string, search_string, |
| 109 static_cast<uint32_t>(index))); |
95 } | 110 } |
96 | 111 |
97 RUNTIME_FUNCTION(Runtime_StringLastIndexOf) { | 112 RUNTIME_FUNCTION(Runtime_StringLastIndexOf) { |
98 HandleScope handle_scope(isolate); | 113 HandleScope handle_scope(isolate); |
99 return String::LastIndexOf(isolate, args.at<Object>(0), args.at<Object>(1), | 114 return String::LastIndexOf(isolate, args.at(0), args.at(1), |
100 isolate->factory()->undefined_value()); | 115 isolate->factory()->undefined_value()); |
101 } | 116 } |
102 | 117 |
103 RUNTIME_FUNCTION(Runtime_SubString) { | 118 RUNTIME_FUNCTION(Runtime_SubString) { |
104 HandleScope scope(isolate); | 119 HandleScope scope(isolate); |
105 DCHECK(args.length() == 3); | 120 DCHECK(args.length() == 3); |
106 | 121 |
107 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 122 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
108 int start, end; | 123 int start, end; |
109 // We have a fast integer-only case here to avoid a conversion to double in | 124 // We have a fast integer-only case here to avoid a conversion to double in |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 SealHandleScope shs(isolate); | 999 SealHandleScope shs(isolate); |
985 DCHECK(args.length() == 2); | 1000 DCHECK(args.length() == 2); |
986 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1001 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
987 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1002 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
988 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1003 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
989 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1004 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
990 } | 1005 } |
991 | 1006 |
992 } // namespace internal | 1007 } // namespace internal |
993 } // namespace v8 | 1008 } // namespace v8 |
OLD | NEW |