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