Index: src/bootstrapper.cc |
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc |
index 5e6ff7a9f6b910716221a63f4295137072d74b6b..c70cd1d28bc1e77a65f14f5f1ebd9e6a273703b2 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,32 @@ 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); |
+ Handle<JSFunction> typed_array_fun = |
+ InstallFunction(global, "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); |
+ |
+ // 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 +1721,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 |