Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: src/bootstrapper.cc

Issue 2752273003: [builtins] Implement Array.prototype.reduce in the CSA (Closed)
Patch Set: Simplify Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | src/builtins/builtins-array-gen.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index b31677caef810f7d15583145288c3e9009d7158b..2ae03256df22d6650e76ed19c565e1d822511e29 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -216,6 +216,8 @@ class Genesis BASE_EMBEDDED {
HARMONY_SHIPPING(DECLARE_FEATURE_INITIALIZATION)
#undef DECLARE_FEATURE_INITIALIZATION
+ void InstallOneBuiltinFunction(const char* object, const char* method,
+ Builtins::Name name);
void InitializeGlobal_enable_fast_array_builtins();
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
@@ -3664,63 +3666,39 @@ void InstallPublicSymbol(Factory* factory, Handle<Context> native_context,
JSObject::AddProperty(symbol, name_string, value, attributes);
}
-void Genesis::InitializeGlobal_enable_fast_array_builtins() {
- if (!FLAG_enable_fast_array_builtins) return;
-
+void Genesis::InstallOneBuiltinFunction(const char* object_name,
+ const char* method_name,
+ Builtins::Name builtin_name) {
Handle<JSGlobalObject> global(native_context()->global_object());
Isolate* isolate = global->GetIsolate();
Factory* factory = isolate->factory();
- LookupIterator it1(global, factory->NewStringFromAsciiChecked("Array"),
+ LookupIterator it1(global, factory->NewStringFromAsciiChecked(object_name),
LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> array_object = Object::GetProperty(&it1).ToHandleChecked();
- LookupIterator it2(array_object,
- factory->NewStringFromAsciiChecked("prototype"),
+ Handle<Object> object = Object::GetProperty(&it1).ToHandleChecked();
+ LookupIterator it2(object, factory->NewStringFromAsciiChecked("prototype"),
LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> array_prototype = Object::GetProperty(&it2).ToHandleChecked();
+ Handle<Object> prototype = Object::GetProperty(&it2).ToHandleChecked();
- LookupIterator it3(array_prototype,
- factory->NewStringFromAsciiChecked("forEach"),
- LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> for_each_function =
- Object::GetProperty(&it3).ToHandleChecked();
- Handle<JSFunction>::cast(for_each_function)
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayForEach));
- Handle<JSFunction>::cast(for_each_function)
- ->shared()
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayForEach));
-
- LookupIterator it4(array_prototype,
- factory->NewStringFromAsciiChecked("every"),
- LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> every_function = Object::GetProperty(&it4).ToHandleChecked();
- Handle<JSFunction>::cast(every_function)
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayEvery));
- Handle<JSFunction>::cast(every_function)
- ->shared()
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayEvery));
-
- LookupIterator it5(array_prototype,
- factory->NewStringFromAsciiChecked("some"),
+ LookupIterator it3(prototype, factory->NewStringFromAsciiChecked(method_name),
LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> some_function = Object::GetProperty(&it5).ToHandleChecked();
- Handle<JSFunction>::cast(some_function)
- ->set_code(isolate->builtins()->builtin(Builtins::kArraySome));
- Handle<JSFunction>::cast(some_function)
- ->shared()
- ->set_code(isolate->builtins()->builtin(Builtins::kArraySome));
+ Handle<Object> function = Object::GetProperty(&it3).ToHandleChecked();
+ Handle<JSFunction>::cast(function)->set_code(
+ isolate->builtins()->builtin(builtin_name));
+ Handle<JSFunction>::cast(function)->shared()->set_code(
+ isolate->builtins()->builtin(builtin_name));
+}
+
+void Genesis::InitializeGlobal_enable_fast_array_builtins() {
+ if (!FLAG_enable_fast_array_builtins) return;
+
+ InstallOneBuiltinFunction("Array", "forEach", Builtins::kArrayForEach);
+ InstallOneBuiltinFunction("Array", "every", Builtins::kArrayEvery);
+ InstallOneBuiltinFunction("Array", "some", Builtins::kArraySome);
+ InstallOneBuiltinFunction("Array", "reduce", Builtins::kArrayReduce);
if (FLAG_experimental_array_builtins) {
- LookupIterator it6(array_prototype,
- factory->NewStringFromAsciiChecked("filter"),
- LookupIterator::OWN_SKIP_INTERCEPTOR);
- Handle<Object> filter_function =
- Object::GetProperty(&it6).ToHandleChecked();
- Handle<JSFunction>::cast(filter_function)
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayFilter));
- Handle<JSFunction>::cast(filter_function)
- ->shared()
- ->set_code(isolate->builtins()->builtin(Builtins::kArrayFilter));
+ InstallOneBuiltinFunction("Array", "filter", Builtins::kArrayFilter);
}
}
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | src/builtins/builtins-array-gen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698