| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Handle<Object> match; | 129 Handle<Object> match; |
| 130 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 130 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 131 isolate, match, | 131 isolate, match, |
| 132 JSObject::GetProperty(receiver, isolate->factory()->match_symbol()), | 132 JSObject::GetProperty(receiver, isolate->factory()->match_symbol()), |
| 133 Nothing<bool>()); | 133 Nothing<bool>()); |
| 134 | 134 |
| 135 if (!match->IsUndefined(isolate)) return Just(match->BooleanValue()); | 135 if (!match->IsUndefined(isolate)) return Just(match->BooleanValue()); |
| 136 return Just(object->IsJSRegExp()); | 136 return Just(object->IsJSRegExp()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool RegExpUtils::IsBuiltinExec(Handle<Object> exec) { | 139 bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle<Object> obj) { |
| 140 if (!exec->IsJSFunction()) return false; | 140 // TODO(ishell): Update this check once map changes for constant field |
| 141 // tracking are landing. |
| 141 | 142 |
| 142 Code* code = Handle<JSFunction>::cast(exec)->code(); | 143 if (!obj->IsJSReceiver()) return false; |
| 143 if (code == nullptr) return false; | |
| 144 | 144 |
| 145 return (code->builtin_index() == Builtins::kRegExpPrototypeExec); | 145 JSReceiver* recv = JSReceiver::cast(*obj); |
| 146 |
| 147 // Check the receiver's map. |
| 148 Handle<JSFunction> regexp_function = isolate->regexp_function(); |
| 149 if (recv->map() != regexp_function->initial_map()) return false; |
| 150 |
| 151 // Check the receiver's prototype's map. |
| 152 Object* proto = recv->map()->prototype(); |
| 153 if (!proto->IsJSReceiver()) return false; |
| 154 |
| 155 Handle<Map> initial_proto_initial_map = isolate->regexp_prototype_map(); |
| 156 return (JSReceiver::cast(proto)->map() == *initial_proto_initial_map); |
| 146 } | 157 } |
| 147 | 158 |
| 148 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string, | 159 int RegExpUtils::AdvanceStringIndex(Isolate* isolate, Handle<String> string, |
| 149 int index, bool unicode) { | 160 int index, bool unicode) { |
| 150 if (unicode && index < string->length()) { | 161 if (unicode && index < string->length()) { |
| 151 const uint16_t first = string->Get(index); | 162 const uint16_t first = string->Get(index); |
| 152 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) { | 163 if (first >= 0xD800 && first <= 0xDBFF && string->length() > index + 1) { |
| 153 const uint16_t second = string->Get(index + 1); | 164 const uint16_t second = string->Get(index + 1); |
| 154 if (second >= 0xDC00 && second <= 0xDFFF) { | 165 if (second >= 0xDC00 && second <= 0xDFFF) { |
| 155 return index + 2; | 166 return index + 2; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 | 185 |
| 175 const int last_index = Handle<Smi>::cast(last_index_obj)->value(); | 186 const int last_index = Handle<Smi>::cast(last_index_obj)->value(); |
| 176 const int new_last_index = | 187 const int new_last_index = |
| 177 AdvanceStringIndex(isolate, string, last_index, unicode); | 188 AdvanceStringIndex(isolate, string, last_index, unicode); |
| 178 | 189 |
| 179 return SetLastIndex(isolate, regexp, new_last_index); | 190 return SetLastIndex(isolate, regexp, new_last_index); |
| 180 } | 191 } |
| 181 | 192 |
| 182 } // namespace internal | 193 } // namespace internal |
| 183 } // namespace v8 | 194 } // namespace v8 |
| OLD | NEW |