Commit bb70859f authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup native methods creation in js/array.js.

This CL replaces usages of utils.InstallFunctions and utils.InstallGetter()
with the DEFINE_METHOD* macros that ensure that the native function is
created in proper form from the beginning. Thus the function will not
require further reconfiguring like adding a computed name or removing of
'prototype' property.

This CL is one of a series of cleanup CL which are the preliminary steps for
improving function closures creation.

Bug: v8:6459
Change-Id: Iff4b0754677e8b71f893ea29a06da64b58b41b27
Reviewed-on: https://chromium-review.googlesource.com/548056
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46280}
parent e14c4c95
...@@ -385,13 +385,37 @@ Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name, ...@@ -385,13 +385,37 @@ Handle<JSFunction> SimpleCreateFunction(Isolate* isolate, Handle<String> name,
} }
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
Handle<String> name, Handle<Name> property_name,
Handle<String> function_name,
Builtins::Name call, int len, Builtins::Name call, int len,
bool adapt, bool adapt,
PropertyAttributes attrs = DONT_ENUM) { PropertyAttributes attrs = DONT_ENUM) {
Handle<JSFunction> fun = Handle<JSFunction> fun =
SimpleCreateFunction(base->GetIsolate(), name, call, len, adapt); SimpleCreateFunction(base->GetIsolate(), function_name, call, len, adapt);
InstallFunction(base, fun, name, attrs); InstallFunction(base, fun, property_name, attrs);
return fun;
}
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
Handle<String> name,
Builtins::Name call, int len,
bool adapt,
PropertyAttributes attrs = DONT_ENUM) {
return SimpleInstallFunction(base, name, name, call, len, adapt, attrs);
}
Handle<JSFunction> SimpleInstallFunction(
Handle<JSObject> base, Handle<Name> property_name,
const char* function_name, Builtins::Name call, int len, bool adapt,
PropertyAttributes attrs = DONT_ENUM,
BuiltinFunctionId id = kInvalidBuiltinFunctionId) {
Factory* const factory = base->GetIsolate()->factory();
Handle<JSFunction> fun = SimpleInstallFunction(
base, property_name, factory->InternalizeUtf8String(function_name), call,
len, adapt, attrs);
if (id != kInvalidBuiltinFunctionId) {
fun->shared()->set_builtin_function_id(id);
}
return fun; return fun;
} }
...@@ -1454,15 +1478,44 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1454,15 +1478,44 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
array_function->shared()->SetConstructStub(*code); array_function->shared()->SetConstructStub(*code);
// Set up %ArrayPrototype%. // Set up %ArrayPrototype%.
Handle<JSArray> array_prototype = Handle<JSArray> proto =
Handle<JSArray>::cast(factory->NewJSObject(array_function, TENURED)); Handle<JSArray>::cast(factory->NewJSObject(array_function, TENURED));
JSArray::Initialize(array_prototype, 0); JSArray::Initialize(proto, 0);
JSFunction::SetPrototype(array_function, array_prototype); JSFunction::SetPrototype(array_function, proto);
native_context()->set_initial_array_prototype(*array_prototype); native_context()->set_initial_array_prototype(*proto);
Handle<JSFunction> is_arraylike = SimpleInstallFunction( Handle<JSFunction> is_arraylike = SimpleInstallFunction(
array_function, "isArray", Builtins::kArrayIsArray, 1, true); array_function, "isArray", Builtins::kArrayIsArray, 1, true);
native_context()->set_is_arraylike(*is_arraylike); native_context()->set_is_arraylike(*is_arraylike);
JSObject::AddProperty(proto, factory->constructor_string(), array_function,
DONT_ENUM);
SimpleInstallFunction(proto, "concat", Builtins::kArrayConcat, 1, false);
SimpleInstallFunction(proto, "pop", Builtins::kFastArrayPop, 0, false);
SimpleInstallFunction(proto, "push", Builtins::kFastArrayPush, 1, false);
SimpleInstallFunction(proto, "shift", Builtins::kFastArrayShift, 0, false);
SimpleInstallFunction(proto, "unshift", Builtins::kArrayUnshift, 1, false);
SimpleInstallFunction(proto, "slice", Builtins::kArraySlice, 2, false);
SimpleInstallFunction(proto, "splice", Builtins::kArraySplice, 2, false);
SimpleInstallFunction(proto, "includes", Builtins::kArrayIncludes, 1,
false);
SimpleInstallFunction(proto, "indexOf", Builtins::kArrayIndexOf, 1, false);
SimpleInstallFunction(proto, "keys", Builtins::kArrayPrototypeKeys, 0, true,
kArrayKeys);
SimpleInstallFunction(proto, "entries", Builtins::kArrayPrototypeEntries, 0,
true, kArrayEntries);
SimpleInstallFunction(proto, factory->iterator_symbol(), "values",
Builtins::kArrayPrototypeValues, 0, false, DONT_ENUM,
kArrayValues);
SimpleInstallFunction(proto, "forEach", Builtins::kArrayForEach, 1, false);
SimpleInstallFunction(proto, "filter", Builtins::kArrayFilter, 1, false);
SimpleInstallFunction(proto, "map", Builtins::kArrayMap, 1, false);
SimpleInstallFunction(proto, "every", Builtins::kArrayEvery, 1, false);
SimpleInstallFunction(proto, "some", Builtins::kArraySome, 1, false);
SimpleInstallFunction(proto, "reduce", Builtins::kArrayReduce, 1, false);
SimpleInstallFunction(proto, "reduceRight", Builtins::kArrayReduceRight, 1,
false);
} }
{ // --- A r r a y I t e r a t o r --- { // --- A r r a y I t e r a t o r ---
...@@ -4375,18 +4428,6 @@ bool Genesis::InstallNatives(GlobalContextType context_type) { ...@@ -4375,18 +4428,6 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
// This is necessary to enable fast checks for absence of elements // This is necessary to enable fast checks for absence of elements
// on Array.prototype and below. // on Array.prototype and below.
proto->set_elements(heap()->empty_fixed_array()); proto->set_elements(heap()->empty_fixed_array());
SimpleInstallFunction(proto, "concat", Builtins::kArrayConcat, 1, false);
Handle<JSFunction> for_each = SimpleInstallFunction(
proto, "forEach", Builtins::kArrayForEach, 1, false);
native_context()->set_array_for_each_iterator(*for_each);
SimpleInstallFunction(proto, "filter", Builtins::kArrayFilter, 1, false);
SimpleInstallFunction(proto, "map", Builtins::kArrayMap, 1, false);
SimpleInstallFunction(proto, "every", Builtins::kArrayEvery, 1, false);
SimpleInstallFunction(proto, "some", Builtins::kArraySome, 1, false);
SimpleInstallFunction(proto, "reduce", Builtins::kArrayReduce, 1, false);
SimpleInstallFunction(proto, "reduceRight", Builtins::kArrayReduceRight, 1,
false);
} }
// Install InternalArray.prototype.concat // Install InternalArray.prototype.concat
......
This diff is collapsed.
...@@ -4655,6 +4655,7 @@ class ContextExtension : public Struct { ...@@ -4655,6 +4655,7 @@ class ContextExtension : public Struct {
V(Atomics, xor, AtomicsXor) V(Atomics, xor, AtomicsXor)
enum BuiltinFunctionId { enum BuiltinFunctionId {
kInvalidBuiltinFunctionId = -1,
kArrayCode, kArrayCode,
#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
k##name, k##name,
......
...@@ -17,58 +17,6 @@ ...@@ -17,58 +17,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
static void InstallCode(
Isolate* isolate, Handle<JSObject> holder, const char* name,
Handle<Code> code, int argc = -1,
BuiltinFunctionId id = static_cast<BuiltinFunctionId>(-1)) {
Handle<String> key = isolate->factory()->InternalizeUtf8String(name);
Handle<JSFunction> optimized =
isolate->factory()->NewFunctionWithoutPrototype(key, code, true);
if (argc < 0) {
optimized->shared()->DontAdaptArguments();
} else {
optimized->shared()->set_internal_formal_parameter_count(argc);
}
if (id >= 0) {
optimized->shared()->set_builtin_function_id(id);
}
optimized->shared()->set_language_mode(STRICT);
optimized->shared()->set_native(true);
JSObject::AddProperty(holder, key, optimized, NONE);
}
static void InstallBuiltin(
Isolate* isolate, Handle<JSObject> holder, const char* name,
Builtins::Name builtin_name, int argc = -1,
BuiltinFunctionId id = static_cast<BuiltinFunctionId>(-1)) {
InstallCode(isolate, holder, name,
handle(isolate->builtins()->builtin(builtin_name), isolate), argc,
id);
}
RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
Handle<JSObject> holder =
isolate->factory()->NewJSObject(isolate->object_function());
InstallBuiltin(isolate, holder, "pop", Builtins::kFastArrayPop);
InstallBuiltin(isolate, holder, "push", Builtins::kFastArrayPush);
InstallBuiltin(isolate, holder, "shift", Builtins::kFastArrayShift);
InstallBuiltin(isolate, holder, "unshift", Builtins::kArrayUnshift);
InstallBuiltin(isolate, holder, "slice", Builtins::kArraySlice);
InstallBuiltin(isolate, holder, "splice", Builtins::kArraySplice);
InstallBuiltin(isolate, holder, "includes", Builtins::kArrayIncludes);
InstallBuiltin(isolate, holder, "indexOf", Builtins::kArrayIndexOf);
InstallBuiltin(isolate, holder, "keys", Builtins::kArrayPrototypeKeys, 0,
kArrayKeys);
InstallBuiltin(isolate, holder, "values", Builtins::kArrayPrototypeValues, 0,
kArrayValues);
InstallBuiltin(isolate, holder, "entries", Builtins::kArrayPrototypeEntries,
0, kArrayEntries);
return *holder;
}
RUNTIME_FUNCTION(Runtime_FixedArrayGet) { RUNTIME_FUNCTION(Runtime_FixedArrayGet) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK_EQ(2, args.length()); DCHECK_EQ(2, args.length());
......
...@@ -37,7 +37,6 @@ namespace internal { ...@@ -37,7 +37,6 @@ namespace internal {
// are specified by inline comments // are specified by inline comments
#define FOR_EACH_INTRINSIC_ARRAY(F) \ #define FOR_EACH_INTRINSIC_ARRAY(F) \
F(SpecialArrayFunctions, 0, 1) \
F(TransitionElementsKind, 2, 1) \ F(TransitionElementsKind, 2, 1) \
F(RemoveArrayHoles, 2, 1) \ F(RemoveArrayHoles, 2, 1) \
F(MoveArrayContents, 2, 1) \ F(MoveArrayContents, 2, 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