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

Unified Diff: src/bootstrapper.cc

Issue 2046333002: Revert "Revert of [builtins] Properly optimize TypedArray/DataView accessors. (patchset #3 id:40001… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove TypedArray from global object Created 4 years, 6 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.h » ('j') | no next file with comments »
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 111c2696c865c570375d23bc05ab4764e04bb0d5..cd05e7b13f9bfb56f0770f2bb672f605778382df 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -379,6 +379,16 @@ void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function,
InstallFunction(target, name, function, name_string, attributes);
}
+Handle<JSFunction> InstallGetter(Handle<JSObject> target,
+ Handle<Name> property_name,
+ Handle<JSFunction> getter,
+ PropertyAttributes attributes = DONT_ENUM) {
+ Handle<Object> setter = target->GetIsolate()->factory()->undefined_value();
+ JSObject::DefineAccessor(target, property_name, getter, setter, attributes)
+ .Check();
+ return getter;
+}
+
Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name,
InstanceType type, int instance_size,
MaybeHandle<JSObject> maybe_prototype,
@@ -456,6 +466,27 @@ Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
len, adapt);
}
+Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
+ Handle<String> name, Builtins::Name call,
+ bool adapt) {
+ Isolate* const isolate = base->GetIsolate();
+ Handle<String> fun_name =
+ Name::ToFunctionName(name, isolate->factory()->get_string())
+ .ToHandleChecked();
+ Handle<JSFunction> fun =
+ SimpleCreateFunction(isolate, fun_name, call, 0, adapt);
+ InstallGetter(base, name, fun);
+ return fun;
+}
+
+Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
+ Handle<String> name, Builtins::Name call,
+ bool adapt, BuiltinFunctionId id) {
+ Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt);
+ fun->shared()->set_builtin_function_id(id);
+ return fun;
+}
+
} // namespace
void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map,
@@ -1654,6 +1685,36 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Context::ARRAY_BUFFER_FUN_INDEX);
}
+ { // -- T y p e d A r r a y
+ Handle<JSObject> prototype =
+ factory->NewJSObject(isolate->object_function(), TENURED);
+ native_context()->set_typed_array_prototype(*prototype);
+
+ Handle<JSFunction> typed_array_fun =
+ CreateFunction(isolate, factory->InternalizeUtf8String("TypedArray"),
+ JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize, prototype,
+ Builtins::kIllegal);
+
+ // Install the "constructor" property on the {prototype}.
+ JSObject::AddProperty(prototype, factory->constructor_string(),
+ typed_array_fun, DONT_ENUM);
+ native_context()->set_typed_array_function(*typed_array_fun);
+
+ // Install the "buffer", "byteOffset", "byteLength" and "length"
+ // getters on the {prototype}.
+ SimpleInstallGetter(prototype, factory->buffer_string(),
+ Builtins::kTypedArrayPrototypeBuffer, false);
+ SimpleInstallGetter(prototype, factory->byte_length_string(),
+ Builtins::kTypedArrayPrototypeByteLength, true,
+ kTypedArrayByteLength);
+ SimpleInstallGetter(prototype, factory->byte_offset_string(),
+ Builtins::kTypedArrayPrototypeByteOffset, true,
+ kTypedArrayByteOffset);
+ SimpleInstallGetter(prototype, factory->length_string(),
+ Builtins::kTypedArrayPrototypeLength, true,
+ kTypedArrayLength);
+ }
+
{ // -- T y p e d A r r a y s
#define INSTALL_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
{ \
@@ -1664,17 +1725,43 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
}
TYPED_ARRAYS(INSTALL_TYPED_ARRAY)
#undef INSTALL_TYPED_ARRAY
+ }
- Handle<JSFunction> data_view_fun = InstallFunction(
- global, "DataView", JS_DATA_VIEW_TYPE,
- JSDataView::kSizeWithInternalFields,
- isolate->initial_object_prototype(), Builtins::kDataViewConstructor);
+ { // -- D a t a V i e w
+ Handle<JSObject> prototype =
+ factory->NewJSObject(isolate->object_function(), TENURED);
+ Handle<JSFunction> data_view_fun =
+ InstallFunction(global, "DataView", JS_DATA_VIEW_TYPE,
+ JSDataView::kSizeWithInternalFields, prototype,
+ Builtins::kDataViewConstructor);
InstallWithIntrinsicDefaultProto(isolate, data_view_fun,
Context::DATA_VIEW_FUN_INDEX);
data_view_fun->shared()->set_construct_stub(
*isolate->builtins()->DataViewConstructor_ConstructStub());
data_view_fun->shared()->set_length(3);
data_view_fun->shared()->DontAdaptArguments();
+
+ // Install the @@toStringTag property on the {prototype}.
+ JSObject::AddProperty(
+ prototype, factory->to_string_tag_symbol(),
+ factory->NewStringFromAsciiChecked("DataView"),
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
+
+ // Install the "constructor" property on the {prototype}.
+ JSObject::AddProperty(prototype, factory->constructor_string(),
+ data_view_fun, DONT_ENUM);
+
+ // Install the "buffer", "byteOffset" and "byteLength" getters
+ // on the {prototype}.
+ SimpleInstallGetter(prototype, factory->buffer_string(),
+ Builtins::kDataViewPrototypeGetBuffer, false,
+ kDataViewBuffer);
+ SimpleInstallGetter(prototype, factory->byte_length_string(),
+ Builtins::kDataViewPrototypeGetByteLength, false,
+ kDataViewByteLength);
+ SimpleInstallGetter(prototype, factory->byte_offset_string(),
+ Builtins::kDataViewPrototypeGetByteOffset, false,
+ kDataViewByteOffset);
}
{ // -- M a p
@@ -1973,13 +2060,20 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
}
} // NOLINT(readability/fn_size)
-
void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind,
Handle<JSFunction>* fun) {
Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
- Handle<JSFunction> result = InstallFunction(
- global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize,
- isolate()->initial_object_prototype(), Builtins::kIllegal);
+
+ Handle<JSObject> typed_array_prototype =
+ Handle<JSObject>(isolate()->typed_array_prototype());
+ Handle<JSFunction> typed_array_function =
+ Handle<JSFunction>(isolate()->typed_array_function());
+
+ Handle<JSObject> prototype =
+ factory()->NewJSObject(isolate()->object_function(), TENURED);
+ Handle<JSFunction> result =
+ InstallFunction(global, name, JS_TYPED_ARRAY_TYPE, JSTypedArray::kSize,
+ prototype, Builtins::kIllegal);
Handle<Map> initial_map = isolate()->factory()->NewMap(
JS_TYPED_ARRAY_TYPE,
@@ -1987,6 +2081,14 @@ void Genesis::InstallTypedArray(const char* name, ElementsKind elements_kind,
elements_kind);
JSFunction::SetInitialMap(result, initial_map,
handle(initial_map->prototype(), isolate()));
+
+ CHECK(JSObject::SetPrototype(result, typed_array_function, false,
+ Object::DONT_THROW)
+ .FromJust());
+
+ CHECK(JSObject::SetPrototype(prototype, typed_array_prototype, false,
+ Object::DONT_THROW)
+ .FromJust());
*fun = result;
}
« no previous file with comments | « no previous file | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698