Chromium Code Reviews| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/jsregexp-inl.h" | 8 #include "src/jsregexp-inl.h" |
| 9 #include "src/jsregexp.h" | 9 #include "src/jsregexp.h" |
| 10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, *input); | 798 array->InObjectPropertyAtPut(JSRegExpResult::kInputIndex, *input); |
| 799 return *array; | 799 return *array; |
| 800 } | 800 } |
| 801 | 801 |
| 802 | 802 |
| 803 static JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, | 803 static JSRegExp::Flags RegExpFlagsFromString(Handle<String> flags, |
| 804 bool* success) { | 804 bool* success) { |
| 805 uint32_t value = JSRegExp::NONE; | 805 uint32_t value = JSRegExp::NONE; |
| 806 int length = flags->length(); | 806 int length = flags->length(); |
| 807 // A longer flags string cannot be valid. | 807 // A longer flags string cannot be valid. |
| 808 if (length > 4) return JSRegExp::Flags(0); | 808 if (length > 5) return JSRegExp::Flags(0); |
| 809 for (int i = 0; i < length; i++) { | 809 for (int i = 0; i < length; i++) { |
| 810 uint32_t flag = JSRegExp::NONE; | 810 uint32_t flag = JSRegExp::NONE; |
| 811 switch (flags->Get(i)) { | 811 switch (flags->Get(i)) { |
| 812 case 'g': | 812 case 'g': |
| 813 flag = JSRegExp::GLOBAL; | 813 flag = JSRegExp::GLOBAL; |
| 814 break; | 814 break; |
| 815 case 'i': | 815 case 'i': |
| 816 flag = JSRegExp::IGNORE_CASE; | 816 flag = JSRegExp::IGNORE_CASE; |
| 817 break; | 817 break; |
| 818 case 'm': | 818 case 'm': |
| 819 flag = JSRegExp::MULTILINE; | 819 flag = JSRegExp::MULTILINE; |
| 820 break; | 820 break; |
| 821 case 'y': | 821 case 'y': |
| 822 if (!FLAG_harmony_regexps) return JSRegExp::Flags(0); | 822 if (!FLAG_harmony_regexps) return JSRegExp::Flags(0); |
| 823 flag = JSRegExp::STICKY; | 823 flag = JSRegExp::STICKY; |
| 824 break; | 824 break; |
| 825 case 'u': | |
|
rossberg
2015/01/08 12:47:45
Nit: sort cases alphabetically
marja
2015/01/08 13:42:18
Done.
| |
| 826 if (!FLAG_harmony_unicode) return JSRegExp::Flags(0); | |
| 827 flag = JSRegExp::UNICODE_ESCAPES; | |
| 828 break; | |
| 825 default: | 829 default: |
| 826 return JSRegExp::Flags(0); | 830 return JSRegExp::Flags(0); |
| 827 } | 831 } |
| 828 // Duplicate flag. | 832 // Duplicate flag. |
| 829 if (value & flag) return JSRegExp::Flags(0); | 833 if (value & flag) return JSRegExp::Flags(0); |
| 830 value |= flag; | 834 value |= flag; |
| 831 } | 835 } |
| 832 *success = true; | 836 *success = true; |
| 833 return JSRegExp::Flags(value); | 837 return JSRegExp::Flags(value); |
| 834 } | 838 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 852 element->set(0, *flags_string); | 856 element->set(0, *flags_string); |
| 853 Handle<JSArray> args = factory->NewJSArrayWithElements(element); | 857 Handle<JSArray> args = factory->NewJSArrayWithElements(element); |
| 854 THROW_NEW_ERROR_RETURN_FAILURE( | 858 THROW_NEW_ERROR_RETURN_FAILURE( |
| 855 isolate, NewSyntaxError("invalid_regexp_flags", args)); | 859 isolate, NewSyntaxError("invalid_regexp_flags", args)); |
| 856 } | 860 } |
| 857 | 861 |
| 858 Handle<Object> global = factory->ToBoolean(flags.is_global()); | 862 Handle<Object> global = factory->ToBoolean(flags.is_global()); |
| 859 Handle<Object> ignore_case = factory->ToBoolean(flags.is_ignore_case()); | 863 Handle<Object> ignore_case = factory->ToBoolean(flags.is_ignore_case()); |
| 860 Handle<Object> multiline = factory->ToBoolean(flags.is_multiline()); | 864 Handle<Object> multiline = factory->ToBoolean(flags.is_multiline()); |
| 861 Handle<Object> sticky = factory->ToBoolean(flags.is_sticky()); | 865 Handle<Object> sticky = factory->ToBoolean(flags.is_sticky()); |
| 866 Handle<Object> unicode = factory->ToBoolean(flags.is_unicode()); | |
| 862 | 867 |
| 863 Map* map = regexp->map(); | 868 Map* map = regexp->map(); |
| 864 Object* constructor = map->constructor(); | 869 Object* constructor = map->constructor(); |
| 865 if (!FLAG_harmony_regexps && constructor->IsJSFunction() && | 870 if (!FLAG_harmony_regexps && !FLAG_harmony_unicode && |
| 871 constructor->IsJSFunction() && | |
| 866 JSFunction::cast(constructor)->initial_map() == map) { | 872 JSFunction::cast(constructor)->initial_map() == map) { |
| 867 // If we still have the original map, set in-object properties directly. | 873 // If we still have the original map, set in-object properties directly. |
| 868 // Both true and false are immovable immortal objects so no need for write | 874 // Both true and false are immovable immortal objects so no need for write |
| 869 // barrier. | 875 // barrier. |
| 870 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, *global, | 876 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, *global, |
| 871 SKIP_WRITE_BARRIER); | 877 SKIP_WRITE_BARRIER); |
| 872 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, *ignore_case, | 878 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, *ignore_case, |
| 873 SKIP_WRITE_BARRIER); | 879 SKIP_WRITE_BARRIER); |
| 874 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, *multiline, | 880 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, *multiline, |
| 875 SKIP_WRITE_BARRIER); | 881 SKIP_WRITE_BARRIER); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 889 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->global_string(), | 895 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->global_string(), |
| 890 global, final).Check(); | 896 global, final).Check(); |
| 891 JSObject::SetOwnPropertyIgnoreAttributes( | 897 JSObject::SetOwnPropertyIgnoreAttributes( |
| 892 regexp, factory->ignore_case_string(), ignore_case, final).Check(); | 898 regexp, factory->ignore_case_string(), ignore_case, final).Check(); |
| 893 JSObject::SetOwnPropertyIgnoreAttributes( | 899 JSObject::SetOwnPropertyIgnoreAttributes( |
| 894 regexp, factory->multiline_string(), multiline, final).Check(); | 900 regexp, factory->multiline_string(), multiline, final).Check(); |
| 895 if (FLAG_harmony_regexps) { | 901 if (FLAG_harmony_regexps) { |
| 896 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->sticky_string(), | 902 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->sticky_string(), |
| 897 sticky, final).Check(); | 903 sticky, final).Check(); |
| 898 } | 904 } |
| 905 if (FLAG_harmony_unicode) { | |
| 906 JSObject::SetOwnPropertyIgnoreAttributes( | |
| 907 regexp, factory->unicode_string(), unicode, final).Check(); | |
| 908 } | |
| 899 JSObject::SetOwnPropertyIgnoreAttributes( | 909 JSObject::SetOwnPropertyIgnoreAttributes( |
| 900 regexp, factory->last_index_string(), zero, writable).Check(); | 910 regexp, factory->last_index_string(), zero, writable).Check(); |
| 901 } | 911 } |
| 902 | 912 |
| 903 Handle<Object> result; | 913 Handle<Object> result; |
| 904 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 914 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 905 isolate, result, RegExpImpl::Compile(regexp, source, flags)); | 915 isolate, result, RegExpImpl::Compile(regexp, source, flags)); |
| 906 return *result; | 916 return *result; |
| 907 } | 917 } |
| 908 | 918 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1113 | 1123 |
| 1114 | 1124 |
| 1115 RUNTIME_FUNCTION(RuntimeReference_IsRegExp) { | 1125 RUNTIME_FUNCTION(RuntimeReference_IsRegExp) { |
| 1116 SealHandleScope shs(isolate); | 1126 SealHandleScope shs(isolate); |
| 1117 DCHECK(args.length() == 1); | 1127 DCHECK(args.length() == 1); |
| 1118 CONVERT_ARG_CHECKED(Object, obj, 0); | 1128 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1119 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1129 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1120 } | 1130 } |
| 1121 } | 1131 } |
| 1122 } // namespace v8::internal | 1132 } // namespace v8::internal |
| OLD | NEW |