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-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 | 7 |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/regexp/jsregexp.h" | 9 #include "src/regexp/jsregexp.h" |
| 10 #include "src/string-builder.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 | 14 |
14 // ----------------------------------------------------------------------------- | 15 // ----------------------------------------------------------------------------- |
15 // ES6 section 21.2 RegExp Objects | 16 // ES6 section 21.2 RegExp Objects |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // ES#sec-isregexp IsRegExp ( argument ) | 20 // ES#sec-isregexp IsRegExp ( argument ) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 Handle<JSObject> object; | 153 Handle<JSObject> object; |
153 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 154 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
154 isolate, object, JSObject::New(target, new_target_receiver)); | 155 isolate, object, JSObject::New(target, new_target_receiver)); |
155 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(object); | 156 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(object); |
156 | 157 |
157 RETURN_RESULT_OR_FAILURE(isolate, | 158 RETURN_RESULT_OR_FAILURE(isolate, |
158 RegExpInitialize(isolate, regexp, pattern, flags)); | 159 RegExpInitialize(isolate, regexp, pattern, flags)); |
159 } | 160 } |
160 | 161 |
| 162 BUILTIN(RegExpPrototypeCompile) { |
| 163 HandleScope scope(isolate); |
| 164 CHECK_RECEIVER(JSRegExp, regexp, "RegExp.prototype.compile"); |
| 165 |
| 166 Handle<Object> pattern = args.atOrUndefined(isolate, 1); |
| 167 Handle<Object> flags = args.atOrUndefined(isolate, 2); |
| 168 |
| 169 if (pattern->IsJSRegExp()) { |
| 170 Handle<JSRegExp> pattern_regexp = Handle<JSRegExp>::cast(pattern); |
| 171 |
| 172 if (!flags->IsUndefined(isolate)) { |
| 173 THROW_NEW_ERROR_RETURN_FAILURE( |
| 174 isolate, NewTypeError(MessageTemplate::kRegExpFlags)); |
| 175 } |
| 176 |
| 177 flags = PatternFlags(isolate, pattern_regexp); |
| 178 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 179 isolate, pattern, |
| 180 Object::GetProperty(pattern, isolate->factory()->source_string())); |
| 181 } |
| 182 |
| 183 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 184 isolate, regexp, RegExpInitialize(isolate, regexp, pattern, flags)); |
| 185 |
| 186 // Return undefined for compatibility with JSC. |
| 187 // See http://crbug.com/585775 for web compat details. |
| 188 |
| 189 return isolate->heap()->undefined_value(); |
| 190 } |
| 191 |
161 namespace { | 192 namespace { |
162 | 193 |
163 compiler::Node* LoadLastIndex(CodeStubAssembler* a, compiler::Node* context, | 194 compiler::Node* LoadLastIndex(CodeStubAssembler* a, compiler::Node* context, |
164 compiler::Node* has_initialmap, | 195 compiler::Node* has_initialmap, |
165 compiler::Node* regexp) { | 196 compiler::Node* regexp) { |
166 typedef CodeStubAssembler::Variable Variable; | 197 typedef CodeStubAssembler::Variable Variable; |
167 typedef CodeStubAssembler::Label Label; | 198 typedef CodeStubAssembler::Label Label; |
168 typedef compiler::Node Node; | 199 typedef compiler::Node Node; |
169 | 200 |
170 Variable var_value(a, MachineRepresentation::kTagged); | 201 Variable var_value(a, MachineRepresentation::kTagged); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 THROW_NEW_ERROR_RETURN_FAILURE( | 680 THROW_NEW_ERROR_RETURN_FAILURE( |
650 isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, | 681 isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, |
651 isolate->factory()->NewStringFromAsciiChecked( | 682 isolate->factory()->NewStringFromAsciiChecked( |
652 "RegExp.prototype.source"))); | 683 "RegExp.prototype.source"))); |
653 } | 684 } |
654 | 685 |
655 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); | 686 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); |
656 return regexp->source(); | 687 return regexp->source(); |
657 } | 688 } |
658 | 689 |
| 690 BUILTIN(RegExpPrototypeToString) { |
| 691 HandleScope scope(isolate); |
| 692 CHECK_RECEIVER(JSReceiver, recv, "RegExp.prototype.toString"); |
| 693 |
| 694 if (*recv == isolate->regexp_function()->prototype()) { |
| 695 isolate->CountUsage(v8::Isolate::kRegExpPrototypeToString); |
| 696 } |
| 697 |
| 698 IncrementalStringBuilder builder(isolate); |
| 699 |
| 700 builder.AppendCharacter('/'); |
| 701 { |
| 702 Handle<Object> source; |
| 703 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 704 isolate, source, |
| 705 JSReceiver::GetProperty(recv, isolate->factory()->source_string())); |
| 706 Handle<String> source_str; |
| 707 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, source_str, |
| 708 Object::ToString(isolate, source)); |
| 709 builder.AppendString(source_str); |
| 710 } |
| 711 |
| 712 builder.AppendCharacter('/'); |
| 713 { |
| 714 Handle<Object> flags; |
| 715 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 716 isolate, flags, |
| 717 JSReceiver::GetProperty(recv, isolate->factory()->flags_string())); |
| 718 Handle<String> flags_str; |
| 719 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, flags_str, |
| 720 Object::ToString(isolate, flags)); |
| 721 builder.AppendString(flags_str); |
| 722 } |
| 723 |
| 724 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); |
| 725 } |
| 726 |
659 // ES6 21.2.4.2. | 727 // ES6 21.2.4.2. |
660 BUILTIN(RegExpPrototypeSpeciesGetter) { | 728 BUILTIN(RegExpPrototypeSpeciesGetter) { |
661 HandleScope scope(isolate); | 729 HandleScope scope(isolate); |
662 return *args.receiver(); | 730 return *args.receiver(); |
663 } | 731 } |
664 | 732 |
665 namespace { | 733 namespace { |
666 | 734 |
667 void Generate_FlagGetter(CodeStubAssembler* a, JSRegExp::Flag flag, | 735 void Generate_FlagGetter(CodeStubAssembler* a, JSRegExp::Flag flag, |
668 v8::Isolate::UseCounterFeature counter, | 736 v8::Isolate::UseCounterFeature counter, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 BUILTIN(RegExpRightContextGetter) { | 971 BUILTIN(RegExpRightContextGetter) { |
904 HandleScope scope(isolate); | 972 HandleScope scope(isolate); |
905 const int start_index = GetLastMatchCapture(isolate, 1); | 973 const int start_index = GetLastMatchCapture(isolate, 1); |
906 Handle<String> last_subject = GetLastMatchSubject(isolate); | 974 Handle<String> last_subject = GetLastMatchSubject(isolate); |
907 const int len = last_subject->length(); | 975 const int len = last_subject->length(); |
908 return *isolate->factory()->NewSubString(last_subject, start_index, len); | 976 return *isolate->factory()->NewSubString(last_subject, start_index, len); |
909 } | 977 } |
910 | 978 |
911 } // namespace internal | 979 } // namespace internal |
912 } // namespace v8 | 980 } // namespace v8 |
OLD | NEW |