Commit 74996b4e authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[builtins] Port IsRegExp function to Torque

Bug: v8:8976
Change-Id: I7b215adda82f9982d38e35ab5c80c86eeca81487
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1856921
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64279}
parent d518f6da
...@@ -1450,6 +1450,7 @@ extern macro EmptyStringConstant(): EmptyString; ...@@ -1450,6 +1450,7 @@ extern macro EmptyStringConstant(): EmptyString;
extern macro LengthStringConstant(): String; extern macro LengthStringConstant(): String;
extern macro NanConstant(): NaN; extern macro NanConstant(): NaN;
extern macro IteratorSymbolConstant(): Symbol; extern macro IteratorSymbolConstant(): Symbol;
extern macro MatchSymbolConstant(): Symbol;
const TheHole: TheHole = TheHoleConstant(); const TheHole: TheHole = TheHoleConstant();
const Null: Null = NullConstant(); const Null: Null = NullConstant();
......
...@@ -1237,56 +1237,6 @@ TNode<String> RegExpBuiltinsAssembler::FlagsGetter(TNode<Context> context, ...@@ -1237,56 +1237,6 @@ TNode<String> RegExpBuiltinsAssembler::FlagsGetter(TNode<Context> context,
} }
} }
// ES#sec-isregexp IsRegExp ( argument )
TNode<BoolT> RegExpBuiltinsAssembler::IsRegExp(TNode<Context> context,
TNode<Object> maybe_receiver) {
Label out(this), if_isregexp(this);
TVARIABLE(BoolT, var_result, Int32FalseConstant());
GotoIf(TaggedIsSmi(maybe_receiver), &out);
GotoIfNot(IsJSReceiver(CAST(maybe_receiver)), &out);
TNode<JSReceiver> receiver = CAST(maybe_receiver);
// Check @@match.
{
TNode<Object> value =
GetProperty(context, receiver, isolate()->factory()->match_symbol());
Label match_isundefined(this), match_isnotundefined(this);
Branch(IsUndefined(value), &match_isundefined, &match_isnotundefined);
BIND(&match_isundefined);
Branch(IsJSRegExp(receiver), &if_isregexp, &out);
BIND(&match_isnotundefined);
Label match_istrueish(this), match_isfalseish(this);
BranchIfToBooleanIsTrue(value, &match_istrueish, &match_isfalseish);
// The common path. Symbol.match exists, equals the RegExpPrototypeMatch
// function (and is thus trueish), and the receiver is a JSRegExp.
BIND(&match_istrueish);
GotoIf(IsJSRegExp(receiver), &if_isregexp);
CallRuntime(Runtime::kIncrementUseCounter, context,
SmiConstant(v8::Isolate::kRegExpMatchIsTrueishOnNonJSRegExp));
Goto(&if_isregexp);
BIND(&match_isfalseish);
GotoIfNot(IsJSRegExp(receiver), &out);
CallRuntime(Runtime::kIncrementUseCounter, context,
SmiConstant(v8::Isolate::kRegExpMatchIsFalseishOnJSRegExp));
Goto(&out);
}
BIND(&if_isregexp);
var_result = Int32TrueConstant();
Goto(&out);
BIND(&out);
return var_result.value();
}
// ES#sec-regexpinitialize // ES#sec-regexpinitialize
// Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) // Runtime Semantics: RegExpInitialize ( obj, pattern, flags )
TNode<Object> RegExpBuiltinsAssembler::RegExpInitialize( TNode<Object> RegExpBuiltinsAssembler::RegExpInitialize(
......
...@@ -25,8 +25,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -25,8 +25,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map, TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map,
TNode<Object> regexp_string, TNode<String> flags); TNode<Object> regexp_string, TNode<String> flags);
TNode<BoolT> IsRegExp(TNode<Context> context, TNode<Object> maybe_receiver);
TNode<Smi> SmiZero(); TNode<Smi> SmiZero();
TNode<IntPtrT> IntPtrZero(); TNode<IntPtrT> IntPtrZero();
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
namespace regexp { namespace regexp {
const kRegExpPrototypeSourceGetter: constexpr int31
generates 'v8::Isolate::kRegExpPrototypeSourceGetter';
// ES6 21.2.5.10. // ES6 21.2.5.10.
// ES #sec-get-regexp.prototype.source // ES #sec-get-regexp.prototype.source
transitioning javascript builtin RegExpPrototypeSourceGetter( transitioning javascript builtin RegExpPrototypeSourceGetter(
......
...@@ -177,4 +177,43 @@ namespace regexp { ...@@ -177,4 +177,43 @@ namespace regexp {
RegExpBuiltinsAssembler::AdvanceStringIndexFast(String, Smi, bool): Smi; RegExpBuiltinsAssembler::AdvanceStringIndexFast(String, Smi, bool): Smi;
extern macro extern macro
RegExpBuiltinsAssembler::AdvanceStringIndexSlow(String, Number, bool): Smi; RegExpBuiltinsAssembler::AdvanceStringIndexSlow(String, Number, bool): Smi;
type UseCounterFeature extends int31
constexpr 'v8::Isolate::UseCounterFeature';
const kRegExpMatchIsTrueishOnNonJSRegExp: constexpr UseCounterFeature
generates 'v8::Isolate::kRegExpMatchIsTrueishOnNonJSRegExp';
const kRegExpMatchIsFalseishOnJSRegExp: constexpr UseCounterFeature
generates 'v8::Isolate::kRegExpMatchIsFalseishOnJSRegExp';
const kRegExpPrototypeSourceGetter: constexpr UseCounterFeature
generates 'v8::Isolate::kRegExpPrototypeSourceGetter';
// ES#sec-isregexp IsRegExp ( argument )
@export
transitioning macro IsRegExp(implicit context: Context)(obj: JSAny): bool {
const receiver = Cast<JSReceiver>(obj) otherwise return false;
// Check @match.
const value = GetProperty(receiver, MatchSymbolConstant());
if (value == Undefined) {
return Is<JSRegExp>(receiver);
}
assert(value != Undefined);
// The common path. Symbol.match exists, equals the RegExpPrototypeMatch
// function (and is thus trueish), and the receiver is a JSRegExp.
if (ToBoolean(value)) {
if (!Is<JSRegExp>(receiver)) {
IncrementUseCounter(
context, SmiConstant(kRegExpMatchIsTrueishOnNonJSRegExp));
}
return true;
}
assert(!ToBoolean(value));
if (Is<JSRegExp>(receiver)) {
IncrementUseCounter(
context, SmiConstant(kRegExpMatchIsFalseishOnJSRegExp));
}
return false;
}
} }
...@@ -41,7 +41,7 @@ namespace string { ...@@ -41,7 +41,7 @@ namespace string {
// 3. Let isRegExp be ? IsRegExp(searchString). // 3. Let isRegExp be ? IsRegExp(searchString).
// 4. If isRegExp is true, throw a TypeError exception. // 4. If isRegExp is true, throw a TypeError exception.
if (IsRegExp(searchString)) { if (regexp::IsRegExp(searchString)) {
ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName); ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName);
} }
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#include 'src/builtins/builtins-regexp-gen.h' #include 'src/builtins/builtins-regexp-gen.h'
namespace string { namespace string {
extern macro RegExpBuiltinsAssembler::IsRegExp(implicit context:
Context)(Object): bool;
// https://tc39.github.io/ecma262/#sec-string.prototype.startswith // https://tc39.github.io/ecma262/#sec-string.prototype.startswith
transitioning javascript builtin StringPrototypeStartsWith( transitioning javascript builtin StringPrototypeStartsWith(
js-implicit context: Context, receiver: JSAny)(...arguments): Boolean { js-implicit context: Context, receiver: JSAny)(...arguments): Boolean {
...@@ -23,7 +20,7 @@ namespace string { ...@@ -23,7 +20,7 @@ namespace string {
// 3. Let isRegExp be ? IsRegExp(searchString). // 3. Let isRegExp be ? IsRegExp(searchString).
// 4. If isRegExp is true, throw a TypeError exception. // 4. If isRegExp is true, throw a TypeError exception.
if (IsRegExp(searchString)) { if (regexp::IsRegExp(searchString)) {
ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName); ThrowTypeError(kFirstArgumentNotRegExp, kBuiltinName);
} }
......
...@@ -97,6 +97,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; ...@@ -97,6 +97,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol };
V(iterator_symbol, iterator_symbol, IteratorSymbol) \ V(iterator_symbol, iterator_symbol, IteratorSymbol) \
V(length_string, length_string, LengthString) \ V(length_string, length_string, LengthString) \
V(ManyClosuresCellMap, many_closures_cell_map, ManyClosuresCellMap) \ V(ManyClosuresCellMap, many_closures_cell_map, ManyClosuresCellMap) \
V(match_symbol, match_symbol, MatchSymbol) \
V(megamorphic_symbol, megamorphic_symbol, MegamorphicSymbol) \ V(megamorphic_symbol, megamorphic_symbol, MegamorphicSymbol) \
V(MetaMap, meta_map, MetaMap) \ V(MetaMap, meta_map, MetaMap) \
V(MinusZeroValue, minus_zero_value, MinusZero) \ V(MinusZeroValue, minus_zero_value, MinusZero) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment