Commit 2c995c8c authored by danno's avatar danno Committed by Commit bot

[builtins] De-duplicate specification of array builtin parameter count

Previously, the parameter count for CSA-generated array builtins needed to be
specified both in the TFJ list of builtins as well as in the bootstrapper when
installing each builtin. This patch adds a utility function that returns the
arity of builtins, including CSA-generated array builtins, given the builtin's
name. This function is now used by the bootstrapper and thus removes the need
for the explicit duplication.

R=ishell@chromium.org
BUG=v8:1956
LOG=N

Review-Url: https://codereview.chromium.org/2852833002
Cr-Commit-Position: refs/heads/master@{#45033}
parent fc6e0678
...@@ -177,8 +177,7 @@ class Genesis BASE_EMBEDDED { ...@@ -177,8 +177,7 @@ class Genesis BASE_EMBEDDED {
#undef DECLARE_FEATURE_INITIALIZATION #undef DECLARE_FEATURE_INITIALIZATION
void InstallOneBuiltinFunction(Handle<Object> prototype, const char* method, void InstallOneBuiltinFunction(Handle<Object> prototype, const char* method,
Builtins::Name name, Builtins::Name name);
int internal_formal_parameter_count);
void InitializeGlobal_experimental_fast_array_builtins(); void InitializeGlobal_experimental_fast_array_builtins();
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
...@@ -397,14 +396,14 @@ Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name, ...@@ -397,14 +396,14 @@ Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name,
Handle<JSFunction> InstallArrayBuiltinFunction(Handle<JSObject> base, Handle<JSFunction> InstallArrayBuiltinFunction(Handle<JSObject> base,
const char* name, const char* name,
Builtins::Name call, Builtins::Name call) {
int argument_count) {
Isolate* isolate = base->GetIsolate(); Isolate* isolate = base->GetIsolate();
Handle<String> str_name = isolate->factory()->InternalizeUtf8String(name); Handle<String> str_name = isolate->factory()->InternalizeUtf8String(name);
Handle<JSFunction> fun = Handle<JSFunction> fun =
CreateFunction(isolate, str_name, JS_OBJECT_TYPE, JSObject::kHeaderSize, CreateFunction(isolate, str_name, JS_OBJECT_TYPE, JSObject::kHeaderSize,
MaybeHandle<JSObject>(), call, true); MaybeHandle<JSObject>(), call, true);
fun->shared()->set_internal_formal_parameter_count(argument_count); fun->shared()->set_internal_formal_parameter_count(
Builtins::GetBuiltinParameterCount(call));
// Set the length to 1 to satisfy ECMA-262. // Set the length to 1 to satisfy ECMA-262.
fun->shared()->set_length(1); fun->shared()->set_length(1);
...@@ -3871,8 +3870,7 @@ void InstallPublicSymbol(Factory* factory, Handle<Context> native_context, ...@@ -3871,8 +3870,7 @@ void InstallPublicSymbol(Factory* factory, Handle<Context> native_context,
void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype, void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype,
const char* method_name, const char* method_name,
Builtins::Name builtin_name, Builtins::Name builtin_name) {
int internal_formal_parameter_count) {
LookupIterator it( LookupIterator it(
prototype, isolate()->factory()->NewStringFromAsciiChecked(method_name), prototype, isolate()->factory()->NewStringFromAsciiChecked(method_name),
LookupIterator::OWN_SKIP_INTERCEPTOR); LookupIterator::OWN_SKIP_INTERCEPTOR);
...@@ -3881,7 +3879,8 @@ void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype, ...@@ -3881,7 +3879,8 @@ void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype,
isolate()->builtins()->builtin(builtin_name)); isolate()->builtins()->builtin(builtin_name));
SharedFunctionInfo* info = Handle<JSFunction>::cast(function)->shared(); SharedFunctionInfo* info = Handle<JSFunction>::cast(function)->shared();
info->set_code(isolate()->builtins()->builtin(builtin_name)); info->set_code(isolate()->builtins()->builtin(builtin_name));
info->set_internal_formal_parameter_count(internal_formal_parameter_count); info->set_internal_formal_parameter_count(
Builtins::GetBuiltinParameterCount(builtin_name));
} }
void Genesis::InitializeGlobal_experimental_fast_array_builtins() { void Genesis::InitializeGlobal_experimental_fast_array_builtins() {
...@@ -3891,17 +3890,13 @@ void Genesis::InitializeGlobal_experimental_fast_array_builtins() { ...@@ -3891,17 +3890,13 @@ void Genesis::InitializeGlobal_experimental_fast_array_builtins() {
native_context()->typed_array_prototype(), isolate()); native_context()->typed_array_prototype(), isolate());
// Insert experimental fast TypedArray builtins here. // Insert experimental fast TypedArray builtins here.
InstallOneBuiltinFunction(typed_array_prototype, "every", InstallOneBuiltinFunction(typed_array_prototype, "every",
Builtins::kTypedArrayPrototypeEvery, Builtins::kTypedArrayPrototypeEvery);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
InstallOneBuiltinFunction(typed_array_prototype, "some", InstallOneBuiltinFunction(typed_array_prototype, "some",
Builtins::kTypedArrayPrototypeSome, Builtins::kTypedArrayPrototypeSome);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
InstallOneBuiltinFunction(typed_array_prototype, "reduce", InstallOneBuiltinFunction(typed_array_prototype, "reduce",
Builtins::kTypedArrayPrototypeReduce, Builtins::kTypedArrayPrototypeReduce);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
InstallOneBuiltinFunction(typed_array_prototype, "reduceRight", InstallOneBuiltinFunction(typed_array_prototype, "reduceRight",
Builtins::kTypedArrayPrototypeReduceRight, Builtins::kTypedArrayPrototypeReduceRight);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
} }
} }
...@@ -4366,41 +4361,29 @@ bool Genesis::InstallNatives(GlobalContextType context_type) { ...@@ -4366,41 +4361,29 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
concat->shared()->set_length(1); concat->shared()->set_length(1);
// Install Array.prototype.forEach // Install Array.prototype.forEach
Handle<JSFunction> forEach = InstallArrayBuiltinFunction( Handle<JSFunction> forEach =
proto, "forEach", Builtins::kArrayForEach, InstallArrayBuiltinFunction(proto, "forEach", Builtins::kArrayForEach);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Add forEach to the context. // Add forEach to the context.
native_context()->set_array_for_each_iterator(*forEach); native_context()->set_array_for_each_iterator(*forEach);
// Install Array.prototype.filter // Install Array.prototype.filter
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "filter", Builtins::kArrayFilter);
proto, "filter", Builtins::kArrayFilter,
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Install Array.prototype.map // Install Array.prototype.map
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "map", Builtins::kArrayMap);
proto, "map", Builtins::kArrayMap,
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Install Array.prototype.every // Install Array.prototype.every
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "every", Builtins::kArrayEvery);
proto, "every", Builtins::kArrayEvery,
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Install Array.prototype.some // Install Array.prototype.some
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "some", Builtins::kArraySome);
proto, "some", Builtins::kArraySome,
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Install Array.prototype.reduce // Install Array.prototype.reduce
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "reduce", Builtins::kArrayReduce);
proto, "reduce", Builtins::kArrayReduce,
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
// Install Array.prototype.reduceRight // Install Array.prototype.reduceRight
InstallArrayBuiltinFunction( InstallArrayBuiltinFunction(proto, "reduceRight",
proto, "reduceRight", Builtins::kArrayReduceRight, Builtins::kArrayReduceRight);
SharedFunctionInfo::kDontAdaptArgumentsSentinel);
} }
// Install InternalArray.prototype.concat // Install InternalArray.prototype.concat
......
...@@ -115,6 +115,22 @@ Handle<Code> Builtins::OrdinaryToPrimitive(OrdinaryToPrimitiveHint hint) { ...@@ -115,6 +115,22 @@ Handle<Code> Builtins::OrdinaryToPrimitive(OrdinaryToPrimitiveHint hint) {
return Handle<Code>::null(); return Handle<Code>::null();
} }
// static
int Builtins::GetBuiltinParameterCount(Name name) {
switch (name) {
#define TFJ_CASE(Name, ParamCount, ...) \
case k##Name: { \
return ParamCount; \
}
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, TFJ_CASE, IGNORE_BUILTIN,
IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#undef CASE
default:
UNREACHABLE();
return 0;
}
}
// static // static
Callable Builtins::CallableFor(Isolate* isolate, Name name) { Callable Builtins::CallableFor(Isolate* isolate, Name name) {
switch (name) { switch (name) {
......
...@@ -76,6 +76,8 @@ class Builtins { ...@@ -76,6 +76,8 @@ class Builtins {
return reinterpret_cast<Address>(&builtins_[name]); return reinterpret_cast<Address>(&builtins_[name]);
} }
static int GetBuiltinParameterCount(Name name);
static Callable CallableFor(Isolate* isolate, Name name); static Callable CallableFor(Isolate* isolate, Name name);
static const char* name(int index); static const char* name(int index);
......
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