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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 replacement = String::Flatten(replacement); | 678 replacement = String::Flatten(replacement); |
679 | 679 |
680 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, | 680 return StringReplaceGlobalRegExpWithString(isolate, subject, regexp, |
681 replacement, last_match_info); | 681 replacement, last_match_info); |
682 } | 682 } |
683 | 683 |
684 } // namespace | 684 } // namespace |
685 | 685 |
686 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { | 686 RUNTIME_FUNCTION(Runtime_StringReplaceGlobalRegExpWithString) { |
687 HandleScope scope(isolate); | 687 HandleScope scope(isolate); |
688 DCHECK(args.length() == 4); | 688 DCHECK_EQ(4, args.length()); |
689 | 689 |
690 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 690 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
691 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | 691 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
692 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 692 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
693 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 3); | 693 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 3); |
694 | 694 |
695 return StringReplaceGlobalRegExpWithStringHelper( | 695 return StringReplaceGlobalRegExpWithStringHelper( |
696 isolate, regexp, subject, replacement, last_match_info); | 696 isolate, regexp, subject, replacement, last_match_info); |
697 } | 697 } |
698 | 698 |
699 RUNTIME_FUNCTION(Runtime_StringSplit) { | 699 RUNTIME_FUNCTION(Runtime_StringSplit) { |
700 HandleScope handle_scope(isolate); | 700 HandleScope handle_scope(isolate); |
701 DCHECK(args.length() == 3); | 701 DCHECK_EQ(3, args.length()); |
702 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 702 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
703 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); | 703 CONVERT_ARG_HANDLE_CHECKED(String, pattern, 1); |
704 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); | 704 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[2]); |
705 CHECK(limit > 0); | 705 CHECK(limit > 0); |
706 | 706 |
707 int subject_length = subject->length(); | 707 int subject_length = subject->length(); |
708 int pattern_length = pattern->length(); | 708 int pattern_length = pattern->length(); |
709 CHECK(pattern_length > 0); | 709 CHECK(pattern_length > 0); |
710 | 710 |
711 if (limit == 0xffffffffu) { | 711 if (limit == 0xffffffffu) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 | 774 |
775 TruncateRegexpIndicesList(isolate); | 775 TruncateRegexpIndicesList(isolate); |
776 | 776 |
777 return *result; | 777 return *result; |
778 } | 778 } |
779 | 779 |
780 // ES##sec-regexpcreate | 780 // ES##sec-regexpcreate |
781 // RegExpCreate ( P, F ) | 781 // RegExpCreate ( P, F ) |
782 RUNTIME_FUNCTION(Runtime_RegExpCreate) { | 782 RUNTIME_FUNCTION(Runtime_RegExpCreate) { |
783 HandleScope scope(isolate); | 783 HandleScope scope(isolate); |
784 DCHECK(args.length() == 1); | 784 DCHECK_EQ(1, args.length()); |
785 CONVERT_ARG_HANDLE_CHECKED(Object, source_object, 0); | 785 CONVERT_ARG_HANDLE_CHECKED(Object, source_object, 0); |
786 | 786 |
787 Handle<String> source; | 787 Handle<String> source; |
788 if (source_object->IsUndefined(isolate)) { | 788 if (source_object->IsUndefined(isolate)) { |
789 source = isolate->factory()->empty_string(); | 789 source = isolate->factory()->empty_string(); |
790 } else { | 790 } else { |
791 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 791 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
792 isolate, source, Object::ToString(isolate, source_object)); | 792 isolate, source, Object::ToString(isolate, source_object)); |
793 } | 793 } |
794 | 794 |
795 Handle<Map> map(isolate->regexp_function()->initial_map()); | 795 Handle<Map> map(isolate->regexp_function()->initial_map()); |
796 Handle<JSRegExp> regexp = | 796 Handle<JSRegExp> regexp = |
797 Handle<JSRegExp>::cast(isolate->factory()->NewJSObjectFromMap(map)); | 797 Handle<JSRegExp>::cast(isolate->factory()->NewJSObjectFromMap(map)); |
798 | 798 |
799 JSRegExp::Flags flags = JSRegExp::kNone; | 799 JSRegExp::Flags flags = JSRegExp::kNone; |
800 | 800 |
801 RETURN_FAILURE_ON_EXCEPTION(isolate, | 801 RETURN_FAILURE_ON_EXCEPTION(isolate, |
802 JSRegExp::Initialize(regexp, source, flags)); | 802 JSRegExp::Initialize(regexp, source, flags)); |
803 | 803 |
804 return *regexp; | 804 return *regexp; |
805 } | 805 } |
806 | 806 |
807 RUNTIME_FUNCTION(Runtime_RegExpExec) { | 807 RUNTIME_FUNCTION(Runtime_RegExpExec) { |
808 HandleScope scope(isolate); | 808 HandleScope scope(isolate); |
809 DCHECK(args.length() == 4); | 809 DCHECK_EQ(4, args.length()); |
810 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 810 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
811 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 811 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
812 CONVERT_INT32_ARG_CHECKED(index, 2); | 812 CONVERT_INT32_ARG_CHECKED(index, 2); |
813 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 3); | 813 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 3); |
814 // Due to the way the JS calls are constructed this must be less than the | 814 // Due to the way the JS calls are constructed this must be less than the |
815 // length of a string, i.e. it is always a Smi. We check anyway for security. | 815 // length of a string, i.e. it is always a Smi. We check anyway for security. |
816 CHECK(index >= 0); | 816 CHECK(index >= 0); |
817 CHECK(index <= subject->length()); | 817 CHECK(index <= subject->length()); |
818 isolate->counters()->regexp_entry_runtime()->Increment(); | 818 isolate->counters()->regexp_entry_runtime()->Increment(); |
819 RETURN_RESULT_OR_FAILURE( | 819 RETURN_RESULT_OR_FAILURE( |
820 isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info)); | 820 isolate, RegExpImpl::Exec(regexp, subject, index, last_match_info)); |
821 } | 821 } |
822 | 822 |
823 RUNTIME_FUNCTION(Runtime_RegExpInternalReplace) { | 823 RUNTIME_FUNCTION(Runtime_RegExpInternalReplace) { |
824 HandleScope scope(isolate); | 824 HandleScope scope(isolate); |
825 DCHECK(args.length() == 3); | 825 DCHECK_EQ(3, args.length()); |
826 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 826 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
827 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 827 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
828 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); | 828 CONVERT_ARG_HANDLE_CHECKED(String, replacement, 2); |
829 | 829 |
830 Handle<RegExpMatchInfo> internal_match_info = | 830 Handle<RegExpMatchInfo> internal_match_info = |
831 isolate->regexp_internal_match_info(); | 831 isolate->regexp_internal_match_info(); |
832 | 832 |
833 return StringReplaceGlobalRegExpWithStringHelper( | 833 return StringReplaceGlobalRegExpWithStringHelper( |
834 isolate, regexp, subject, replacement, internal_match_info); | 834 isolate, regexp, subject, replacement, internal_match_info); |
835 } | 835 } |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 | 1230 |
1231 UNREACHABLE(); | 1231 UNREACHABLE(); |
1232 return MaybeHandle<String>(); | 1232 return MaybeHandle<String>(); |
1233 } | 1233 } |
1234 | 1234 |
1235 } // namespace | 1235 } // namespace |
1236 | 1236 |
1237 // This is only called for StringReplaceGlobalRegExpWithFunction. | 1237 // This is only called for StringReplaceGlobalRegExpWithFunction. |
1238 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { | 1238 RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { |
1239 HandleScope handles(isolate); | 1239 HandleScope handles(isolate); |
1240 DCHECK(args.length() == 4); | 1240 DCHECK_EQ(4, args.length()); |
1241 | 1241 |
1242 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 1242 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
1243 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); | 1243 CONVERT_ARG_HANDLE_CHECKED(String, subject, 1); |
1244 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 2); | 1244 CONVERT_ARG_HANDLE_CHECKED(RegExpMatchInfo, last_match_info, 2); |
1245 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); | 1245 CONVERT_ARG_HANDLE_CHECKED(JSArray, result_array, 3); |
1246 CHECK(result_array->HasFastObjectElements()); | 1246 CHECK(result_array->HasFastObjectElements()); |
1247 | 1247 |
1248 subject = String::Flatten(subject); | 1248 subject = String::Flatten(subject); |
1249 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); | 1249 CHECK(regexp->GetFlags() & JSRegExp::kGlobal); |
1250 | 1250 |
1251 if (regexp->CaptureCount() == 0) { | 1251 if (regexp->CaptureCount() == 0) { |
1252 return SearchRegExpMultiple<false>(isolate, subject, regexp, | 1252 return SearchRegExpMultiple<false>(isolate, subject, regexp, |
1253 last_match_info, result_array); | 1253 last_match_info, result_array); |
1254 } else { | 1254 } else { |
1255 return SearchRegExpMultiple<true>(isolate, subject, regexp, last_match_info, | 1255 return SearchRegExpMultiple<true>(isolate, subject, regexp, last_match_info, |
1256 result_array); | 1256 result_array); |
1257 } | 1257 } |
1258 } | 1258 } |
1259 | 1259 |
1260 RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { | 1260 RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { |
1261 HandleScope scope(isolate); | 1261 HandleScope scope(isolate); |
1262 DCHECK(args.length() == 3); | 1262 DCHECK_EQ(3, args.length()); |
1263 | 1263 |
1264 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 1264 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
1265 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 1265 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
1266 CONVERT_ARG_HANDLE_CHECKED(JSObject, replace, 2); | 1266 CONVERT_ARG_HANDLE_CHECKED(JSObject, replace, 2); |
1267 | 1267 |
1268 RETURN_RESULT_OR_FAILURE(isolate, StringReplaceNonGlobalRegExpWithFunction( | 1268 RETURN_RESULT_OR_FAILURE(isolate, StringReplaceNonGlobalRegExpWithFunction( |
1269 isolate, subject, regexp, replace)); | 1269 isolate, subject, regexp, replace)); |
1270 } | 1270 } |
1271 | 1271 |
1272 namespace { | 1272 namespace { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 return isolate->factory()->NewJSArrayWithElements(elems); | 1329 return isolate->factory()->NewJSArrayWithElements(elems); |
1330 } | 1330 } |
1331 | 1331 |
1332 } // namespace | 1332 } // namespace |
1333 | 1333 |
1334 // Slow path for: | 1334 // Slow path for: |
1335 // ES#sec-regexp.prototype-@@replace | 1335 // ES#sec-regexp.prototype-@@replace |
1336 // RegExp.prototype [ @@split ] ( string, limit ) | 1336 // RegExp.prototype [ @@split ] ( string, limit ) |
1337 RUNTIME_FUNCTION(Runtime_RegExpSplit) { | 1337 RUNTIME_FUNCTION(Runtime_RegExpSplit) { |
1338 HandleScope scope(isolate); | 1338 HandleScope scope(isolate); |
1339 DCHECK(args.length() == 3); | 1339 DCHECK_EQ(3, args.length()); |
1340 | 1340 |
1341 DCHECK(args[1]->IsString()); | 1341 DCHECK(args[1]->IsString()); |
1342 | 1342 |
1343 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); | 1343 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); |
1344 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); | 1344 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); |
1345 CONVERT_ARG_HANDLE_CHECKED(Object, limit_obj, 2); | 1345 CONVERT_ARG_HANDLE_CHECKED(Object, limit_obj, 2); |
1346 | 1346 |
1347 Factory* factory = isolate->factory(); | 1347 Factory* factory = isolate->factory(); |
1348 | 1348 |
1349 Handle<JSFunction> regexp_fun = isolate->regexp_function(); | 1349 Handle<JSFunction> regexp_fun = isolate->regexp_function(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 } | 1483 } |
1484 | 1484 |
1485 return *NewJSArrayWithElements(isolate, elems, num_elems); | 1485 return *NewJSArrayWithElements(isolate, elems, num_elems); |
1486 } | 1486 } |
1487 | 1487 |
1488 // Slow path for: | 1488 // Slow path for: |
1489 // ES#sec-regexp.prototype-@@replace | 1489 // ES#sec-regexp.prototype-@@replace |
1490 // RegExp.prototype [ @@replace ] ( string, replaceValue ) | 1490 // RegExp.prototype [ @@replace ] ( string, replaceValue ) |
1491 RUNTIME_FUNCTION(Runtime_RegExpReplace) { | 1491 RUNTIME_FUNCTION(Runtime_RegExpReplace) { |
1492 HandleScope scope(isolate); | 1492 HandleScope scope(isolate); |
1493 DCHECK(args.length() == 3); | 1493 DCHECK_EQ(3, args.length()); |
1494 | 1494 |
1495 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); | 1495 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, recv, 0); |
1496 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); | 1496 CONVERT_ARG_HANDLE_CHECKED(String, string, 1); |
1497 Handle<Object> replace_obj = args.at(2); | 1497 Handle<Object> replace_obj = args.at(2); |
1498 | 1498 |
1499 Factory* factory = isolate->factory(); | 1499 Factory* factory = isolate->factory(); |
1500 | 1500 |
1501 string = String::Flatten(string); | 1501 string = String::Flatten(string); |
1502 | 1502 |
1503 // Fast-path for unmodified JSRegExps. | 1503 // Fast-path for unmodified JSRegExps. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 if (next_source_position < length) { | 1650 if (next_source_position < length) { |
1651 builder.AppendString( | 1651 builder.AppendString( |
1652 factory->NewSubString(string, next_source_position, length)); | 1652 factory->NewSubString(string, next_source_position, length)); |
1653 } | 1653 } |
1654 | 1654 |
1655 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); | 1655 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
1656 } | 1656 } |
1657 | 1657 |
1658 RUNTIME_FUNCTION(Runtime_RegExpExecReThrow) { | 1658 RUNTIME_FUNCTION(Runtime_RegExpExecReThrow) { |
1659 SealHandleScope shs(isolate); | 1659 SealHandleScope shs(isolate); |
1660 DCHECK(args.length() == 4); | 1660 DCHECK_EQ(4, args.length()); |
1661 Object* exception = isolate->pending_exception(); | 1661 Object* exception = isolate->pending_exception(); |
1662 isolate->clear_pending_exception(); | 1662 isolate->clear_pending_exception(); |
1663 return isolate->ReThrow(exception); | 1663 return isolate->ReThrow(exception); |
1664 } | 1664 } |
1665 | 1665 |
1666 RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) { | 1666 RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) { |
1667 HandleScope scope(isolate); | 1667 HandleScope scope(isolate); |
1668 DCHECK(args.length() == 3); | 1668 DCHECK_EQ(3, args.length()); |
1669 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); | 1669 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 0); |
1670 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 1670 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); |
1671 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); | 1671 CONVERT_ARG_HANDLE_CHECKED(String, flags, 2); |
1672 | 1672 |
1673 RETURN_FAILURE_ON_EXCEPTION(isolate, | 1673 RETURN_FAILURE_ON_EXCEPTION(isolate, |
1674 JSRegExp::Initialize(regexp, source, flags)); | 1674 JSRegExp::Initialize(regexp, source, flags)); |
1675 | 1675 |
1676 return *regexp; | 1676 return *regexp; |
1677 } | 1677 } |
1678 | 1678 |
1679 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1679 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
1680 SealHandleScope shs(isolate); | 1680 SealHandleScope shs(isolate); |
1681 DCHECK(args.length() == 1); | 1681 DCHECK_EQ(1, args.length()); |
1682 CONVERT_ARG_CHECKED(Object, obj, 0); | 1682 CONVERT_ARG_CHECKED(Object, obj, 0); |
1683 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1683 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
1684 } | 1684 } |
1685 | 1685 |
1686 } // namespace internal | 1686 } // namespace internal |
1687 } // namespace v8 | 1687 } // namespace v8 |
OLD | NEW |