Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: src/builtins/builtins-regexp.cc

Issue 2537973004: [regexp] Move source and species getter to TF (Closed)
Patch Set: Simplify instance type check Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/regexp/regexp-utils.h" 10 #include "src/regexp/regexp-utils.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 CASE_FOR_FLAG(JSRegExp::kUnicode, 'u', label_unicode, label_sticky); 691 CASE_FOR_FLAG(JSRegExp::kUnicode, 'u', label_unicode, label_sticky);
692 CASE_FOR_FLAG(JSRegExp::kSticky, 'y', label_sticky, out); 692 CASE_FOR_FLAG(JSRegExp::kSticky, 'y', label_sticky, out);
693 #undef CASE_FOR_FLAG 693 #undef CASE_FOR_FLAG
694 694
695 a.Bind(&out); 695 a.Bind(&out);
696 a.Return(result); 696 a.Return(result);
697 } 697 }
698 } 698 }
699 699
700 // ES6 21.2.5.10. 700 // ES6 21.2.5.10.
701 BUILTIN(RegExpPrototypeSourceGetter) { 701 void Builtins::Generate_RegExpPrototypeSourceGetter(CodeAssemblerState* state) {
Camillo Bruni 2016/12/01 12:24:47 Could you migrate this to the new and much cleaner
Igor Sheludko 2016/12/01 12:29:53 This requires a separate CL.
Camillo Bruni 2016/12/01 14:02:57 probably cleaner that way.
jgruber 2016/12/01 14:18:38 Will do in a follow-up. Much cleaner indeed :)
702 HandleScope scope(isolate); 702 CodeStubAssembler a(state);
703 Node* const receiver = a.Parameter(0);
704 Node* const context = a.Parameter(3);
703 705
704 Handle<Object> recv = args.receiver(); 706 // Check whether we have an unmodified regexp instance.
705 if (!recv->IsJSRegExp()) { 707 CLabel if_isjsregexp(&a), if_isnotjsregexp(&a, CLabel::kDeferred);
706 Handle<JSFunction> regexp_fun = isolate->regexp_function(); 708
707 if (*recv == regexp_fun->prototype()) { 709 a.GotoIf(a.TaggedIsSmi(receiver), &if_isnotjsregexp);
708 isolate->CountUsage(v8::Isolate::kRegExpPrototypeSourceGetter); 710 a.Branch(a.HasInstanceType(receiver, JS_REGEXP_TYPE), &if_isjsregexp,
709 return *isolate->factory()->NewStringFromAsciiChecked("(?:)"); 711 &if_isnotjsregexp);
Camillo Bruni 2016/12/01 12:24:47 If you want to go the extra mile, you'd probably a
jgruber 2016/12/01 14:18:38 Acknowledged.
710 } 712
711 THROW_NEW_ERROR_RETURN_FAILURE( 713 a.Bind(&if_isjsregexp);
712 isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, 714 {
713 isolate->factory()->NewStringFromAsciiChecked( 715 Node* const source = a.LoadObjectField(receiver, JSRegExp::kSourceOffset);
714 "RegExp.prototype.source"))); 716 a.Return(source);
715 } 717 }
716 718
717 Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); 719 a.Bind(&if_isnotjsregexp);
718 return regexp->source(); 720 {
721 Isolate* isolate = a.isolate();
722 Node* const native_context = a.LoadNativeContext(context);
723 Node* const regexp_fun =
724 a.LoadContextElement(native_context, Context::REGEXP_FUNCTION_INDEX);
725 Node* const initial_map =
726 a.LoadObjectField(regexp_fun, JSFunction::kPrototypeOrInitialMapOffset);
Camillo Bruni 2016/12/01 12:24:47 this sequence of loading the default regexp's map
jgruber 2016/12/01 14:18:38 Acknowledged.
727 Node* const initial_prototype = a.LoadMapPrototype(initial_map);
728
729 CLabel if_isprototype(&a), if_isnotprototype(&a);
730 a.Branch(a.WordEqual(receiver, initial_prototype), &if_isprototype,
731 &if_isnotprototype);
732
733 a.Bind(&if_isprototype);
734 {
735 const int counter = v8::Isolate::kRegExpPrototypeSourceGetter;
736 Node* const counter_smi = a.SmiConstant(Smi::FromInt(counter));
Camillo Bruni 2016/12/01 12:24:47 nit: you can directly pass in the int to SmiConsta
jgruber 2016/12/01 14:18:38 Done.
737 a.CallRuntime(Runtime::kIncrementUseCounter, context, counter_smi);
738
739 Node* const result =
740 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("(?:)"));
741 a.Return(result);
742 }
743
744 a.Bind(&if_isnotprototype);
745 {
746 Node* const message_id =
747 a.SmiConstant(Smi::FromInt(MessageTemplate::kRegExpNonRegExp));
748 Node* const method_name_str =
749 a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked(
750 "RegExp.prototype.source"));
751 a.CallRuntime(Runtime::kThrowTypeError, context, message_id,
752 method_name_str);
753 a.Return(a.UndefinedConstant()); // Never reached.
Camillo Bruni 2016/12/01 12:24:47 Could you do a TailCallRuntime here?
jgruber 2016/12/01 14:18:38 Done.
754 }
755 }
719 } 756 }
720 757
721 BUILTIN(RegExpPrototypeToString) { 758 BUILTIN(RegExpPrototypeToString) {
722 HandleScope scope(isolate); 759 HandleScope scope(isolate);
723 CHECK_RECEIVER(JSReceiver, recv, "RegExp.prototype.toString"); 760 CHECK_RECEIVER(JSReceiver, recv, "RegExp.prototype.toString");
724 761
725 if (*recv == isolate->regexp_function()->prototype()) { 762 if (*recv == isolate->regexp_function()->prototype()) {
726 isolate->CountUsage(v8::Isolate::kRegExpPrototypeToString); 763 isolate->CountUsage(v8::Isolate::kRegExpPrototypeToString);
727 } 764 }
728 765
(...skipping 20 matching lines...) Expand all
749 Handle<String> flags_str; 786 Handle<String> flags_str;
750 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, flags_str, 787 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, flags_str,
751 Object::ToString(isolate, flags)); 788 Object::ToString(isolate, flags));
752 builder.AppendString(flags_str); 789 builder.AppendString(flags_str);
753 } 790 }
754 791
755 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish()); 792 RETURN_RESULT_OR_FAILURE(isolate, builder.Finish());
756 } 793 }
757 794
758 // ES6 21.2.4.2. 795 // ES6 21.2.4.2.
759 BUILTIN(RegExpPrototypeSpeciesGetter) { 796 void Builtins::Generate_RegExpPrototypeSpeciesGetter(
760 HandleScope scope(isolate); 797 CodeAssemblerState* state) {
Camillo Bruni 2016/12/01 12:24:47 ditto: please port to new builtins style
jgruber 2016/12/01 14:18:38 Acknowledged.
761 return *args.receiver(); 798 CodeStubAssembler a(state);
799 Node* const receiver = a.Parameter(0);
800 a.Return(receiver);
762 } 801 }
763 802
764 namespace { 803 namespace {
765 804
766 // Fast-path implementation for flag checks on an unmodified JSRegExp instance. 805 // Fast-path implementation for flag checks on an unmodified JSRegExp instance.
767 Node* FastFlagGetter(CodeStubAssembler* a, Node* const regexp, 806 Node* FastFlagGetter(CodeStubAssembler* a, Node* const regexp,
768 JSRegExp::Flag flag) { 807 JSRegExp::Flag flag) {
769 Node* const smi_zero = a->SmiConstant(Smi::kZero); 808 Node* const smi_zero = a->SmiConstant(Smi::kZero);
770 Node* const flags = a->LoadObjectField(regexp, JSRegExp::kFlagsOffset); 809 Node* const flags = a->LoadObjectField(regexp, JSRegExp::kFlagsOffset);
771 Node* const mask = a->SmiConstant(Smi::FromInt(flag)); 810 Node* const mask = a->SmiConstant(Smi::FromInt(flag));
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 a.Bind(&if_matched); 2405 a.Bind(&if_matched);
2367 { 2406 {
2368 Node* result = ConstructNewResultFromMatchInfo(isolate, &a, context, 2407 Node* result = ConstructNewResultFromMatchInfo(isolate, &a, context,
2369 match_indices, string); 2408 match_indices, string);
2370 a.Return(result); 2409 a.Return(result);
2371 } 2410 }
2372 } 2411 }
2373 2412
2374 } // namespace internal 2413 } // namespace internal
2375 } // namespace v8 2414 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698