OLD | NEW |
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 <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 16093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16104 } | 16104 } |
16105 dst[d++] = src[s++]; | 16105 dst[d++] = src[s++]; |
16106 } | 16106 } |
16107 DCHECK_EQ(result->length(), d); | 16107 DCHECK_EQ(result->length(), d); |
16108 return result; | 16108 return result; |
16109 } | 16109 } |
16110 | 16110 |
16111 | 16111 |
16112 MaybeHandle<String> EscapeRegExpSource(Isolate* isolate, | 16112 MaybeHandle<String> EscapeRegExpSource(Isolate* isolate, |
16113 Handle<String> source) { | 16113 Handle<String> source) { |
16114 String::Flatten(source); | 16114 DCHECK(source->IsFlat()); |
16115 if (source->length() == 0) return isolate->factory()->query_colon_string(); | 16115 if (source->length() == 0) return isolate->factory()->query_colon_string(); |
16116 bool one_byte = source->IsOneByteRepresentationUnderneath(); | 16116 bool one_byte = source->IsOneByteRepresentationUnderneath(); |
16117 int escapes = one_byte ? CountRequiredEscapes<uint8_t>(source) | 16117 int escapes = one_byte ? CountRequiredEscapes<uint8_t>(source) |
16118 : CountRequiredEscapes<uc16>(source); | 16118 : CountRequiredEscapes<uc16>(source); |
16119 if (escapes == 0) return source; | 16119 if (escapes == 0) return source; |
16120 int length = source->length() + escapes; | 16120 int length = source->length() + escapes; |
16121 if (one_byte) { | 16121 if (one_byte) { |
16122 Handle<SeqOneByteString> result; | 16122 Handle<SeqOneByteString> result; |
16123 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, | 16123 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, |
16124 isolate->factory()->NewRawOneByteString(length), | 16124 isolate->factory()->NewRawOneByteString(length), |
(...skipping 28 matching lines...) Expand all Loading... |
16153 | 16153 |
16154 // static | 16154 // static |
16155 MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp, | 16155 MaybeHandle<JSRegExp> JSRegExp::Initialize(Handle<JSRegExp> regexp, |
16156 Handle<String> source, Flags flags) { | 16156 Handle<String> source, Flags flags) { |
16157 Isolate* isolate = regexp->GetIsolate(); | 16157 Isolate* isolate = regexp->GetIsolate(); |
16158 Factory* factory = isolate->factory(); | 16158 Factory* factory = isolate->factory(); |
16159 // If source is the empty string we set it to "(?:)" instead as | 16159 // If source is the empty string we set it to "(?:)" instead as |
16160 // suggested by ECMA-262, 5th, section 15.10.4.1. | 16160 // suggested by ECMA-262, 5th, section 15.10.4.1. |
16161 if (source->length() == 0) source = factory->query_colon_string(); | 16161 if (source->length() == 0) source = factory->query_colon_string(); |
16162 | 16162 |
| 16163 source = String::Flatten(source); |
| 16164 |
16163 Handle<String> escaped_source; | 16165 Handle<String> escaped_source; |
16164 ASSIGN_RETURN_ON_EXCEPTION(isolate, escaped_source, | 16166 ASSIGN_RETURN_ON_EXCEPTION(isolate, escaped_source, |
16165 EscapeRegExpSource(isolate, source), JSRegExp); | 16167 EscapeRegExpSource(isolate, source), JSRegExp); |
16166 | 16168 |
16167 RETURN_ON_EXCEPTION(isolate, RegExpImpl::Compile(regexp, source, flags), | 16169 RETURN_ON_EXCEPTION(isolate, RegExpImpl::Compile(regexp, source, flags), |
16168 JSRegExp); | 16170 JSRegExp); |
16169 | 16171 |
16170 regexp->set_source(*escaped_source); | 16172 regexp->set_source(*escaped_source); |
16171 regexp->set_flags(Smi::FromInt(flags)); | 16173 regexp->set_flags(Smi::FromInt(flags)); |
16172 | 16174 |
(...skipping 4061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20234 // depend on this. | 20236 // depend on this. |
20235 return DICTIONARY_ELEMENTS; | 20237 return DICTIONARY_ELEMENTS; |
20236 } | 20238 } |
20237 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20239 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20238 return kind; | 20240 return kind; |
20239 } | 20241 } |
20240 } | 20242 } |
20241 | 20243 |
20242 } // namespace internal | 20244 } // namespace internal |
20243 } // namespace v8 | 20245 } // namespace v8 |
OLD | NEW |