Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/runtime/runtime-regexp.cc

Issue 2006673002: Reduce boilerplace for common pattern to return MaybeHandle. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase and fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (global_cache.HasException()) return isolate->heap()->exception(); 537 if (global_cache.HasException()) return isolate->heap()->exception();
538 538
539 if (prev < subject_length) { 539 if (prev < subject_length) {
540 builder.EnsureCapacity(2); 540 builder.EnsureCapacity(2);
541 builder.AddSubjectSlice(prev, subject_length); 541 builder.AddSubjectSlice(prev, subject_length);
542 } 542 }
543 543
544 RegExpImpl::SetLastMatchInfo(last_match_info, subject, capture_count, 544 RegExpImpl::SetLastMatchInfo(last_match_info, subject, capture_count,
545 global_cache.LastSuccessfulMatch()); 545 global_cache.LastSuccessfulMatch());
546 546
547 Handle<String> result; 547 RETURN_RESULT_OR_FAILURE(isolate, builder.ToString());
548 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, builder.ToString());
549 return *result;
550 } 548 }
551 549
552 550
553 template <typename ResultSeqString> 551 template <typename ResultSeqString>
554 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString( 552 MUST_USE_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString(
555 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp, 553 Isolate* isolate, Handle<String> subject, Handle<JSRegExp> regexp,
556 Handle<JSArray> last_match_info) { 554 Handle<JSArray> last_match_info) {
557 DCHECK(subject->IsFlat()); 555 DCHECK(subject->IsFlat());
558 556
559 // Shortcut for simple non-regexp global replacements 557 // Shortcut for simple non-regexp global replacements
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 DCHECK(args.length() == 4); 770 DCHECK(args.length() == 4);
773 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); 771 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0);
774 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); 772 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1);
775 CONVERT_INT32_ARG_CHECKED(index, 2); 773 CONVERT_INT32_ARG_CHECKED(index, 2);
776 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); 774 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3);
777 // Due to the way the JS calls are constructed this must be less than the 775 // Due to the way the JS calls are constructed this must be less than the
778 // length of a string, i.e. it is always a Smi. We check anyway for security. 776 // length of a string, i.e. it is always a Smi. We check anyway for security.
779 RUNTIME_ASSERT(index >= 0); 777 RUNTIME_ASSERT(index >= 0);
780 RUNTIME_ASSERT(index <= subject->length()); 778 RUNTIME_ASSERT(index <= subject->length());
781 isolate->counters()->regexp_entry_runtime()->Increment(); 779 isolate->counters()->regexp_entry_runtime()->Increment();
782 Handle<Object> result; 780 RETURN_RESULT_OR_FAILURE(
783 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 781 isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info));
784 isolate, result,
785 RegExpImpl::Exec(regexp, subject, index, last_match_info));
786 return *result;
787 } 782 }
788 783
789 784
790 RUNTIME_FUNCTION(Runtime_RegExpFlags) { 785 RUNTIME_FUNCTION(Runtime_RegExpFlags) {
791 SealHandleScope shs(isolate); 786 SealHandleScope shs(isolate);
792 DCHECK(args.length() == 1); 787 DCHECK(args.length() == 1);
793 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); 788 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0);
794 return regexp->flags(); 789 return regexp->flags();
795 } 790 }
796 791
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1016
1022 1017
1023 RUNTIME_FUNCTION(Runtime_IsRegExp) { 1018 RUNTIME_FUNCTION(Runtime_IsRegExp) {
1024 SealHandleScope shs(isolate); 1019 SealHandleScope shs(isolate);
1025 DCHECK(args.length() == 1); 1020 DCHECK(args.length() == 1);
1026 CONVERT_ARG_CHECKED(Object, obj, 0); 1021 CONVERT_ARG_CHECKED(Object, obj, 0);
1027 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1022 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1028 } 1023 }
1029 } // namespace internal 1024 } // namespace internal
1030 } // namespace v8 1025 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-proxy.cc ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698