[builtins] Port Regexp exec to Torque
Bug: v8:8976 Change-Id: Iede3b662188392303949edf2a9f0c585976695ab Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1806100 Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#63851}
This commit is contained in:
parent
9849000141
commit
84d724deda
1
BUILD.gn
1
BUILD.gn
@ -994,6 +994,7 @@ torque_files = [
|
||||
"src/builtins/proxy-set-prototype-of.tq",
|
||||
"src/builtins/proxy.tq",
|
||||
"src/builtins/reflect.tq",
|
||||
"src/builtins/regexp-exec.tq",
|
||||
"src/builtins/regexp-match.tq",
|
||||
"src/builtins/regexp-replace.tq",
|
||||
"src/builtins/regexp-search.tq",
|
||||
|
@ -847,8 +847,6 @@ namespace internal {
|
||||
CPP(RegExpLeftContextGetter) \
|
||||
/* ES #sec-regexp.prototype.compile */ \
|
||||
TFJ(RegExpPrototypeCompile, 2, kReceiver, kPattern, kFlags) \
|
||||
/* ES #sec-regexp.prototype.exec */ \
|
||||
TFJ(RegExpPrototypeExec, 1, kReceiver, kString) \
|
||||
/* https://tc39.github.io/proposal-string-matchall/ */ \
|
||||
TFJ(RegExpPrototypeMatchAll, 1, kReceiver, kString) \
|
||||
CPP(RegExpPrototypeToString) \
|
||||
@ -858,7 +856,6 @@ namespace internal {
|
||||
TFS(RegExpExecAtom, kRegExp, kString, kLastIndex, kMatchInfo) \
|
||||
TFS(RegExpExecInternal, kRegExp, kString, kLastIndex, kMatchInfo) \
|
||||
ASM(RegExpInterpreterTrampoline, CCall) \
|
||||
TFS(RegExpPrototypeExecSlow, kReceiver, kString) \
|
||||
\
|
||||
/* RegExp String Iterator */ \
|
||||
/* https://tc39.github.io/proposal-string-matchall/ */ \
|
||||
|
@ -1070,15 +1070,6 @@ void RegExpBuiltinsAssembler::BranchIfFastRegExpResult(
|
||||
if_ismodified);
|
||||
}
|
||||
|
||||
// Slow path stub for RegExpPrototypeExec to decrease code size.
|
||||
TF_BUILTIN(RegExpPrototypeExecSlow, RegExpBuiltinsAssembler) {
|
||||
TNode<JSRegExp> regexp = CAST(Parameter(Descriptor::kReceiver));
|
||||
TNode<String> string = CAST(Parameter(Descriptor::kString));
|
||||
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
|
||||
|
||||
Return(RegExpPrototypeExecBody(context, regexp, string, false));
|
||||
}
|
||||
|
||||
// Fast path stub for ATOM regexps. String matching is done by StringIndexOf,
|
||||
// and {match_info} is updated on success.
|
||||
// The slow path is implemented in RegExp::AtomExec.
|
||||
@ -1158,33 +1149,6 @@ TF_BUILTIN(RegExpExecInternal, RegExpBuiltinsAssembler) {
|
||||
Return(RegExpExecInternal(context, regexp, string, last_index, match_info));
|
||||
}
|
||||
|
||||
// ES#sec-regexp.prototype.exec
|
||||
// RegExp.prototype.exec ( string )
|
||||
TF_BUILTIN(RegExpPrototypeExec, RegExpBuiltinsAssembler) {
|
||||
TNode<Object> maybe_receiver = CAST(Parameter(Descriptor::kReceiver));
|
||||
TNode<Object> maybe_string = CAST(Parameter(Descriptor::kString));
|
||||
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
|
||||
|
||||
// Ensure {maybe_receiver} is a JSRegExp.
|
||||
ThrowIfNotInstanceType(context, maybe_receiver, JS_REGEXP_TYPE,
|
||||
"RegExp.prototype.exec");
|
||||
TNode<JSRegExp> receiver = CAST(maybe_receiver);
|
||||
|
||||
// Convert {maybe_string} to a String.
|
||||
TNode<String> string = ToString_Inline(context, maybe_string);
|
||||
|
||||
Label if_isfastpath(this), if_isslowpath(this);
|
||||
Branch(IsFastRegExpNoPrototype(context, receiver), &if_isfastpath,
|
||||
&if_isslowpath);
|
||||
|
||||
BIND(&if_isfastpath);
|
||||
Return(RegExpPrototypeExecBody(context, receiver, string, true));
|
||||
|
||||
BIND(&if_isslowpath);
|
||||
Return(CallBuiltin(Builtins::kRegExpPrototypeExecSlow, context, receiver,
|
||||
string));
|
||||
}
|
||||
|
||||
TNode<String> RegExpBuiltinsAssembler::FlagsGetter(TNode<Context> context,
|
||||
TNode<Object> regexp,
|
||||
bool is_fastpath) {
|
||||
|
45
src/builtins/regexp-exec.tq
Normal file
45
src/builtins/regexp-exec.tq
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2019 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include 'src/builtins/builtins-regexp-gen.h'
|
||||
|
||||
namespace regexp {
|
||||
|
||||
extern transitioning macro RegExpBuiltinsAssembler::RegExpPrototypeExecBody(
|
||||
implicit context: Context)(JSReceiver, String, constexpr bool): JSAny;
|
||||
|
||||
transitioning macro RegExpPrototypeExecBodyFast(implicit context: Context)(
|
||||
receiver: JSReceiver, string: String): JSAny {
|
||||
return RegExpPrototypeExecBody(receiver, string, true);
|
||||
}
|
||||
|
||||
transitioning macro RegExpPrototypeExecBodySlow(implicit context: Context)(
|
||||
receiver: JSReceiver, string: String): JSAny {
|
||||
return RegExpPrototypeExecBody(receiver, string, false);
|
||||
}
|
||||
|
||||
// Slow path stub for RegExpPrototypeExec to decrease code size.
|
||||
transitioning builtin
|
||||
RegExpPrototypeExecSlow(implicit context: Context)(
|
||||
regexp: JSRegExp, string: String): JSAny {
|
||||
return RegExpPrototypeExecBodySlow(regexp, string);
|
||||
}
|
||||
|
||||
extern macro RegExpBuiltinsAssembler::IsFastRegExpNoPrototype(
|
||||
implicit context: Context)(Object): bool;
|
||||
|
||||
// ES#sec-regexp.prototype.exec
|
||||
// RegExp.prototype.exec ( string )
|
||||
transitioning javascript builtin RegExpPrototypeExec(
|
||||
js-implicit context: Context, receiver: JSAny)(string: JSAny): JSAny {
|
||||
// Ensure {receiver} is a JSRegExp.
|
||||
const receiver = Cast<JSRegExp>(receiver) otherwise ThrowTypeError(
|
||||
kIncompatibleMethodReceiver, 'RegExp.prototype.exec', receiver);
|
||||
const string = ToString_Inline(context, string);
|
||||
|
||||
return IsFastRegExpNoPrototype(receiver) ?
|
||||
RegExpPrototypeExecBodyFast(receiver, string) :
|
||||
RegExpPrototypeExecSlow(receiver, string);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user