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/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 | 7 |
8 #include "src/string-builder.h" | 8 #include "src/string-builder.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 Handle<JSObject> object; | 142 Handle<JSObject> object; |
143 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 143 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
144 isolate, object, JSObject::New(target, new_target_receiver)); | 144 isolate, object, JSObject::New(target, new_target_receiver)); |
145 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(object); | 145 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(object); |
146 | 146 |
147 RETURN_RESULT_OR_FAILURE(isolate, | 147 RETURN_RESULT_OR_FAILURE(isolate, |
148 RegExpInitialize(isolate, regexp, pattern, flags)); | 148 RegExpInitialize(isolate, regexp, pattern, flags)); |
149 } | 149 } |
150 | 150 |
| 151 BUILTIN(RegExpPrototypeCompile) { |
| 152 HandleScope scope(isolate); |
| 153 CHECK_RECEIVER(JSRegExp, regexp, "RegExp.prototype.compile"); |
| 154 |
| 155 Handle<Object> pattern = args.atOrUndefined(isolate, 1); |
| 156 Handle<Object> flags = args.atOrUndefined(isolate, 2); |
| 157 |
| 158 if (pattern->IsJSRegExp()) { |
| 159 Handle<JSRegExp> pattern_regexp = Handle<JSRegExp>::cast(pattern); |
| 160 |
| 161 if (!flags->IsUndefined(isolate)) { |
| 162 THROW_NEW_ERROR_RETURN_FAILURE( |
| 163 isolate, NewTypeError(MessageTemplate::kRegExpFlags)); |
| 164 } |
| 165 |
| 166 flags = PatternFlags(isolate, pattern_regexp); |
| 167 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 168 isolate, pattern, |
| 169 Object::GetProperty(pattern, isolate->factory()->source_string())); |
| 170 } |
| 171 |
| 172 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 173 isolate, regexp, RegExpInitialize(isolate, regexp, pattern, flags)); |
| 174 |
| 175 // Return undefined for compatibility with JSC. |
| 176 // See http://crbug.com/585775 for web compat details. |
| 177 |
| 178 return isolate->heap()->undefined_value(); |
| 179 } |
| 180 |
151 #define APPEND_CHAR_FOR_FLAG(flag, c) \ | 181 #define APPEND_CHAR_FOR_FLAG(flag, c) \ |
152 do { \ | 182 do { \ |
153 Handle<Object> property; \ | 183 Handle<Object> property; \ |
154 Handle<Name> name = isolate->factory()->flag##_string(); \ | 184 Handle<Name> name = isolate->factory()->flag##_string(); \ |
155 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, property, \ | 185 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, property, \ |
156 JSReceiver::GetProperty(recv, name)); \ | 186 JSReceiver::GetProperty(recv, name)); \ |
157 if (property->BooleanValue()) { \ | 187 if (property->BooleanValue()) { \ |
158 builder.AppendCharacter(c); \ | 188 builder.AppendCharacter(c); \ |
159 } \ | 189 } \ |
160 } while (false); | 190 } while (false); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 THROW_NEW_ERROR_RETURN_FAILURE( | 222 THROW_NEW_ERROR_RETURN_FAILURE( |
193 isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, | 223 isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, |
194 isolate->factory()->NewStringFromAsciiChecked( | 224 isolate->factory()->NewStringFromAsciiChecked( |
195 "RegExp.prototype.source"))); | 225 "RegExp.prototype.source"))); |
196 } | 226 } |
197 | 227 |
198 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); | 228 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); |
199 return regexp->source(); | 229 return regexp->source(); |
200 } | 230 } |
201 | 231 |
| 232 BUILTIN(RegExpPrototypeToString) { |
| 233 HandleScope scope(isolate); |
| 234 CHECK_RECEIVER(JSReceiver, recv, "RegExp.prototype.toString"); |
| 235 |
| 236 if (*recv == isolate->regexp_function()->prototype()) { |
| 237 isolate->CountUsage(v8::Isolate::kRegExpPrototypeToString); |
| 238 } |
| 239 |
| 240 IncrementalStringBuilder builder(isolate); |
| 241 |
| 242 builder.AppendCharacter('/'); |
| 243 { |
| 244 Handle<Object> source; |
| 245 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 246 isolate, source, |
| 247 JSReceiver::GetProperty(recv, isolate->factory()->source_string())); |
| 248 Handle<String> source_str; |
| 249 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source_str, |
| 250 Object::ToString(isolate, source)); |
| 251 builder.AppendString(source_str); |
| 252 } |
| 253 |
| 254 builder.AppendCharacter('/'); |
| 255 { |
| 256 Handle<Object> flags; |
| 257 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 258 isolate, flags, |
| 259 JSReceiver::GetProperty(recv, isolate->factory()->flags_string())); |
| 260 Handle<String> flags_str; |
| 261 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, flags_str, |
| 262 Object::ToString(isolate, flags)); |
| 263 builder.AppendString(flags_str); |
| 264 } |
| 265 |
| 266 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
| 267 } |
| 268 |
202 // ES6 21.2.4.2. | 269 // ES6 21.2.4.2. |
203 BUILTIN(RegExpPrototypeSpeciesGetter) { | 270 BUILTIN(RegExpPrototypeSpeciesGetter) { |
204 HandleScope scope(isolate); | 271 HandleScope scope(isolate); |
205 return *args.receiver(); | 272 return *args.receiver(); |
206 } | 273 } |
207 | 274 |
208 #define REGEXP_FLAG_GETTER(name, counter, getter) \ | 275 #define REGEXP_FLAG_GETTER(name, counter, getter) \ |
209 BUILTIN(RegExpPrototype##name##Getter) { \ | 276 BUILTIN(RegExpPrototype##name##Getter) { \ |
210 HandleScope scope(isolate); \ | 277 HandleScope scope(isolate); \ |
211 Handle<Object> recv = args.receiver(); \ | 278 Handle<Object> recv = args.receiver(); \ |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 BUILTIN(RegExpPrototypeRightContextGetter) { | 454 BUILTIN(RegExpPrototypeRightContextGetter) { |
388 HandleScope scope(isolate); | 455 HandleScope scope(isolate); |
389 const int start_index = GetLastMatchCapture(isolate, 1); | 456 const int start_index = GetLastMatchCapture(isolate, 1); |
390 Handle<String> last_subject = GetLastMatchSubject(isolate); | 457 Handle<String> last_subject = GetLastMatchSubject(isolate); |
391 const int len = last_subject->length(); | 458 const int len = last_subject->length(); |
392 return *isolate->factory()->NewSubString(last_subject, start_index, len); | 459 return *isolate->factory()->NewSubString(last_subject, start_index, len); |
393 } | 460 } |
394 | 461 |
395 } // namespace internal | 462 } // namespace internal |
396 } // namespace v8 | 463 } // namespace v8 |
OLD | NEW |