OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/regexp/regexp-utils.h" | 5 #include "src/regexp/regexp-utils.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 #include "src/regexp/jsregexp.h" | 10 #include "src/regexp/jsregexp.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 bool RegExpUtils::IsBuiltinExec(Handle<Object> exec) { | 182 bool RegExpUtils::IsBuiltinExec(Handle<Object> exec) { |
183 if (!exec->IsJSFunction()) return false; | 183 if (!exec->IsJSFunction()) return false; |
184 | 184 |
185 Code* code = Handle<JSFunction>::cast(exec)->code(); | 185 Code* code = Handle<JSFunction>::cast(exec)->code(); |
186 if (code == nullptr) return false; | 186 if (code == nullptr) return false; |
187 | 187 |
188 return (code->builtin_index() == Builtins::kRegExpPrototypeExec); | 188 return (code->builtin_index() == Builtins::kRegExpPrototypeExec); |
189 } | 189 } |
190 | 190 |
191 // ES#sec-advancestringindex | |
192 // AdvanceStringIndex ( S, index, unicode ) | |
193 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string, | 191 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string, |
194 int index, bool unicode) { | 192 int index, bool unicode) { |
195 int increment = 1; | |
196 | |
197 if (unicode && index < string->length()) { | 193 if (unicode && index < string->length()) { |
198 const uint16_t first = string->Get(index); | 194 const uint16_t first = string->Get(index); |
199 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) { | 195 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) { |
200 const uint16_t second = string->Get(index + 1); | 196 const uint16_t second = string->Get(index + 1); |
201 if (second >= 0xDC00 && second <= 0xDFFF) { | 197 if (second >= 0xDC00 && second <= 0xDFFF) { |
202 increment = 2; | 198 return index + 2; |
203 } | 199 } |
204 } | 200 } |
205 } | 201 } |
206 | 202 |
207 return increment; | 203 return index + 1; |
208 } | 204 } |
209 | 205 |
210 MaybeHandle<Object> RegExpUtils::SetAdvancedStringIndex( | 206 MaybeHandle<Object> RegExpUtils::SetAdvancedStringIndex( |
211 Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string, | 207 Isolate* isolate, Handle<JSReceiver> regexp, Handle<String> string, |
212 bool unicode) { | 208 bool unicode) { |
213 Handle<Object> last_index_obj; | 209 Handle<Object> last_index_obj; |
214 ASSIGN_RETURN_ON_EXCEPTION( | 210 ASSIGN_RETURN_ON_EXCEPTION( |
215 isolate, last_index_obj, | 211 isolate, last_index_obj, |
216 Object::GetProperty(regexp, isolate->factory()->lastIndex_string()), | 212 Object::GetProperty(regexp, isolate->factory()->lastIndex_string()), |
217 Object); | 213 Object); |
218 | 214 |
219 ASSIGN_RETURN_ON_EXCEPTION(isolate, last_index_obj, | 215 ASSIGN_RETURN_ON_EXCEPTION(isolate, last_index_obj, |
220 Object::ToLength(isolate, last_index_obj), Object); | 216 Object::ToLength(isolate, last_index_obj), Object); |
221 | 217 |
222 const int last_index = Handle<Smi>::cast(last_index_obj)->value(); | 218 const int last_index = Handle<Smi>::cast(last_index_obj)->value(); |
223 const int new_last_index = | 219 const int new_last_index = |
224 last_index + AdvanceStringIndex(isolate, string, last_index, unicode); | 220 AdvanceStringIndex(isolate, string, last_index, unicode); |
225 | 221 |
226 return SetLastIndex(isolate, regexp, new_last_index); | 222 return SetLastIndex(isolate, regexp, new_last_index); |
227 } | 223 } |
228 | 224 |
229 } // namespace internal | 225 } // namespace internal |
230 } // namespace v8 | 226 } // namespace v8 |
OLD | NEW |