Commit 0c2cd565 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr][cleanup] Prepare for improving literals creation

Create[Array|Object]Literal were simply extracted from Helper
classes.

Bug: v8:9353
Change-Id: I8a97a7d5151c324db4a924cbfe1720444a1529aa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1683992Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62474}
parent 6f41bff2
......@@ -324,13 +324,44 @@ MaybeHandle<JSObject> DeepCopy(Handle<JSObject> object,
return copy;
}
Handle<JSObject> CreateObjectLiteral(
Isolate* isolate,
Handle<ObjectBoilerplateDescription> object_boilerplate_description,
int flags, AllocationType allocation);
Handle<JSObject> CreateArrayLiteral(
Isolate* isolate,
Handle<ArrayBoilerplateDescription> array_boilerplate_description,
AllocationType allocation);
struct ObjectLiteralHelper {
static Handle<JSObject> Create(Isolate* isolate,
Handle<HeapObject> description, int flags,
AllocationType allocation) {
Handle<NativeContext> native_context = isolate->native_context();
static inline Handle<JSObject> Create(Isolate* isolate,
Handle<HeapObject> description,
int flags, AllocationType allocation) {
Handle<ObjectBoilerplateDescription> object_boilerplate_description =
Handle<ObjectBoilerplateDescription>::cast(description);
return CreateObjectLiteral(isolate, object_boilerplate_description, flags,
allocation);
}
};
struct ArrayLiteralHelper {
static inline Handle<JSObject> Create(Isolate* isolate,
Handle<HeapObject> description,
int flags_not_used,
AllocationType allocation) {
Handle<ArrayBoilerplateDescription> array_boilerplate_description =
Handle<ArrayBoilerplateDescription>::cast(description);
return CreateArrayLiteral(isolate, array_boilerplate_description,
allocation);
}
};
Handle<JSObject> CreateObjectLiteral(
Isolate* isolate,
Handle<ObjectBoilerplateDescription> object_boilerplate_description,
int flags, AllocationType allocation) {
Handle<NativeContext> native_context = isolate->native_context();
bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
bool has_null_prototype = (flags & ObjectLiteral::kHasNullPrototype) != 0;
......@@ -347,8 +378,8 @@ struct ObjectLiteralHelper {
has_null_prototype
? handle(native_context->slow_object_with_null_prototype_map(),
isolate)
: isolate->factory()->ObjectLiteralMapFromCache(
native_context, number_of_properties);
: isolate->factory()->ObjectLiteralMapFromCache(native_context,
number_of_properties);
Handle<JSObject> boilerplate =
isolate->factory()->NewFastOrSlowJSObjectFromMap(
......@@ -362,8 +393,7 @@ struct ObjectLiteralHelper {
// TODO(verwaest): Support tracking representations in the boilerplate.
for (int index = 0; index < length; index++) {
Handle<Object> key(object_boilerplate_description->name(index), isolate);
Handle<Object> value(object_boilerplate_description->value(index),
isolate);
Handle<Object> value(object_boilerplate_description->value(index), isolate);
if (value->IsObjectBoilerplateDescription() ||
value->IsArrayBoilerplateDescription()) {
......@@ -375,8 +405,8 @@ struct ObjectLiteralHelper {
if (value->IsUninitialized(isolate)) {
value = handle(Smi::kZero, isolate);
}
JSObject::SetOwnElementIgnoreAttributes(boilerplate, element_index,
value, NONE)
JSObject::SetOwnElementIgnoreAttributes(boilerplate, element_index, value,
NONE)
.Check();
} else {
Handle<String> name = Handle<String>::cast(key);
......@@ -389,21 +419,16 @@ struct ObjectLiteralHelper {
if (map->is_dictionary_map() && !has_null_prototype) {
// TODO(cbruni): avoid making the boilerplate fast again, the clone stub
// supports dict-mode objects directly.
JSObject::MigrateSlowToFast(boilerplate,
boilerplate->map().UnusedPropertyFields(),
"FastLiteral");
JSObject::MigrateSlowToFast(
boilerplate, boilerplate->map().UnusedPropertyFields(), "FastLiteral");
}
return boilerplate;
}
};
}
struct ArrayLiteralHelper {
static Handle<JSObject> Create(Isolate* isolate,
Handle<HeapObject> description, int flags,
Handle<JSObject> CreateArrayLiteral(
Isolate* isolate,
Handle<ArrayBoilerplateDescription> array_boilerplate_description,
AllocationType allocation) {
Handle<ArrayBoilerplateDescription> array_boilerplate_description =
Handle<ArrayBoilerplateDescription>::cast(description);
ElementsKind constant_elements_kind =
array_boilerplate_description->elements_kind();
......@@ -421,13 +446,13 @@ struct ArrayLiteralHelper {
ReadOnlyRoots(isolate).fixed_cow_array_map());
if (is_cow) {
copied_elements_values = constant_elements_values;
#if DEBUG
if (DEBUG_BOOL) {
Handle<FixedArray> fixed_array_values =
Handle<FixedArray>::cast(copied_elements_values);
for (int i = 0; i < fixed_array_values->length(); i++) {
DCHECK(!fixed_array_values->get(i).IsFixedArray());
}
#endif
}
} else {
Handle<FixedArray> fixed_array_values =
Handle<FixedArray>::cast(constant_elements_values);
......@@ -451,8 +476,7 @@ struct ArrayLiteralHelper {
return isolate->factory()->NewJSArrayWithElements(
copied_elements_values, constant_elements_kind,
copied_elements_values->length(), allocation);
}
};
}
Handle<Object> InnerCreateBoilerplate(Isolate* isolate,
Handle<Object> description,
......@@ -554,6 +578,7 @@ MaybeHandle<JSObject> CreateLiteral(Isolate* isolate,
usage_context.ExitScope(site, boilerplate);
return copy;
}
} // namespace
RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) {
......
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