Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: src/runtime/runtime-regexp.cc

Issue 736003002: Correctly escape RegExp source. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@regexpref
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 Handle<Object> global = factory->ToBoolean(flags.is_global()); 857 Handle<Object> global = factory->ToBoolean(flags.is_global());
858 Handle<Object> ignore_case = factory->ToBoolean(flags.is_ignore_case()); 858 Handle<Object> ignore_case = factory->ToBoolean(flags.is_ignore_case());
859 Handle<Object> multiline = factory->ToBoolean(flags.is_multiline()); 859 Handle<Object> multiline = factory->ToBoolean(flags.is_multiline());
860 Handle<Object> sticky = factory->ToBoolean(flags.is_sticky()); 860 Handle<Object> sticky = factory->ToBoolean(flags.is_sticky());
861 861
862 Map* map = regexp->map(); 862 Map* map = regexp->map();
863 Object* constructor = map->constructor(); 863 Object* constructor = map->constructor();
864 if (!FLAG_harmony_regexps && constructor->IsJSFunction() && 864 if (!FLAG_harmony_regexps && constructor->IsJSFunction() &&
865 JSFunction::cast(constructor)->initial_map() == map) { 865 JSFunction::cast(constructor)->initial_map() == map) {
866 // If we still have the original map, set in-object properties directly. 866 // If we still have the original map, set in-object properties directly.
867 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, *source);
868 // Both true and false are immovable immortal objects so no need for write 867 // Both true and false are immovable immortal objects so no need for write
869 // barrier. 868 // barrier.
870 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, *global, 869 regexp->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, *global,
871 SKIP_WRITE_BARRIER); 870 SKIP_WRITE_BARRIER);
872 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, *ignore_case, 871 regexp->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, *ignore_case,
873 SKIP_WRITE_BARRIER); 872 SKIP_WRITE_BARRIER);
874 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, *multiline, 873 regexp->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, *multiline,
875 SKIP_WRITE_BARRIER); 874 SKIP_WRITE_BARRIER);
876 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, 875 regexp->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex,
877 Smi::FromInt(0), SKIP_WRITE_BARRIER); 876 Smi::FromInt(0), SKIP_WRITE_BARRIER);
878 } else { 877 } else {
879 // Map has changed, so use generic, but slower, method. We also end here if 878 // Map has changed, so use generic, but slower, method. We also end here if
880 // the --harmony-regexp flag is set, because the initial map does not have 879 // the --harmony-regexp flag is set, because the initial map does not have
881 // space for the 'sticky' flag, since it is from the snapshot, but must work 880 // space for the 'sticky' flag, since it is from the snapshot, but must work
882 // both with and without --harmony-regexp. When sticky comes out from under 881 // both with and without --harmony-regexp. When sticky comes out from under
883 // the flag, we will be able to use the fast initial map. 882 // the flag, we will be able to use the fast initial map.
884 PropertyAttributes final = 883 PropertyAttributes final =
885 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); 884 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE);
886 PropertyAttributes writable = 885 PropertyAttributes writable =
887 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); 886 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
888 Handle<Object> zero(Smi::FromInt(0), isolate); 887 Handle<Object> zero(Smi::FromInt(0), isolate);
889 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->source_string(),
890 source, final).Check();
891 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->global_string(), 888 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->global_string(),
892 global, final).Check(); 889 global, final).Check();
893 JSObject::SetOwnPropertyIgnoreAttributes( 890 JSObject::SetOwnPropertyIgnoreAttributes(
894 regexp, factory->ignore_case_string(), ignore_case, final).Check(); 891 regexp, factory->ignore_case_string(), ignore_case, final).Check();
895 JSObject::SetOwnPropertyIgnoreAttributes( 892 JSObject::SetOwnPropertyIgnoreAttributes(
896 regexp, factory->multiline_string(), multiline, final).Check(); 893 regexp, factory->multiline_string(), multiline, final).Check();
897 if (FLAG_harmony_regexps) { 894 if (FLAG_harmony_regexps) {
898 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->sticky_string(), 895 JSObject::SetOwnPropertyIgnoreAttributes(regexp, factory->sticky_string(),
899 sticky, final).Check(); 896 sticky, final).Check();
900 } 897 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 1112
1116 1113
1117 RUNTIME_FUNCTION(RuntimeReference_IsRegExp) { 1114 RUNTIME_FUNCTION(RuntimeReference_IsRegExp) {
1118 SealHandleScope shs(isolate); 1115 SealHandleScope shs(isolate);
1119 DCHECK(args.length() == 1); 1116 DCHECK(args.length() == 1);
1120 CONVERT_ARG_CHECKED(Object, obj, 0); 1117 CONVERT_ARG_CHECKED(Object, obj, 0);
1121 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); 1118 return isolate->heap()->ToBoolean(obj->IsJSRegExp());
1122 } 1119 }
1123 } 1120 }
1124 } // namespace v8::internal 1121 } // namespace v8::internal
OLDNEW
« src/accessors.cc ('K') | « src/objects.cc ('k') | test/mjsunit/compiler/literals.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698