Commit 7c449a62 authored by ishell's avatar ishell Committed by Commit bot

Prepare to enable in-object properties in subclasses on a case by case basis.

Minor cleanup in VisitorId selection.

Review URL: https://codereview.chromium.org/1448313002

Cr-Commit-Position: refs/heads/master@{#32030}
parent 37632606
......@@ -79,14 +79,6 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case WEAK_CELL_TYPE:
return kVisitWeakCell;
case JS_SET_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSSet::kSize, has_unboxed_fields);
case JS_MAP_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSMap::kSize, has_unboxed_fields);
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
return kVisitJSWeakCollection;
......@@ -97,24 +89,16 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case SHARED_FUNCTION_INFO_TYPE:
return kVisitSharedFunctionInfo;
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_PROXY_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSProxy::kSize, has_unboxed_fields);
case JS_FUNCTION_PROXY_TYPE:
return GetVisitorIdForSize(kVisitStruct, kVisitStructGeneric,
JSFunctionProxy::kSize, has_unboxed_fields);
case FOREIGN_TYPE:
return GetVisitorIdForSize(kVisitDataObject, kVisitDataObjectGeneric,
Foreign::kSize, has_unboxed_fields);
instance_size, has_unboxed_fields);
case SYMBOL_TYPE:
return kVisitSymbol;
case FILLER_TYPE:
return kVisitDataObjectGeneric;
case JS_ARRAY_BUFFER_TYPE:
return kVisitJSArrayBuffer;
......@@ -143,6 +127,10 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId(
case JS_FUNCTION_TYPE:
return kVisitJSFunction;
case FILLER_TYPE:
if (instance_size == kPointerSize) return kVisitDataObjectGeneric;
// Fall through.
case FOREIGN_TYPE:
case HEAP_NUMBER_TYPE:
case MUTABLE_HEAP_NUMBER_TYPE:
case SIMD128_VALUE_TYPE:
......
......@@ -11896,6 +11896,75 @@ void JSFunction::SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
}
namespace {
bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
switch (instance_type) {
case JS_OBJECT_TYPE:
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
case JS_GENERATOR_OBJECT_TYPE:
case JS_MODULE_TYPE:
case JS_VALUE_TYPE:
case JS_DATE_TYPE:
case JS_ARRAY_TYPE:
case JS_MESSAGE_OBJECT_TYPE:
case JS_SET_ITERATOR_TYPE:
case JS_MAP_ITERATOR_TYPE:
case JS_ITERATOR_RESULT_TYPE:
return true;
case JS_TYPED_ARRAY_TYPE:
case JS_DATA_VIEW_TYPE:
case JS_REGEXP_TYPE:
case JS_SET_TYPE:
case JS_MAP_TYPE:
case JS_PROXY_TYPE:
case JS_FUNCTION_PROXY_TYPE:
case JS_WEAK_MAP_TYPE:
case JS_WEAK_SET_TYPE:
case JS_ARRAY_BUFFER_TYPE:
case JS_FUNCTION_TYPE:
return false;
case JS_GLOBAL_PROXY_TYPE:
case JS_GLOBAL_OBJECT_TYPE:
case FIXED_ARRAY_TYPE:
case FIXED_DOUBLE_ARRAY_TYPE:
case ODDBALL_TYPE:
case FOREIGN_TYPE:
case MAP_TYPE:
case CODE_TYPE:
case CELL_TYPE:
case PROPERTY_CELL_TYPE:
case WEAK_CELL_TYPE:
case SYMBOL_TYPE:
case BYTECODE_ARRAY_TYPE:
case HEAP_NUMBER_TYPE:
case MUTABLE_HEAP_NUMBER_TYPE:
case SIMD128_VALUE_TYPE:
case FILLER_TYPE:
case BYTE_ARRAY_TYPE:
case FREE_SPACE_TYPE:
case SHARED_FUNCTION_INFO_TYPE:
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case FIXED_##TYPE##_ARRAY_TYPE:
#undef TYPED_ARRAY_CASE
#define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE:
STRUCT_LIST(MAKE_STRUCT_CASE)
#undef MAKE_STRUCT_CASE
// We must not end up here for these instance types at all.
UNREACHABLE();
// Fall through.
default:
return false;
}
}
} // namespace
void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
if (function->has_initial_map()) return;
Isolate* isolate = function->GetIsolate();
......@@ -11970,25 +12039,27 @@ Handle<Map> JSFunction::EnsureDerivedHasInitialMap(
// Finally link initial map and constructor function if the original
// constructor is actually a subclass constructor.
if (IsSubclassConstructor(new_target->shared()->kind())) {
// TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have
// in-object properties.
#if 0
// TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have
// in-object properties.
InstanceType instance_type = constructor_initial_map->instance_type();
int internal_fields =
JSObject::GetInternalFieldCount(*constructor_initial_map);
int pre_allocated = constructor_initial_map->GetInObjectProperties() -
constructor_initial_map->unused_property_fields();
int instance_size;
int in_object_properties;
new_target->CalculateInstanceSizeForDerivedClass(
instance_type, internal_fields, &instance_size, &in_object_properties);
int unused_property_fields = in_object_properties - pre_allocated;
Handle<Map> map =
Map::CopyInitialMap(constructor_initial_map, instance_size,
in_object_properties, unused_property_fields);
#endif
Handle<Map> map = Map::CopyInitialMap(constructor_initial_map);
Handle<Map> map;
if (CanSubclassHaveInobjectProperties(instance_type)) {
int internal_fields =
JSObject::GetInternalFieldCount(*constructor_initial_map);
int pre_allocated = constructor_initial_map->GetInObjectProperties() -
constructor_initial_map->unused_property_fields();
int instance_size;
int in_object_properties;
new_target->CalculateInstanceSizeForDerivedClass(
instance_type, internal_fields, &instance_size,
&in_object_properties);
int unused_property_fields = in_object_properties - pre_allocated;
map = Map::CopyInitialMap(constructor_initial_map, instance_size,
in_object_properties, unused_property_fields);
} else {
map = Map::CopyInitialMap(constructor_initial_map);
}
JSFunction::SetInitialMap(new_target, map, prototype);
map->SetConstructor(*constructor);
......
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