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

Unified Diff: src/ast/ast.cc

Issue 2481363009: Revert of Compiling an array literal should be context-independent. (Closed)
Patch Set: Created 4 years, 1 month 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/elements.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast.cc
diff --git a/src/ast/ast.cc b/src/ast/ast.cc
index 24712e4ef5a9ee61abcd98624f0191fe45c2aeb3..530bd50aaf7e12fadf6860b241663b594c5c514c 100644
--- a/src/ast/ast.cc
+++ b/src/ast/ast.cc
@@ -14,7 +14,6 @@
#include "src/code-stubs.h"
#include "src/contexts.h"
#include "src/conversions.h"
-#include "src/elements.h"
#include "src/property-details.h"
#include "src/property.h"
#include "src/string-stream.h"
@@ -581,9 +580,11 @@
if (!constant_elements_.is_null()) return;
int constants_length = values()->length();
- ElementsKind kind = FIRST_FAST_ELEMENTS_KIND;
- Handle<FixedArray> fixed_array =
- isolate->factory()->NewFixedArrayWithHoles(constants_length);
+
+ // Allocate a fixed array to hold all the object literals.
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
+ INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
// Fill in the literals.
bool is_simple = true;
@@ -614,34 +615,29 @@
is_simple = false;
}
- kind = GetMoreGeneralElementsKind(kind,
- boilerplate_value->OptimalElementsKind());
- fixed_array->set(array_index, *boilerplate_value);
- }
-
- if (is_holey) kind = GetHoleyElementsKind(kind);
+ JSObject::AddDataElement(array, array_index, boilerplate_value, NONE)
+ .Assert();
+ }
+
+ JSObject::ValidateElements(array);
+ Handle<FixedArrayBase> element_values(array->elements());
// Simple and shallow arrays can be lazily copied, we transform the
// elements array to a copy-on-write array.
if (is_simple && depth_acc == 1 && array_index > 0 &&
- IsFastSmiOrObjectElementsKind(kind)) {
- fixed_array->set_map(isolate->heap()->fixed_cow_array_map());
- }
-
- Handle<FixedArrayBase> elements = fixed_array;
- if (IsFastDoubleElementsKind(kind)) {
- ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
- elements = isolate->factory()->NewFixedDoubleArray(constants_length);
- // We are copying from non-fast-double to fast-double.
- ElementsKind from_kind = TERMINAL_FAST_ELEMENTS_KIND;
- accessor->CopyElements(fixed_array, from_kind, elements, constants_length);
+ array->HasFastSmiOrObjectElements()) {
+ element_values->set_map(isolate->heap()->fixed_cow_array_map());
}
// Remember both the literal's constant values as well as the ElementsKind
// in a 2-element FixedArray.
Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED);
+
+ ElementsKind kind = array->GetElementsKind();
+ kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind);
+
literals->set(0, Smi::FromInt(kind));
- literals->set(1, *elements);
+ literals->set(1, *element_values);
constant_elements_ = literals;
set_is_simple(is_simple);
« no previous file with comments | « no previous file | src/elements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698