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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 649 |
650 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { | 650 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { |
651 HandleScope scope(isolate); | 651 HandleScope scope(isolate); |
652 DCHECK(args.length() == 4); | 652 DCHECK(args.length() == 4); |
653 | 653 |
654 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 654 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
655 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | 655 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
656 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 656 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
657 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); | 657 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
658 | 658 |
659 RUNTIME_ASSERT(regexp->GetFlags() & JSRegExp::kGlobal); | 659 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); |
660 RUNTIME_ASSERT(last_match_info->HasFastObjectElements()); | 660 CHECK(last_match_info->HasFastObjectElements()); |
661 | 661 |
662 subject = String::Flatten(subject); | 662 subject = String::Flatten(subject); |
663 | 663 |
664 if (replacement->length() == 0) { | 664 if (replacement->length() == 0) { |
665 if (subject->HasOnlyOneByteChars()) { | 665 if (subject->HasOnlyOneByteChars()) { |
666 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( | 666 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( |
667 isolate, subject, regexp, last_match_info); | 667 isolate, subject, regexp, last_match_info); |
668 } else { | 668 } else { |
669 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( | 669 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( |
670 isolate, subject, regexp, last_match_info); | 670 isolate, subject, regexp, last_match_info); |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 replacement = String::Flatten(replacement); | 674 replacement = String::Flatten(replacement); |
675 | 675 |
676 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, | 676 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, |
677 replacement, last_match_info); | 677 replacement, last_match_info); |
678 } | 678 } |
679 | 679 |
680 | 680 |
681 RUNTIME_FUNCTION(Runtime_StringSplit) { | 681 RUNTIME_FUNCTION(Runtime_StringSplit) { |
682 HandleScope handle_scope(isolate); | 682 HandleScope handle_scope(isolate); |
683 DCHECK(args.length() == 3); | 683 DCHECK(args.length() == 3); |
684 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 684 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
685 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); | 685 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); |
686 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); | 686 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); |
687 RUNTIME_ASSERT(limit > 0); | 687 CHECK(limit > 0); |
688 | 688 |
689 int subject_length = subject->length(); | 689 int subject_length = subject->length(); |
690 int pattern_length = pattern->length(); | 690 int pattern_length = pattern->length(); |
691 RUNTIME_ASSERT(pattern_length > 0); | 691 CHECK(pattern_length > 0); |
692 | 692 |
693 if (limit == 0xffffffffu) { | 693 if (limit == 0xffffffffu) { |
694 FixedArray* last_match_cache_unused; | 694 FixedArray* last_match_cache_unused; |
695 Handle<Object> cached_answer( | 695 Handle<Object> cached_answer( |
696 RegExpResultsCache::Lookup(isolate->heap(), *subject, *pattern, | 696 RegExpResultsCache::Lookup(isolate->heap(), *subject, *pattern, |
697 &last_match_cache_unused, | 697 &last_match_cache_unused, |
698 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS), | 698 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS), |
699 isolate); | 699 isolate); |
700 if (*cached_answer != Smi::FromInt(0)) { | 700 if (*cached_answer != Smi::FromInt(0)) { |
701 // The cache FixedArray is a COW-array and can therefore be reused. | 701 // The cache FixedArray is a COW-array and can therefore be reused. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 767 |
768 RUNTIME_FUNCTION(Runtime_RegExpExec) { | 768 RUNTIME_FUNCTION(Runtime_RegExpExec) { |
769 HandleScope scope(isolate); | 769 HandleScope scope(isolate); |
770 DCHECK(args.length() == 4); | 770 DCHECK(args.length() == 4); |
771 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 771 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
772 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 772 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
773 CONVERT_INT32_ARG_CHECKED(index, 2); | 773 CONVERT_INT32_ARG_CHECKED(index, 2); |
774 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); | 774 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 3); |
775 // 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 |
776 // 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. |
777 RUNTIME_ASSERT(index >= 0); | 777 CHECK(index >= 0); |
778 RUNTIME_ASSERT(index <= subject->length()); | 778 CHECK(index <= subject->length()); |
779 isolate->counters()->regexp_entry_runtime()->Increment(); | 779 isolate->counters()->regexp_entry_runtime()->Increment(); |
780 RETURN_RESULT_OR_FAILURE( | 780 RETURN_RESULT_OR_FAILURE( |
781 isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info)); | 781 isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info)); |
782 } | 782 } |
783 | 783 |
784 | 784 |
785 RUNTIME_FUNCTION(Runtime_RegExpFlags) { | 785 RUNTIME_FUNCTION(Runtime_RegExpFlags) { |
786 SealHandleScope shs(isolate); | 786 SealHandleScope shs(isolate); |
787 DCHECK(args.length() == 1); | 787 DCHECK(args.length() == 1); |
788 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); | 788 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); |
789 return regexp->flags(); | 789 return regexp->flags(); |
790 } | 790 } |
791 | 791 |
792 | 792 |
793 RUNTIME_FUNCTION(Runtime_RegExpSource) { | 793 RUNTIME_FUNCTION(Runtime_RegExpSource) { |
794 SealHandleScope shs(isolate); | 794 SealHandleScope shs(isolate); |
795 DCHECK(args.length() == 1); | 795 DCHECK(args.length() == 1); |
796 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); | 796 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); |
797 return regexp->source(); | 797 return regexp->source(); |
798 } | 798 } |
799 | 799 |
800 | 800 |
801 RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { | 801 RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { |
802 HandleScope handle_scope(isolate); | 802 HandleScope handle_scope(isolate); |
803 DCHECK(args.length() == 3); | 803 DCHECK(args.length() == 3); |
804 CONVERT_SMI_ARG_CHECKED(size, 0); | 804 CONVERT_SMI_ARG_CHECKED(size, 0); |
805 RUNTIME_ASSERT(size >= 0 && size <= FixedArray::kMaxLength); | 805 CHECK(size >= 0 && size <= FixedArray::kMaxLength); |
806 CONVERT_ARG_HANDLE_CHECKED(Object, index, 1); | 806 CONVERT_ARG_HANDLE_CHECKED(Object, index, 1); |
807 CONVERT_ARG_HANDLE_CHECKED(Object, input, 2); | 807 CONVERT_ARG_HANDLE_CHECKED(Object, input, 2); |
808 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(size); | 808 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(size); |
809 Handle<Map> regexp_map(isolate->native_context()->regexp_result_map()); | 809 Handle<Map> regexp_map(isolate->native_context()->regexp_result_map()); |
810 Handle<JSObject> object = | 810 Handle<JSObject> object = |
811 isolate->factory()->NewJSObjectFromMap(regexp_map, NOT_TENURED); | 811 isolate->factory()->NewJSObjectFromMap(regexp_map, NOT_TENURED); |
812 Handle<JSArray> array = Handle<JSArray>::cast(object); | 812 Handle<JSArray> array = Handle<JSArray>::cast(object); |
813 array->set_elements(*elements); | 813 array->set_elements(*elements); |
814 array->set_length(Smi::FromInt(size)); | 814 array->set_length(Smi::FromInt(size)); |
815 // Write in-object properties after the length of the array. | 815 // Write in-object properties after the length of the array. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 // lastMatchInfoOverride to maintain the last match info, so we don't need to | 983 // lastMatchInfoOverride to maintain the last match info, so we don't need to |
984 // set any other last match array info. | 984 // set any other last match array info. |
985 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { | 985 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { |
986 HandleScope handles(isolate); | 986 HandleScope handles(isolate); |
987 DCHECK(args.length() == 4); | 987 DCHECK(args.length() == 4); |
988 | 988 |
989 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 989 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
990 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 990 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
991 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); | 991 CONVERT_ARG_HANDLE_CHECKED(JSArray, last_match_info, 2); |
992 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); | 992 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); |
993 RUNTIME_ASSERT(last_match_info->HasFastObjectElements()); | 993 CHECK(last_match_info->HasFastObjectElements()); |
994 RUNTIME_ASSERT(result_array->HasFastObjectElements()); | 994 CHECK(result_array->HasFastObjectElements()); |
995 | 995 |
996 subject = String::Flatten(subject); | 996 subject = String::Flatten(subject); |
997 RUNTIME_ASSERT(regexp->GetFlags() & JSRegExp::kGlobal); | 997 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); |
998 | 998 |
999 if (regexp->CaptureCount() == 0) { | 999 if (regexp->CaptureCount() == 0) { |
1000 return SearchRegExpMultiple<false>(isolate, subject, regexp, | 1000 return SearchRegExpMultiple<false>(isolate, subject, regexp, |
1001 last_match_info, result_array); | 1001 last_match_info, result_array); |
1002 } else { | 1002 } else { |
1003 return SearchRegExpMultiple<true>(isolate, subject, regexp, last_match_info, | 1003 return SearchRegExpMultiple<true>(isolate, subject, regexp, last_match_info, |
1004 result_array); | 1004 result_array); |
1005 } | 1005 } |
1006 } | 1006 } |
1007 | 1007 |
1008 | 1008 |
1009 RUNTIME_FUNCTION(Runtime_RegExpExecReThrow) { | 1009 RUNTIME_FUNCTION(Runtime_RegExpExecReThrow) { |
1010 SealHandleScope shs(isolate); | 1010 SealHandleScope shs(isolate); |
1011 DCHECK(args.length() == 4); | 1011 DCHECK(args.length() == 4); |
1012 Object* exception = isolate->pending_exception(); | 1012 Object* exception = isolate->pending_exception(); |
1013 isolate->clear_pending_exception(); | 1013 isolate->clear_pending_exception(); |
1014 return isolate->ReThrow(exception); | 1014 return isolate->ReThrow(exception); |
1015 } | 1015 } |
1016 | 1016 |
1017 | 1017 |
1018 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1018 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
1019 SealHandleScope shs(isolate); | 1019 SealHandleScope shs(isolate); |
1020 DCHECK(args.length() == 1); | 1020 DCHECK(args.length() == 1); |
1021 CONVERT_ARG_CHECKED(Object, obj, 0); | 1021 CONVERT_ARG_CHECKED(Object, obj, 0); |
1022 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1022 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
1023 } | 1023 } |
1024 } // namespace internal | 1024 } // namespace internal |
1025 } // namespace v8 | 1025 } // namespace v8 |
OLD | NEW |