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/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 RegExpResultsCache::Enter( | 1117 RegExpResultsCache::Enter( |
1118 isolate, subject, handle(regexp->data(), isolate), copied_fixed_array, | 1118 isolate, subject, handle(regexp->data(), isolate), copied_fixed_array, |
1119 last_match_cache, RegExpResultsCache::REGEXP_MULTIPLE_INDICES); | 1119 last_match_cache, RegExpResultsCache::REGEXP_MULTIPLE_INDICES); |
1120 } | 1120 } |
1121 return *builder.ToJSArray(result_array); | 1121 return *builder.ToJSArray(result_array); |
1122 } else { | 1122 } else { |
1123 return isolate->heap()->null_value(); // No matches at all. | 1123 return isolate->heap()->null_value(); // No matches at all. |
1124 } | 1124 } |
1125 } | 1125 } |
1126 | 1126 |
1127 MaybeHandle<String> StringReplaceNonGlobalRegExpWithFunction( | 1127 MUST_USE_RESULT MaybeHandle<String> StringReplaceNonGlobalRegExpWithFunction( |
1128 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, | 1128 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, |
1129 Handle<Object> replace_obj) { | 1129 Handle<Object> replace_obj) { |
1130 Factory* factory = isolate->factory(); | 1130 Factory* factory = isolate->factory(); |
1131 Handle<RegExpMatchInfo> last_match_info = isolate->regexp_last_match_info(); | 1131 Handle<RegExpMatchInfo> last_match_info = isolate->regexp_last_match_info(); |
1132 | 1132 |
1133 // TODO(jgruber): This is a pattern we could refactor. | 1133 // TODO(jgruber): This is a pattern we could refactor. |
1134 Handle<Object> match_indices_obj; | 1134 Handle<Object> match_indices_obj; |
1135 ASSIGN_RETURN_ON_EXCEPTION( | 1135 ASSIGN_RETURN_ON_EXCEPTION( |
1136 isolate, match_indices_obj, | 1136 isolate, match_indices_obj, |
1137 RegExpImpl::Exec(regexp, subject, 0, last_match_info), String); | 1137 RegExpImpl::Exec(regexp, subject, 0, last_match_info), String); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 | 1186 |
1187 builder.AppendString(replacement); | 1187 builder.AppendString(replacement); |
1188 builder.AppendString( | 1188 builder.AppendString( |
1189 factory->NewSubString(subject, end_of_match, subject->length())); | 1189 factory->NewSubString(subject, end_of_match, subject->length())); |
1190 | 1190 |
1191 return builder.Finish(); | 1191 return builder.Finish(); |
1192 } | 1192 } |
1193 | 1193 |
1194 // Legacy implementation of RegExp.prototype[Symbol.replace] which | 1194 // Legacy implementation of RegExp.prototype[Symbol.replace] which |
1195 // doesn't properly call the underlying exec method. | 1195 // doesn't properly call the underlying exec method. |
1196 MaybeHandle<String> RegExpReplace(Isolate* isolate, Handle<JSRegExp> regexp, | 1196 MUST_USE_RESULT MaybeHandle<String> RegExpReplace(Isolate* isolate, |
1197 Handle<String> string, | 1197 Handle<JSRegExp> regexp, |
1198 Handle<Object> replace_obj) { | 1198 Handle<String> string, |
| 1199 Handle<Object> replace_obj) { |
1199 Factory* factory = isolate->factory(); | 1200 Factory* factory = isolate->factory(); |
1200 | 1201 |
1201 // TODO(jgruber): We need the even stricter guarantee of an unmodified | 1202 // TODO(jgruber): We need the even stricter guarantee of an unmodified |
1202 // JSRegExp map here for access to GetFlags to be legal. | 1203 // JSRegExp map here for access to GetFlags to be legal. |
1203 const int flags = regexp->GetFlags(); | 1204 const int flags = regexp->GetFlags(); |
1204 const bool global = (flags & JSRegExp::kGlobal) != 0; | 1205 const bool global = (flags & JSRegExp::kGlobal) != 0; |
1205 | 1206 |
1206 // Functional fast-paths are dispatched directly by replace builtin. | 1207 // Functional fast-paths are dispatched directly by replace builtin. |
1207 DCHECK(!replace_obj->IsCallable()); | 1208 DCHECK(!replace_obj->IsCallable()); |
1208 | 1209 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 | 1500 |
1500 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1501 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
1501 SealHandleScope shs(isolate); | 1502 SealHandleScope shs(isolate); |
1502 DCHECK(args.length() == 1); | 1503 DCHECK(args.length() == 1); |
1503 CONVERT_ARG_CHECKED(Object, obj, 0); | 1504 CONVERT_ARG_CHECKED(Object, obj, 0); |
1504 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1505 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
1505 } | 1506 } |
1506 | 1507 |
1507 } // namespace internal | 1508 } // namespace internal |
1508 } // namespace v8 | 1509 } // namespace v8 |
OLD | NEW |