| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (!success) { | 917 if (!success) { |
| 918 THROW_NEW_ERROR_RETURN_FAILURE( | 918 THROW_NEW_ERROR_RETURN_FAILURE( |
| 919 isolate, | 919 isolate, |
| 920 NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string)); | 920 NewSyntaxError(MessageTemplate::kInvalidRegExpFlags, flags_string)); |
| 921 } | 921 } |
| 922 | 922 |
| 923 Handle<String> escaped_source; | 923 Handle<String> escaped_source; |
| 924 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source, | 924 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, escaped_source, |
| 925 EscapeRegExpSource(isolate, source)); | 925 EscapeRegExpSource(isolate, source)); |
| 926 | 926 |
| 927 Handle<Object> global = factory->ToBoolean(flags.is_global()); |
| 928 Handle<Object> ignore_case = factory->ToBoolean(flags.is_ignore_case()); |
| 929 Handle<Object> multiline = factory->ToBoolean(flags.is_multiline()); |
| 930 Handle<Object> sticky = factory->ToBoolean(flags.is_sticky()); |
| 931 Handle<Object> unicode = factory->ToBoolean(flags.is_unicode()); |
| 932 |
| 927 Map* map = regexp->map(); | 933 Map* map = regexp->map(); |
| 928 Object* constructor = map->GetConstructor(); | 934 Object* constructor = map->GetConstructor(); |
| 929 if (constructor->IsJSFunction() && | 935 if (!FLAG_harmony_regexps && !FLAG_harmony_unicode_regexps && |
| 936 constructor->IsJSFunction() && |
| 930 JSFunction::cast(constructor)->initial_map() == map) { | 937 JSFunction::cast(constructor)->initial_map() == map) { |
| 931 // If we still have the original map, set in-object properties directly. | 938 // If we still have the original map, set in-object properties directly. |
| 932 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, *escaped_source); | 939 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, *escaped_source); |
| 933 regexp->InObjectPropertyAtPut(JSRegExp::kFlagsFieldIndex, | 940 // Both true and false are immovable immortal objects so no need for write |
| 934 Smi::FromInt(flags.value()), | 941 // barrier. |
| 942 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, *global, |
| 943 SKIP_WRITE_BARRIER); |
| 944 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, *ignore_case, |
| 945 SKIP_WRITE_BARRIER); |
| 946 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, *multiline, |
| 935 SKIP_WRITE_BARRIER); | 947 SKIP_WRITE_BARRIER); |
| 936 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, | 948 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, |
| 937 Smi::FromInt(0), SKIP_WRITE_BARRIER); | 949 Smi::FromInt(0), SKIP_WRITE_BARRIER); |
| 938 } else { | 950 } else { |
| 939 // Map has changed, so use generic, but slower, method. We also end here if | 951 // Map has changed, so use generic, but slower, method. We also end here if |
| 940 // the --harmony-regexp flag is set, because the initial map does not have | 952 // 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 | 953 // 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 | 954 // 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. | 955 // the flag, we will be able to use the fast initial map. |
| 944 PropertyAttributes final = | 956 PropertyAttributes final = |
| 945 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); | 957 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 946 PropertyAttributes writable = | 958 PropertyAttributes writable = |
| 947 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 959 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 948 Handle<Object> zero(Smi::FromInt(0), isolate); | 960 Handle<Object> zero(Smi::FromInt(0), isolate); |
| 961 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->source_string(), |
| 962 escaped_source, final).Check(); |
| 963 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->global_string(), |
| 964 global, final).Check(); |
| 949 JSObject::SetOwnPropertyIgnoreAttributes( | 965 JSObject::SetOwnPropertyIgnoreAttributes( |
| 950 regexp, factory->regexp_source_symbol(), escaped_source, final) | 966 regexp, factory->ignore_case_string(), ignore_case, final).Check(); |
| 951 .Check(); | |
| 952 JSObject::SetOwnPropertyIgnoreAttributes( | 967 JSObject::SetOwnPropertyIgnoreAttributes( |
| 953 regexp, factory->regexp_flags_symbol(), | 968 regexp, factory->multiline_string(), multiline, final).Check(); |
| 954 Handle<Smi>(Smi::FromInt(flags.value()), isolate), final) | 969 if (FLAG_harmony_regexps) { |
| 955 .Check(); | 970 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->sticky_string(), |
| 971 sticky, final).Check(); |
| 972 } |
| 973 if (FLAG_harmony_unicode_regexps) { |
| 974 JSObject::SetOwnPropertyIgnoreAttributes( |
| 975 regexp, factory->unicode_string(), unicode, final).Check(); |
| 976 } |
| 956 JSObject::SetOwnPropertyIgnoreAttributes( | 977 JSObject::SetOwnPropertyIgnoreAttributes( |
| 957 regexp, factory->last_index_string(), zero, writable).Check(); | 978 regexp, factory->last_index_string(), zero, writable).Check(); |
| 958 } | 979 } |
| 959 | 980 |
| 960 Handle<Object> result; | 981 Handle<Object> result; |
| 961 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 982 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 962 isolate, result, RegExpImpl::Compile(regexp, source, flags)); | 983 isolate, result, RegExpImpl::Compile(regexp, source, flags)); |
| 963 return *result; | 984 return *result; |
| 964 } | 985 } |
| 965 | 986 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1187 |
| 1167 | 1188 |
| 1168 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1189 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
| 1169 SealHandleScope shs(isolate); | 1190 SealHandleScope shs(isolate); |
| 1170 DCHECK(args.length() == 1); | 1191 DCHECK(args.length() == 1); |
| 1171 CONVERT_ARG_CHECKED(Object, obj, 0); | 1192 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1172 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1193 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1173 } | 1194 } |
| 1174 } // namespace internal | 1195 } // namespace internal |
| 1175 } // namespace v8 | 1196 } // namespace v8 |
| OLD | NEW |