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

[builtins] Port some RegExp functions to Torque

IsReceiverInitialRegExpPrototype, RegExpCreate

Bug: v8:8976
Change-Id: If1d2598a2c2f302704c25aa65826fa442e6b79a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1866015
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64361}
parent 3cad6bf5
...@@ -139,28 +139,6 @@ TNode<JSRegExpResult> RegExpBuiltinsAssembler::AllocateRegExpResult( ...@@ -139,28 +139,6 @@ TNode<JSRegExpResult> RegExpBuiltinsAssembler::AllocateRegExpResult(
return result; return result;
} }
TNode<Object> RegExpBuiltinsAssembler::RegExpCreate(
TNode<Context> context, TNode<Context> native_context,
TNode<Object> maybe_string, TNode<String> flags) {
TNode<JSFunction> regexp_function =
CAST(LoadContextElement(native_context, Context::REGEXP_FUNCTION_INDEX));
TNode<Map> initial_map = CAST(LoadObjectField(
regexp_function, JSFunction::kPrototypeOrInitialMapOffset));
return RegExpCreate(context, initial_map, maybe_string, flags);
}
TNode<Object> RegExpBuiltinsAssembler::RegExpCreate(TNode<Context> context,
TNode<Map> initial_map,
TNode<Object> maybe_string,
TNode<String> flags) {
TNode<String> pattern = Select<String>(
IsUndefined(maybe_string), [=] { return EmptyStringConstant(); },
[=] { return ToString_Inline(context, maybe_string); });
TNode<JSObject> regexp = AllocateJSObjectFromMap(initial_map);
return CallRuntime(Runtime::kRegExpInitializeAndCompile, context, regexp,
pattern, flags);
}
TNode<Object> RegExpBuiltinsAssembler::FastLoadLastIndexBeforeSmiCheck( TNode<Object> RegExpBuiltinsAssembler::FastLoadLastIndexBeforeSmiCheck(
TNode<JSRegExp> regexp) { TNode<JSRegExp> regexp) {
// Load the in-object field. // Load the in-object field.
...@@ -897,18 +875,6 @@ TNode<HeapObject> RegExpBuiltinsAssembler::RegExpPrototypeExecBody( ...@@ -897,18 +875,6 @@ TNode<HeapObject> RegExpBuiltinsAssembler::RegExpPrototypeExecBody(
return var_result.value(); return var_result.value();
} }
TNode<BoolT> RegExpBuiltinsAssembler::IsReceiverInitialRegExpPrototype(
SloppyTNode<Context> context, SloppyTNode<Object> receiver) {
TNode<NativeContext> native_context = LoadNativeContext(context);
TNode<JSFunction> const regexp_fun =
CAST(LoadContextElement(native_context, Context::REGEXP_FUNCTION_INDEX));
TNode<Object> const initial_map =
LoadObjectField(regexp_fun, JSFunction::kPrototypeOrInitialMapOffset);
TNode<HeapObject> const initial_prototype =
LoadMapPrototype(CAST(initial_map));
return TaggedEqual(receiver, initial_prototype);
}
TNode<BoolT> RegExpBuiltinsAssembler::IsFastRegExpNoPrototype( TNode<BoolT> RegExpBuiltinsAssembler::IsFastRegExpNoPrototype(
TNode<Context> context, TNode<Object> object, TNode<Map> map) { TNode<Context> context, TNode<Object> object, TNode<Map> map) {
Label out(this); Label out(this);
......
...@@ -17,14 +17,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -17,14 +17,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
explicit RegExpBuiltinsAssembler(compiler::CodeAssemblerState* state) explicit RegExpBuiltinsAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {} : CodeStubAssembler(state) {}
// Create and initialize a RegExp object.
TNode<Object> RegExpCreate(TNode<Context> context,
TNode<Context> native_context,
TNode<Object> regexp_string, TNode<String> flags);
TNode<Object> RegExpCreate(TNode<Context> context, TNode<Map> initial_map,
TNode<Object> regexp_string, TNode<String> flags);
TNode<Smi> SmiZero(); TNode<Smi> SmiZero();
TNode<IntPtrT> IntPtrZero(); TNode<IntPtrT> IntPtrZero();
...@@ -85,9 +77,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler { ...@@ -85,9 +77,6 @@ class RegExpBuiltinsAssembler : public CodeStubAssembler {
TNode<String> string, TNode<String> string,
const bool is_fastpath); const bool is_fastpath);
TNode<BoolT> IsReceiverInitialRegExpPrototype(SloppyTNode<Context> context,
SloppyTNode<Object> receiver);
// Fast path check logic. // Fast path check logic.
// //
// Are you afraid? If not, you should be. // Are you afraid? If not, you should be.
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
namespace regexp { namespace regexp {
extern transitioning macro RegExpBuiltinsAssembler::RegExpCreate(
implicit context: Context)(Context, Object, String): Object;
extern transitioning macro extern transitioning macro
RegExpMatchAllAssembler::CreateRegExpStringIterator( RegExpMatchAllAssembler::CreateRegExpStringIterator(
NativeContext, Object, String, bool, bool): JSAny; NativeContext, Object, String, bool, bool): JSAny;
......
...@@ -56,8 +56,15 @@ namespace regexp { ...@@ -56,8 +56,15 @@ namespace regexp {
implicit context: Context)(JSRegExp, String): implicit context: Context)(JSRegExp, String):
RegExpMatchInfo labels IfDidNotMatch; RegExpMatchInfo labels IfDidNotMatch;
extern macro RegExpBuiltinsAssembler::IsReceiverInitialRegExpPrototype( macro IsReceiverInitialRegExpPrototype(implicit context:
implicit context: Context)(Object): bool; Context)(receiver: Object): bool {
const nativeContext: NativeContext = LoadNativeContext(context);
const regexpFun =
UnsafeCast<JSFunction>(nativeContext[REGEXP_FUNCTION_INDEX]);
const initialMap = UnsafeCast<Map>(regexpFun.prototype_or_initial_map);
const initialPrototype: HeapObject = initialMap.prototype;
return TaggedEqual(receiver, initialPrototype);
}
type Flag constexpr 'JSRegExp::Flag'; type Flag constexpr 'JSRegExp::Flag';
const kGlobal: constexpr Flag const kGlobal: constexpr Flag
...@@ -242,4 +249,27 @@ namespace regexp { ...@@ -242,4 +249,27 @@ namespace regexp {
} }
return false; return false;
} }
extern runtime RegExpInitializeAndCompile(Context, JSRegExp, String, String):
JSAny;
@export
transitioning macro RegExpCreate(implicit context: Context)(
nativeContext: NativeContext, maybeString: JSAny, flags: String): JSAny {
const regexpFun =
UnsafeCast<JSFunction>(nativeContext[REGEXP_FUNCTION_INDEX]);
const initialMap = UnsafeCast<Map>(regexpFun.prototype_or_initial_map);
return RegExpCreate(initialMap, maybeString, flags);
}
@export
transitioning macro RegExpCreate(implicit context: Context)(
initialMap: Map, maybeString: JSAny, flags: String): JSAny {
const pattern: String = maybeString == Undefined ?
kEmptyString :
ToString_Inline(context, maybeString);
const regexp =
UnsafeCast<JSRegExp>(AllocateFastOrSlowJSObjectFromMap(initialMap));
return RegExpInitializeAndCompile(context, regexp, pattern, flags);
}
} }
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