Commit 52016b65 authored by jgruber's avatar jgruber Committed by Commit bot

[regexp] Move source and species getter to TF

BUG=v8:5339

Review-Url: https://codereview.chromium.org/2537973004
Cr-Commit-Position: refs/heads/master@{#41432}
parent 8893d4ff
...@@ -1839,7 +1839,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1839,7 +1839,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(prototype, factory->multiline_string(), SimpleInstallGetter(prototype, factory->multiline_string(),
Builtins::kRegExpPrototypeMultilineGetter, true); Builtins::kRegExpPrototypeMultilineGetter, true);
SimpleInstallGetter(prototype, factory->source_string(), SimpleInstallGetter(prototype, factory->source_string(),
Builtins::kRegExpPrototypeSourceGetter, false); Builtins::kRegExpPrototypeSourceGetter, true);
SimpleInstallGetter(prototype, factory->sticky_string(), SimpleInstallGetter(prototype, factory->sticky_string(),
Builtins::kRegExpPrototypeStickyGetter, true); Builtins::kRegExpPrototypeStickyGetter, true);
SimpleInstallGetter(prototype, factory->unicode_string(), SimpleInstallGetter(prototype, factory->unicode_string(),
...@@ -1896,7 +1896,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1896,7 +1896,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallGetter(regexp_fun, SimpleInstallGetter(regexp_fun,
factory->InternalizeUtf8String("[Symbol.species]"), factory->InternalizeUtf8String("[Symbol.species]"),
factory->species_symbol(), factory->species_symbol(),
Builtins::kRegExpPrototypeSpeciesGetter, false); Builtins::kRegExpPrototypeSpeciesGetter, true);
// Static properties set by a successful match. // Static properties set by a successful match.
......
...@@ -715,24 +715,60 @@ void Builtins::Generate_RegExpPrototypeFlagsGetter(CodeAssemblerState* state) { ...@@ -715,24 +715,60 @@ void Builtins::Generate_RegExpPrototypeFlagsGetter(CodeAssemblerState* state) {
} }
// ES6 21.2.5.10. // ES6 21.2.5.10.
BUILTIN(RegExpPrototypeSourceGetter) { void Builtins::Generate_RegExpPrototypeSourceGetter(CodeAssemblerState* state) {
HandleScope scope(isolate); CodeStubAssembler a(state);
Node* const receiver = a.Parameter(0);
Node* const context = a.Parameter(3);
Handle<Object> recv = args.receiver(); // Check whether we have an unmodified regexp instance.
if (!recv->IsJSRegExp()) { CLabel if_isjsregexp(&a), if_isnotjsregexp(&a, CLabel::kDeferred);
Handle<JSFunction> regexp_fun = isolate->regexp_function();
if (*recv == regexp_fun->prototype()) { a.GotoIf(a.TaggedIsSmi(receiver), &if_isnotjsregexp);
isolate->CountUsage(v8::Isolate::kRegExpPrototypeSourceGetter); a.Branch(a.HasInstanceType(receiver, JS_REGEXP_TYPE), &if_isjsregexp,
return *isolate->factory()->NewStringFromAsciiChecked("(?:)"); &if_isnotjsregexp);
}
THROW_NEW_ERROR_RETURN_FAILURE( a.Bind(&if_isjsregexp);
isolate, NewTypeError(MessageTemplate::kRegExpNonRegExp, {
isolate->factory()->NewStringFromAsciiChecked( Node* const source = a.LoadObjectField(receiver, JSRegExp::kSourceOffset);
"RegExp.prototype.source"))); a.Return(source);
} }
Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(recv); a.Bind(&if_isnotjsregexp);
return regexp->source(); {
Isolate* isolate = a.isolate();
Node* const native_context = a.LoadNativeContext(context);
Node* const regexp_fun =
a.LoadContextElement(native_context, Context::REGEXP_FUNCTION_INDEX);
Node* const initial_map =
a.LoadObjectField(regexp_fun, JSFunction::kPrototypeOrInitialMapOffset);
Node* const initial_prototype = a.LoadMapPrototype(initial_map);
CLabel if_isprototype(&a), if_isnotprototype(&a);
a.Branch(a.WordEqual(receiver, initial_prototype), &if_isprototype,
&if_isnotprototype);
a.Bind(&if_isprototype);
{
const int counter = v8::Isolate::kRegExpPrototypeSourceGetter;
Node* const counter_smi = a.SmiConstant(counter);
a.CallRuntime(Runtime::kIncrementUseCounter, context, counter_smi);
Node* const result =
a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("(?:)"));
a.Return(result);
}
a.Bind(&if_isnotprototype);
{
Node* const message_id =
a.SmiConstant(Smi::FromInt(MessageTemplate::kRegExpNonRegExp));
Node* const method_name_str =
a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked(
"RegExp.prototype.source"));
a.TailCallRuntime(Runtime::kThrowTypeError, context, message_id,
method_name_str);
}
}
} }
BUILTIN(RegExpPrototypeToString) { BUILTIN(RegExpPrototypeToString) {
...@@ -773,9 +809,11 @@ BUILTIN(RegExpPrototypeToString) { ...@@ -773,9 +809,11 @@ BUILTIN(RegExpPrototypeToString) {
} }
// ES6 21.2.4.2. // ES6 21.2.4.2.
BUILTIN(RegExpPrototypeSpeciesGetter) { void Builtins::Generate_RegExpPrototypeSpeciesGetter(
HandleScope scope(isolate); CodeAssemblerState* state) {
return *args.receiver(); CodeStubAssembler a(state);
Node* const receiver = a.Parameter(0);
a.Return(receiver);
} }
namespace { namespace {
......
...@@ -608,8 +608,8 @@ namespace internal { ...@@ -608,8 +608,8 @@ namespace internal {
TFJ(RegExpPrototypeMultilineGetter, 0) \ TFJ(RegExpPrototypeMultilineGetter, 0) \
TFJ(RegExpPrototypeReplace, 2) \ TFJ(RegExpPrototypeReplace, 2) \
TFJ(RegExpPrototypeSearch, 1) \ TFJ(RegExpPrototypeSearch, 1) \
CPP(RegExpPrototypeSourceGetter) \ TFJ(RegExpPrototypeSourceGetter, 0) \
CPP(RegExpPrototypeSpeciesGetter) \ TFJ(RegExpPrototypeSpeciesGetter, 0) \
TFJ(RegExpPrototypeSplit, 2) \ TFJ(RegExpPrototypeSplit, 2) \
TFJ(RegExpPrototypeStickyGetter, 0) \ TFJ(RegExpPrototypeStickyGetter, 0) \
TFJ(RegExpPrototypeTest, 1) \ TFJ(RegExpPrototypeTest, 1) \
......
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