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

Side by Side Diff: src/objects.cc

Issue 2137033002: [regexp] Fix regexp source escaping with preceding backslashes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix tests Created 4 years, 5 months 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-3229.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 15858 matching lines...) Expand 10 before | Expand all | Expand 10 after
15869 return Handle<JSRegExp>::cast(isolate->factory()->CopyJSObject(regexp)); 15869 return Handle<JSRegExp>::cast(isolate->factory()->CopyJSObject(regexp));
15870 } 15870 }
15871 15871
15872 15872
15873 template <typename Char> 15873 template <typename Char>
15874 inline int CountRequiredEscapes(Handle<String> source) { 15874 inline int CountRequiredEscapes(Handle<String> source) {
15875 DisallowHeapAllocation no_gc; 15875 DisallowHeapAllocation no_gc;
15876 int escapes = 0; 15876 int escapes = 0;
15877 Vector<const Char> src = source->GetCharVector<Char>(); 15877 Vector<const Char> src = source->GetCharVector<Char>();
15878 for (int i = 0; i < src.length(); i++) { 15878 for (int i = 0; i < src.length(); i++) {
15879 if (src[i] == '/' && (i == 0 || src[i - 1] != '\\')) escapes++; 15879 if (src[i] == '\\') {
15880 // Escape. Skip next character;
15881 i++;
15882 } else if (src[i] == '/') {
15883 // Not escaped forward-slash needs escape.
15884 escapes++;
15885 }
15880 } 15886 }
15881 return escapes; 15887 return escapes;
15882 } 15888 }
15883 15889
15884 15890
15885 template <typename Char, typename StringType> 15891 template <typename Char, typename StringType>
15886 inline Handle<StringType> WriteEscapedRegExpSource(Handle<String> source, 15892 inline Handle<StringType> WriteEscapedRegExpSource(Handle<String> source,
15887 Handle<StringType> result) { 15893 Handle<StringType> result) {
15888 DisallowHeapAllocation no_gc; 15894 DisallowHeapAllocation no_gc;
15889 Vector<const Char> src = source->GetCharVector<Char>(); 15895 Vector<const Char> src = source->GetCharVector<Char>();
15890 Vector<Char> dst(result->GetChars(), result->length()); 15896 Vector<Char> dst(result->GetChars(), result->length());
15891 int s = 0; 15897 int s = 0;
15892 int d = 0; 15898 int d = 0;
15893 while (s < src.length()) { 15899 while (s < src.length()) {
15894 if (src[s] == '/' && (s == 0 || src[s - 1] != '\\')) dst[d++] = '\\'; 15900 if (src[s] == '\\') {
15901 // Escape. Copy this and next character.
15902 dst[d++] = src[s++];
15903 if (s == src.length()) break;
15904 } else if (src[s] == '/') {
15905 // Not escaped forward-slash needs escape.
15906 dst[d++] = '\\';
15907 }
15895 dst[d++] = src[s++]; 15908 dst[d++] = src[s++];
15896 } 15909 }
15897 DCHECK_EQ(result->length(), d); 15910 DCHECK_EQ(result->length(), d);
15898 return result; 15911 return result;
15899 } 15912 }
15900 15913
15901 15914
15902 MaybeHandle<String> EscapeRegExpSource(Isolate* isolate, 15915 MaybeHandle<String> EscapeRegExpSource(Isolate* isolate,
15903 Handle<String> source) { 15916 Handle<String> source) {
15904 String::Flatten(source); 15917 String::Flatten(source);
(...skipping 3037 matching lines...) Expand 10 before | Expand all | Expand 10 after
18942 18955
18943 Object* data_obj = 18956 Object* data_obj =
18944 constructor->shared()->get_api_func_data()->access_check_info(); 18957 constructor->shared()->get_api_func_data()->access_check_info();
18945 if (data_obj->IsUndefined(isolate)) return nullptr; 18958 if (data_obj->IsUndefined(isolate)) return nullptr;
18946 18959
18947 return AccessCheckInfo::cast(data_obj); 18960 return AccessCheckInfo::cast(data_obj);
18948 } 18961 }
18949 18962
18950 } // namespace internal 18963 } // namespace internal
18951 } // namespace v8 18964 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-3229.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698