| 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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 RUNTIME_ASSERT(index <= subject->length()); | 781 RUNTIME_ASSERT(index <= subject->length()); |
| 782 isolate->counters()->regexp_entry_runtime()->Increment(); | 782 isolate->counters()->regexp_entry_runtime()->Increment(); |
| 783 Handle<Object> result; | 783 Handle<Object> result; |
| 784 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 784 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 785 isolate, result, | 785 isolate, result, |
| 786 RegExpImpl::Exec(regexp, subject, index, last_match_info)); | 786 RegExpImpl::Exec(regexp, subject, index, last_match_info)); |
| 787 return *result; | 787 return *result; |
| 788 } | 788 } |
| 789 | 789 |
| 790 | 790 |
| 791 RUNTIME_FUNCTION(Runtime_RegExpFlags) { |
| 792 SealHandleScope shs(isolate); |
| 793 DCHECK(args.length() == 1); |
| 794 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); |
| 795 return regexp->flags(); |
| 796 } |
| 797 |
| 798 |
| 799 RUNTIME_FUNCTION(Runtime_RegExpSource) { |
| 800 SealHandleScope shs(isolate); |
| 801 DCHECK(args.length() == 1); |
| 802 CONVERT_ARG_CHECKED(JSRegExp, regexp, 0); |
| 803 return regexp->source(); |
| 804 } |
| 805 |
| 806 |
| 791 RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { | 807 RUNTIME_FUNCTION(Runtime_RegExpConstructResult) { |
| 792 HandleScope handle_scope(isolate); | 808 HandleScope handle_scope(isolate); |
| 793 DCHECK(args.length() == 3); | 809 DCHECK(args.length() == 3); |
| 794 CONVERT_SMI_ARG_CHECKED(size, 0); | 810 CONVERT_SMI_ARG_CHECKED(size, 0); |
| 795 RUNTIME_ASSERT(size >= 0 && size <= FixedArray::kMaxLength); | 811 RUNTIME_ASSERT(size >= 0 && size <= FixedArray::kMaxLength); |
| 796 CONVERT_ARG_HANDLE_CHECKED(Object, index, 1); | 812 CONVERT_ARG_HANDLE_CHECKED(Object, index, 1); |
| 797 CONVERT_ARG_HANDLE_CHECKED(Object, input, 2); | 813 CONVERT_ARG_HANDLE_CHECKED(Object, input, 2); |
| 798 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(size); | 814 Handle<FixedArray> elements = isolate->factory()->NewFixedArray(size); |
| 799 Handle<Map> regexp_map(isolate->native_context()->regexp_result_map()); | 815 Handle<Map> regexp_map(isolate->native_context()->regexp_result_map()); |
| 800 Handle<JSObject> object = | 816 Handle<JSObject> object = |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (!success) { | 933 if (!success) { |
| 918 THROW_NEW_ERROR_RETURN_FAILURE( | 934 THROW_NEW_ERROR_RETURN_FAILURE( |
| 919 isolate, | 935 isolate, |
| 920 NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string)); | 936 NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string)); |
| 921 } | 937 } |
| 922 | 938 |
| 923 Handle<String> escaped_source; | 939 Handle<String> escaped_source; |
| 924 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source, | 940 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source, |
| 925 EscapeRegExpSource(isolate, source)); | 941 EscapeRegExpSource(isolate, source)); |
| 926 | 942 |
| 943 regexp->set_source(*escaped_source); |
| 944 regexp->set_flags(Smi::FromInt(flags.value())); |
| 945 |
| 927 Map* map = regexp->map(); | 946 Map* map = regexp->map(); |
| 928 Object* constructor = map->GetConstructor(); | 947 Object* constructor = map->GetConstructor(); |
| 929 if (constructor->IsJSFunction() && | 948 if (constructor->IsJSFunction() && |
| 930 JSFunction::cast(constructor)->initial_map() == map) { | 949 JSFunction::cast(constructor)->initial_map() == map) { |
| 931 // If we still have the original map, set in-object properties directly. | 950 // If we still have the original map, set in-object properties directly. |
| 932 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, *escaped_source); | |
| 933 regexp->InObjectPropertyAtPut(JSRegExp::kFlagsFieldIndex, | |
| 934 Smi::FromInt(flags.value()), | |
| 935 SKIP_WRITE_BARRIER); | |
| 936 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, | 951 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, |
| 937 Smi::FromInt(0), SKIP_WRITE_BARRIER); | 952 Smi::FromInt(0), SKIP_WRITE_BARRIER); |
| 938 } else { | 953 } else { |
| 939 // Map has changed, so use generic, but slower, method. We also end here if | 954 // Map has changed, so use generic, but slower, method. |
| 940 // the --harmony-regexp flag is set, because the initial map does not have | |
| 941 // space for the 'sticky' flag, since it is from the snapshot, but must work | |
| 942 // both with and without --harmony-regexp. When sticky comes out from under | |
| 943 // the flag, we will be able to use the fast initial map. | |
| 944 PropertyAttributes final = | |
| 945 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); | |
| 946 PropertyAttributes writable = | 955 PropertyAttributes writable = |
| 947 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 956 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 948 Handle<Object> zero(Smi::FromInt(0), isolate); | |
| 949 JSObject::SetOwnPropertyIgnoreAttributes( | 957 JSObject::SetOwnPropertyIgnoreAttributes( |
| 950 regexp, factory->regexp_source_symbol(), escaped_source, final) | 958 regexp, factory->last_index_string(), |
| 959 Handle<Smi>(Smi::FromInt(0), isolate), writable) |
| 951 .Check(); | 960 .Check(); |
| 952 JSObject::SetOwnPropertyIgnoreAttributes( | |
| 953 regexp, factory->regexp_flags_symbol(), | |
| 954 Handle<Smi>(Smi::FromInt(flags.value()), isolate), final) | |
| 955 .Check(); | |
| 956 JSObject::SetOwnPropertyIgnoreAttributes( | |
| 957 regexp, factory->last_index_string(), zero, writable).Check(); | |
| 958 } | 961 } |
| 959 | 962 |
| 960 Handle<Object> result; | 963 Handle<Object> result; |
| 961 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 964 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 962 isolate, result, RegExpImpl::Compile(regexp, source, flags)); | 965 isolate, result, RegExpImpl::Compile(regexp, source, flags)); |
| 963 return *result; | 966 return *result; |
| 964 } | 967 } |
| 965 | 968 |
| 966 | 969 |
| 967 RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) { | 970 RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1169 |
| 1167 | 1170 |
| 1168 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1171 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
| 1169 SealHandleScope shs(isolate); | 1172 SealHandleScope shs(isolate); |
| 1170 DCHECK(args.length() == 1); | 1173 DCHECK(args.length() == 1); |
| 1171 CONVERT_ARG_CHECKED(Object, obj, 0); | 1174 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1172 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1175 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1173 } | 1176 } |
| 1174 } // namespace internal | 1177 } // namespace internal |
| 1175 } // namespace v8 | 1178 } // namespace v8 |
| OLD | NEW |