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

Unified Diff: src/runtime/runtime-literals.cc

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: fixing typo 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
Index: src/runtime/runtime-literals.cc
diff --git a/src/runtime/runtime-literals.cc b/src/runtime/runtime-literals.cc
index 7beadf5e0bb1e099beb685f82ed40955c28d89db..73825654c596a1694b93691da57b8d9c09a2eb1f 100644
--- a/src/runtime/runtime-literals.cc
+++ b/src/runtime/runtime-literals.cc
@@ -14,16 +14,6 @@
namespace v8 {
namespace internal {
-static Handle<Map> ComputeObjectLiteralMap(
- Handle<Context> context,
- Handle<BoilerplateDescription> boilerplate_description,
- bool* is_result_from_cache) {
- int number_of_properties = boilerplate_description->backing_store_size();
- Isolate* isolate = context->GetIsolate();
- return isolate->factory()->ObjectLiteralMapFromCache(
- context, number_of_properties, is_result_from_cache);
-}
-
MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
Isolate* isolate, Handle<FeedbackVector> vector,
Handle<BoilerplateDescription> boilerplate_description);
@@ -31,36 +21,33 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
Isolate* isolate, Handle<FeedbackVector> vector,
Handle<BoilerplateDescription> boilerplate_description,
- bool should_have_fast_elements) {
+ bool use_fast_elements, bool has_null_prototype) {
Handle<Context> context = isolate->native_context();
// In case we have function literals, we want the object to be in
// slow properties mode for now. We don't go in the map cache because
// maps with constant functions can't be shared if the functions are
// not the same (which is the common case).
- bool is_result_from_cache = false;
- Handle<Map> map = ComputeObjectLiteralMap(context, boilerplate_description,
- &is_result_from_cache);
+ int number_of_properties = boilerplate_description->backing_store_size();
+ Handle<Map> map = isolate->factory()->ObjectLiteralMapFromCache(
+ context, number_of_properties, has_null_prototype);
PretenureFlag pretenure_flag =
isolate->heap()->InNewSpace(*vector) ? NOT_TENURED : TENURED;
- Handle<JSObject> boilerplate =
- isolate->factory()->NewJSObjectFromMap(map, pretenure_flag);
+ Handle<JSObject> boilerplate;
+ if (map->is_dictionary_map()) {
+ boilerplate = isolate->factory()->NewSlowJSObjectFromMap(
+ map, number_of_properties, pretenure_flag);
+ } else {
+ boilerplate = isolate->factory()->NewJSObjectFromMap(map, pretenure_flag);
+ }
// Normalize the elements of the boilerplate to save space if needed.
- if (!should_have_fast_elements) JSObject::NormalizeElements(boilerplate);
+ if (!use_fast_elements) JSObject::NormalizeElements(boilerplate);
// Add the constant properties to the boilerplate.
int length = boilerplate_description->size();
- bool should_transform =
- !is_result_from_cache && boilerplate->HasFastProperties();
- bool should_normalize = should_transform;
- if (should_normalize) {
- // TODO(verwaest): We might not want to ever normalize here.
- JSObject::NormalizeProperties(boilerplate, KEEP_INOBJECT_PROPERTIES, length,
- "Boilerplate");
- }
// TODO(verwaest): Support tracking representations in the boilerplate.
for (int index = 0; index < length; index++) {
Handle<Object> key(boilerplate_description->name(index), isolate);
@@ -92,11 +79,9 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
RETURN_ON_EXCEPTION(isolate, maybe_result, Object);
}
- // Transform to fast properties if necessary. For object literals with
- // containing function literals we defer this operation until after all
- // computed properties have been assigned so that we can generate
- // constant function properties.
- if (should_transform) {
+ 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()->unused_property_fields(),
"FastLiteral");
@@ -181,15 +166,18 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
Handle<BoilerplateDescription> array) {
Handle<HeapObject> elements = CompileTimeValue::GetElements(array);
switch (CompileTimeValue::GetLiteralType(array)) {
+ // TODO(cbruni): support slow inner literals.
case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: {
Handle<BoilerplateDescription> props =
Handle<BoilerplateDescription>::cast(elements);
- return CreateObjectLiteralBoilerplate(isolate, vector, props, true);
+ return CreateObjectLiteralBoilerplate(isolate, vector, props, true,
+ false);
}
case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: {
Handle<BoilerplateDescription> props =
Handle<BoilerplateDescription>::cast(elements);
- return CreateObjectLiteralBoilerplate(isolate, vector, props, false);
+ return CreateObjectLiteralBoilerplate(isolate, vector, props, false,
+ false);
}
case CompileTimeValue::ARRAY_LITERAL: {
Handle<ConstantElementsPair> elems =
@@ -233,8 +221,9 @@ RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) {
2);
CONVERT_SMI_ARG_CHECKED(flags, 3);
Handle<FeedbackVector> vector(closure->feedback_vector(), isolate);
- bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
+ bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
bool enable_mementos = (flags & ObjectLiteral::kDisableMementos) == 0;
+ bool has_null_prototype = (flags & ObjectLiteral::kHasNullPrototype) != 0;
FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index));
CHECK(literals_slot.ToInt() < vector->slot_count());
@@ -248,7 +237,7 @@ RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, raw_boilerplate,
CreateObjectLiteralBoilerplate(isolate, vector, boilerplate_description,
- should_have_fast_elements));
+ use_fast_elements, has_null_prototype));
boilerplate = Handle<JSObject>::cast(raw_boilerplate);
AllocationSiteCreationContext creation_context(isolate);

Powered by Google App Engine
This is Rietveld 408576698