OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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-regexp-gen.h" | 5 #include "src/builtins/builtins-regexp-gen.h" |
6 | 6 |
7 #include "src/builtins/builtins-constructor-gen.h" | 7 #include "src/builtins/builtins-constructor-gen.h" |
8 #include "src/builtins/builtins-utils-gen.h" | 8 #include "src/builtins/builtins-utils-gen.h" |
9 #include "src/builtins/builtins.h" | 9 #include "src/builtins/builtins.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 2419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 // The runtime call passes in limit to ensure the second ToUint32(limit) | 2430 // The runtime call passes in limit to ensure the second ToUint32(limit) |
2431 // call is not observable. | 2431 // call is not observable. |
2432 CSA_ASSERT(this, IsNumber(limit)); | 2432 CSA_ASSERT(this, IsNumber(limit)); |
2433 Return(CallRuntime(Runtime::kRegExpSplit, context, regexp, string, limit)); | 2433 Return(CallRuntime(Runtime::kRegExpSplit, context, regexp, string, limit)); |
2434 } | 2434 } |
2435 } | 2435 } |
2436 | 2436 |
2437 // ES#sec-regexp.prototype-@@split | 2437 // ES#sec-regexp.prototype-@@split |
2438 // RegExp.prototype [ @@split ] ( string, limit ) | 2438 // RegExp.prototype [ @@split ] ( string, limit ) |
2439 TF_BUILTIN(RegExpPrototypeSplit, RegExpBuiltinsAssembler) { | 2439 TF_BUILTIN(RegExpPrototypeSplit, RegExpBuiltinsAssembler) { |
2440 Node* const maybe_receiver = Parameter(Descriptor::kReceiver); | 2440 const int kStringArg = 0; |
2441 Node* const maybe_string = Parameter(Descriptor::kString); | 2441 const int kLimitArg = 1; |
2442 Node* const maybe_limit = Parameter(Descriptor::kLimit); | 2442 |
2443 Node* const context = Parameter(Descriptor::kContext); | 2443 Node* argc = |
| 2444 ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
| 2445 CodeStubArguments args(this, argc); |
| 2446 |
| 2447 Node* const maybe_receiver = args.GetReceiver(); |
| 2448 Node* const maybe_string = |
| 2449 args.GetOptionalArgumentValue(kStringArg, UndefinedConstant()); |
| 2450 Node* const maybe_limit = |
| 2451 args.GetOptionalArgumentValue(kLimitArg, UndefinedConstant()); |
| 2452 Node* const context = Parameter(BuiltinDescriptor::kContext); |
2444 | 2453 |
2445 // Ensure {maybe_receiver} is a JSReceiver. | 2454 // Ensure {maybe_receiver} is a JSReceiver. |
2446 ThrowIfNotJSReceiver(context, maybe_receiver, | 2455 ThrowIfNotJSReceiver(context, maybe_receiver, |
2447 MessageTemplate::kIncompatibleMethodReceiver, | 2456 MessageTemplate::kIncompatibleMethodReceiver, |
2448 "RegExp.prototype.@@split"); | 2457 "RegExp.prototype.@@split"); |
2449 Node* const receiver = maybe_receiver; | 2458 Node* const receiver = maybe_receiver; |
2450 | 2459 |
2451 // Convert {maybe_string} to a String. | 2460 // Convert {maybe_string} to a String. |
2452 Node* const string = ToString(context, maybe_string); | 2461 Node* const string = ToString(context, maybe_string); |
2453 | 2462 |
2454 Label stub(this), runtime(this, Label::kDeferred); | 2463 Label stub(this), runtime(this, Label::kDeferred); |
2455 BranchIfFastRegExp(context, receiver, &stub, &runtime); | 2464 BranchIfFastRegExp(context, receiver, &stub, &runtime); |
2456 | 2465 |
2457 BIND(&stub); | 2466 BIND(&stub); |
2458 Return(CallBuiltin(Builtins::kRegExpSplit, context, receiver, string, | 2467 args.PopAndReturn(CallBuiltin(Builtins::kRegExpSplit, context, receiver, |
2459 maybe_limit)); | 2468 string, maybe_limit)); |
2460 | 2469 |
2461 BIND(&runtime); | 2470 BIND(&runtime); |
2462 Return(CallRuntime(Runtime::kRegExpSplit, context, receiver, string, | 2471 args.PopAndReturn(CallRuntime(Runtime::kRegExpSplit, context, receiver, |
2463 maybe_limit)); | 2472 string, maybe_limit)); |
2464 } | 2473 } |
2465 | 2474 |
2466 Node* RegExpBuiltinsAssembler::ReplaceGlobalCallableFastPath( | 2475 Node* RegExpBuiltinsAssembler::ReplaceGlobalCallableFastPath( |
2467 Node* context, Node* regexp, Node* string, Node* replace_callable) { | 2476 Node* context, Node* regexp, Node* string, Node* replace_callable) { |
2468 // The fast path is reached only if {receiver} is a global unmodified | 2477 // The fast path is reached only if {receiver} is a global unmodified |
2469 // JSRegExp instance and {replace_callable} is callable. | 2478 // JSRegExp instance and {replace_callable} is callable. |
2470 | 2479 |
2471 CSA_ASSERT(this, IsFastRegExp(context, regexp)); | 2480 CSA_ASSERT(this, IsFastRegExp(context, regexp)); |
2472 CSA_ASSERT(this, IsCallable(replace_callable)); | 2481 CSA_ASSERT(this, IsCallable(replace_callable)); |
2473 CSA_ASSERT(this, IsString(string)); | 2482 CSA_ASSERT(this, IsString(string)); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 } | 2852 } |
2844 | 2853 |
2845 BIND(&runtime); | 2854 BIND(&runtime); |
2846 Return(CallRuntime(Runtime::kRegExpReplace, context, regexp, string, | 2855 Return(CallRuntime(Runtime::kRegExpReplace, context, regexp, string, |
2847 replace_value)); | 2856 replace_value)); |
2848 } | 2857 } |
2849 | 2858 |
2850 // ES#sec-regexp.prototype-@@replace | 2859 // ES#sec-regexp.prototype-@@replace |
2851 // RegExp.prototype [ @@replace ] ( string, replaceValue ) | 2860 // RegExp.prototype [ @@replace ] ( string, replaceValue ) |
2852 TF_BUILTIN(RegExpPrototypeReplace, RegExpBuiltinsAssembler) { | 2861 TF_BUILTIN(RegExpPrototypeReplace, RegExpBuiltinsAssembler) { |
2853 Node* const maybe_receiver = Parameter(Descriptor::kReceiver); | 2862 const int kStringArg = 0; |
2854 Node* const maybe_string = Parameter(Descriptor::kString); | 2863 const int kReplaceValueArg = 1; |
2855 Node* const replace_value = Parameter(Descriptor::kReplaceValue); | 2864 |
2856 Node* const context = Parameter(Descriptor::kContext); | 2865 Node* argc = |
| 2866 ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
| 2867 CodeStubArguments args(this, argc); |
| 2868 |
| 2869 Node* const maybe_receiver = args.GetReceiver(); |
| 2870 Node* const maybe_string = |
| 2871 args.GetOptionalArgumentValue(kStringArg, UndefinedConstant()); |
| 2872 Node* const replace_value = |
| 2873 args.GetOptionalArgumentValue(kReplaceValueArg, UndefinedConstant()); |
| 2874 Node* const context = Parameter(BuiltinDescriptor::kContext); |
2857 | 2875 |
2858 // RegExpPrototypeReplace is a bit of a beast - a summary of dispatch logic: | 2876 // RegExpPrototypeReplace is a bit of a beast - a summary of dispatch logic: |
2859 // | 2877 // |
2860 // if (!IsFastRegExp(receiver)) CallRuntime(RegExpReplace) | 2878 // if (!IsFastRegExp(receiver)) CallRuntime(RegExpReplace) |
2861 // if (IsCallable(replace)) { | 2879 // if (IsCallable(replace)) { |
2862 // if (IsGlobal(receiver)) { | 2880 // if (IsGlobal(receiver)) { |
2863 // // Called 'fast-path' but contains several runtime calls. | 2881 // // Called 'fast-path' but contains several runtime calls. |
2864 // ReplaceGlobalCallableFastPath() | 2882 // ReplaceGlobalCallableFastPath() |
2865 // } else { | 2883 // } else { |
2866 // CallRuntime(StringReplaceNonGlobalRegExpWithFunction) | 2884 // CallRuntime(StringReplaceNonGlobalRegExpWithFunction) |
(...skipping 13 matching lines...) Expand all Loading... |
2880 Node* const receiver = maybe_receiver; | 2898 Node* const receiver = maybe_receiver; |
2881 | 2899 |
2882 // Convert {maybe_string} to a String. | 2900 // Convert {maybe_string} to a String. |
2883 Node* const string = CallBuiltin(Builtins::kToString, context, maybe_string); | 2901 Node* const string = CallBuiltin(Builtins::kToString, context, maybe_string); |
2884 | 2902 |
2885 // Fast-path checks: 1. Is the {receiver} an unmodified JSRegExp instance? | 2903 // Fast-path checks: 1. Is the {receiver} an unmodified JSRegExp instance? |
2886 Label stub(this), runtime(this, Label::kDeferred); | 2904 Label stub(this), runtime(this, Label::kDeferred); |
2887 BranchIfFastRegExp(context, receiver, &stub, &runtime); | 2905 BranchIfFastRegExp(context, receiver, &stub, &runtime); |
2888 | 2906 |
2889 BIND(&stub); | 2907 BIND(&stub); |
2890 Return(CallBuiltin(Builtins::kRegExpReplace, context, receiver, string, | 2908 args.PopAndReturn(CallBuiltin(Builtins::kRegExpReplace, context, receiver, |
2891 replace_value)); | 2909 string, replace_value)); |
2892 | 2910 |
2893 BIND(&runtime); | 2911 BIND(&runtime); |
2894 Return(CallRuntime(Runtime::kRegExpReplace, context, receiver, string, | 2912 args.PopAndReturn(CallRuntime(Runtime::kRegExpReplace, context, receiver, |
2895 replace_value)); | 2913 string, replace_value)); |
2896 } | 2914 } |
2897 | 2915 |
2898 // Simple string matching functionality for internal use which does not modify | 2916 // Simple string matching functionality for internal use which does not modify |
2899 // the last match info. | 2917 // the last match info. |
2900 TF_BUILTIN(RegExpInternalMatch, RegExpBuiltinsAssembler) { | 2918 TF_BUILTIN(RegExpInternalMatch, RegExpBuiltinsAssembler) { |
2901 Node* const regexp = Parameter(Descriptor::kRegExp); | 2919 Node* const regexp = Parameter(Descriptor::kRegExp); |
2902 Node* const string = Parameter(Descriptor::kString); | 2920 Node* const string = Parameter(Descriptor::kString); |
2903 Node* const context = Parameter(Descriptor::kContext); | 2921 Node* const context = Parameter(Descriptor::kContext); |
2904 | 2922 |
2905 Node* const null = NullConstant(); | 2923 Node* const null = NullConstant(); |
(...skipping 18 matching lines...) Expand all Loading... |
2924 BIND(&if_matched); | 2942 BIND(&if_matched); |
2925 { | 2943 { |
2926 Node* result = | 2944 Node* result = |
2927 ConstructNewResultFromMatchInfo(context, regexp, match_indices, string); | 2945 ConstructNewResultFromMatchInfo(context, regexp, match_indices, string); |
2928 Return(result); | 2946 Return(result); |
2929 } | 2947 } |
2930 } | 2948 } |
2931 | 2949 |
2932 } // namespace internal | 2950 } // namespace internal |
2933 } // namespace v8 | 2951 } // namespace v8 |
OLD | NEW |