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 // needed. | 649 // needed. |
650 // TODO(hpayer): We should shrink the large object page if the size | 650 // TODO(hpayer): We should shrink the large object page if the size |
651 // of the object changed significantly. | 651 // of the object changed significantly. |
652 if (!heap->lo_space()->Contains(*answer)) { | 652 if (!heap->lo_space()->Contains(*answer)) { |
653 heap->CreateFillerObjectAt(end_of_string, delta, ClearRecordedSlots::kNo); | 653 heap->CreateFillerObjectAt(end_of_string, delta, ClearRecordedSlots::kNo); |
654 } | 654 } |
655 heap->AdjustLiveBytes(*answer, -delta, Heap::CONCURRENT_TO_SWEEPER); | 655 heap->AdjustLiveBytes(*answer, -delta, Heap::CONCURRENT_TO_SWEEPER); |
656 return *answer; | 656 return *answer; |
657 } | 657 } |
658 | 658 |
| 659 namespace { |
659 | 660 |
660 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { | 661 Object* StringReplaceGlobalRegExpWithStringHelper( |
661 HandleScope scope(isolate); | 662 Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject, |
662 DCHECK(args.length() == 4); | 663 Handle<String> replacement, Handle<JSObject> last_match_info) { |
663 | |
664 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | |
665 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | |
666 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | |
667 CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3); | |
668 | |
669 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); | 664 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); |
670 CHECK(last_match_info->HasFastObjectElements()); | 665 CHECK(last_match_info->HasFastObjectElements()); |
671 | 666 |
672 subject = String::Flatten(subject); | 667 subject = String::Flatten(subject); |
673 | 668 |
674 if (replacement->length() == 0) { | 669 if (replacement->length() == 0) { |
675 if (subject->HasOnlyOneByteChars()) { | 670 if (subject->HasOnlyOneByteChars()) { |
676 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( | 671 return StringReplaceGlobalRegExpWithEmptyString<SeqOneByteString>( |
677 isolate, subject, regexp, last_match_info); | 672 isolate, subject, regexp, last_match_info); |
678 } else { | 673 } else { |
679 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( | 674 return StringReplaceGlobalRegExpWithEmptyString<SeqTwoByteString>( |
680 isolate, subject, regexp, last_match_info); | 675 isolate, subject, regexp, last_match_info); |
681 } | 676 } |
682 } | 677 } |
683 | 678 |
684 replacement = String::Flatten(replacement); | 679 replacement = String::Flatten(replacement); |
685 | 680 |
686 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, | 681 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, |
687 replacement, last_match_info); | 682 replacement, last_match_info); |
688 } | 683 } |
689 | 684 |
| 685 } // namespace |
| 686 |
| 687 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { |
| 688 HandleScope scope(isolate); |
| 689 DCHECK(args.length() == 4); |
| 690 |
| 691 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 692 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
| 693 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
| 694 CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3); |
| 695 |
| 696 return StringReplaceGlobalRegExpWithStringHelper( |
| 697 isolate, regexp, subject, replacement, last_match_info); |
| 698 } |
690 | 699 |
691 RUNTIME_FUNCTION(Runtime_StringSplit) { | 700 RUNTIME_FUNCTION(Runtime_StringSplit) { |
692 HandleScope handle_scope(isolate); | 701 HandleScope handle_scope(isolate); |
693 DCHECK(args.length() == 3); | 702 DCHECK(args.length() == 3); |
694 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 703 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
695 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); | 704 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); |
696 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); | 705 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); |
697 CHECK(limit > 0); | 706 CHECK(limit > 0); |
698 | 707 |
699 int subject_length = subject->length(); | 708 int subject_length = subject->length(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 isolate->factory()->empty_fixed_array(), | 771 isolate->factory()->empty_fixed_array(), |
763 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); | 772 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); |
764 } | 773 } |
765 } | 774 } |
766 | 775 |
767 TruncateRegexpIndicesList(isolate); | 776 TruncateRegexpIndicesList(isolate); |
768 | 777 |
769 return *result; | 778 return *result; |
770 } | 779 } |
771 | 780 |
| 781 // ES##sec-regexpcreate |
| 782 // RegExpCreate ( P, F ) |
| 783 RUNTIME_FUNCTION(Runtime_RegExpCreate) { |
| 784 HandleScope scope(isolate); |
| 785 DCHECK(args.length() == 1); |
| 786 CONVERT_ARG_HANDLE_CHECKED(Object, source_object, 0); |
| 787 |
| 788 Handle<String> source; |
| 789 if (source_object->IsUndefined(isolate)) { |
| 790 source = isolate->factory()->empty_string(); |
| 791 } else { |
| 792 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 793 isolate, source, Object::ToString(isolate, source_object)); |
| 794 } |
| 795 |
| 796 Handle<Map> map(isolate->regexp_function()->initial_map()); |
| 797 Handle<JSRegExp> regexp = |
| 798 Handle<JSRegExp>::cast(isolate->factory()->NewJSObjectFromMap(map)); |
| 799 |
| 800 JSRegExp::Flags flags = JSRegExp::kNone; |
| 801 |
| 802 RETURN_FAILURE_ON_EXCEPTION(isolate, |
| 803 JSRegExp::Initialize(regexp, source, flags)); |
| 804 |
| 805 return *regexp; |
| 806 } |
772 | 807 |
773 RUNTIME_FUNCTION(Runtime_RegExpExec) { | 808 RUNTIME_FUNCTION(Runtime_RegExpExec) { |
774 HandleScope scope(isolate); | 809 HandleScope scope(isolate); |
775 DCHECK(args.length() == 4); | 810 DCHECK(args.length() == 4); |
776 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 811 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
777 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 812 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
778 CONVERT_INT32_ARG_CHECKED(index, 2); | 813 CONVERT_INT32_ARG_CHECKED(index, 2); |
779 CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3); | 814 CONVERT_ARG_HANDLE_CHECKED(JSObject, last_match_info, 3); |
780 // Due to the way the JS calls are constructed this must be less than the | 815 // Due to the way the JS calls are constructed this must be less than the |
781 // length of a string, i.e. it is always a Smi. We check anyway for security. | 816 // length of a string, i.e. it is always a Smi. We check anyway for security. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 863 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
829 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 864 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); |
830 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); | 865 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); |
831 | 866 |
832 RETURN_FAILURE_ON_EXCEPTION(isolate, | 867 RETURN_FAILURE_ON_EXCEPTION(isolate, |
833 JSRegExp::Initialize(regexp, source, flags)); | 868 JSRegExp::Initialize(regexp, source, flags)); |
834 | 869 |
835 return *regexp; | 870 return *regexp; |
836 } | 871 } |
837 | 872 |
| 873 RUNTIME_FUNCTION(Runtime_RegExpInternalReplace) { |
| 874 HandleScope scope(isolate); |
| 875 DCHECK(args.length() == 3); |
| 876 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
| 877 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
| 878 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
| 879 |
| 880 static const int kInitialMatchSlots = 2; |
| 881 Handle<JSArray> internal_match_info = isolate->factory()->NewJSArray( |
| 882 FAST_ELEMENTS, 0, RegExpImpl::kLastMatchOverhead + kInitialMatchSlots, |
| 883 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 884 |
| 885 return StringReplaceGlobalRegExpWithStringHelper( |
| 886 isolate, regexp, subject, replacement, internal_match_info); |
| 887 } |
| 888 |
838 namespace { | 889 namespace { |
839 | 890 |
840 class MatchInfoBackedMatch : public String::Match { | 891 class MatchInfoBackedMatch : public String::Match { |
841 public: | 892 public: |
842 MatchInfoBackedMatch(Isolate* isolate, Handle<String> subject, | 893 MatchInfoBackedMatch(Isolate* isolate, Handle<String> subject, |
843 Handle<JSObject> match_info) | 894 Handle<JSObject> match_info) |
844 : isolate_(isolate), match_info_(match_info) { | 895 : isolate_(isolate), match_info_(match_info) { |
845 subject_ = String::Flatten(subject); | 896 subject_ = String::Flatten(subject); |
846 } | 897 } |
847 | 898 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 | 1675 |
1625 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1676 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
1626 SealHandleScope shs(isolate); | 1677 SealHandleScope shs(isolate); |
1627 DCHECK(args.length() == 1); | 1678 DCHECK(args.length() == 1); |
1628 CONVERT_ARG_CHECKED(Object, obj, 0); | 1679 CONVERT_ARG_CHECKED(Object, obj, 0); |
1629 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1680 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
1630 } | 1681 } |
1631 | 1682 |
1632 } // namespace internal | 1683 } // namespace internal |
1633 } // namespace v8 | 1684 } // namespace v8 |
OLD | NEW |