Commit 4922412a authored by michael_dawson's avatar michael_dawson Committed by Commit bot

PPC: Ensure object literal element boilerplates aren't modified.

Port 7c347c54

Original commit message:
A bug allows JSObject literals with elements to have the elements in the
boilerplate modified.

R=mbrandy@us.ibm.com

BUG=466993
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#27552}
parent 6cb0e87c
...@@ -1651,19 +1651,13 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -1651,19 +1651,13 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
__ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset)); __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
__ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index())); __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
__ mov(r4, Operand(constant_properties)); __ mov(r4, Operand(constant_properties));
int flags = expr->fast_elements() ? ObjectLiteral::kFastElements int flags = expr->ComputeFlags();
: ObjectLiteral::kNoFlags;
flags |= expr->has_function() ? ObjectLiteral::kHasFunction
: ObjectLiteral::kNoFlags;
__ LoadSmiLiteral(r3, Smi::FromInt(flags)); __ LoadSmiLiteral(r3, Smi::FromInt(flags));
int properties_count = constant_properties->length() / 2; if (MustCreateObjectLiteralWithRuntime(expr)) {
if (expr->may_store_doubles() || expr->depth() > 1 ||
masm()->serializer_enabled() || flags != ObjectLiteral::kFastElements ||
properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) {
__ Push(r6, r5, r4, r3); __ Push(r6, r5, r4, r3);
__ CallRuntime(Runtime::kCreateObjectLiteral, 4); __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
} else { } else {
FastCloneShallowObjectStub stub(isolate(), properties_count); FastCloneShallowObjectStub stub(isolate(), expr->properties_count());
__ CallStub(&stub); __ CallStub(&stub);
} }
PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
...@@ -1853,16 +1847,9 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -1853,16 +1847,9 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
Comment cmnt(masm_, "[ ArrayLiteral"); Comment cmnt(masm_, "[ ArrayLiteral");
expr->BuildConstantElements(isolate()); expr->BuildConstantElements(isolate());
int flags = expr->depth() == 1 ? ArrayLiteral::kShallowElements
: ArrayLiteral::kNoFlags;
ZoneList<Expression*>* subexprs = expr->values();
int length = subexprs->length();
Handle<FixedArray> constant_elements = expr->constant_elements(); Handle<FixedArray> constant_elements = expr->constant_elements();
DCHECK_EQ(2, constant_elements->length()); bool has_fast_elements =
ElementsKind constant_elements_kind = IsFastObjectElementsKind(expr->constant_elements_kind());
static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value());
bool has_fast_elements = IsFastObjectElementsKind(constant_elements_kind);
Handle<FixedArrayBase> constant_elements_values( Handle<FixedArrayBase> constant_elements_values(
FixedArrayBase::cast(constant_elements->get(1))); FixedArrayBase::cast(constant_elements->get(1)));
...@@ -1877,8 +1864,8 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -1877,8 +1864,8 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
__ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset)); __ LoadP(r6, FieldMemOperand(r6, JSFunction::kLiteralsOffset));
__ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index())); __ LoadSmiLiteral(r5, Smi::FromInt(expr->literal_index()));
__ mov(r4, Operand(constant_elements)); __ mov(r4, Operand(constant_elements));
if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { if (MustCreateArrayLiteralWithRuntime(expr)) {
__ LoadSmiLiteral(r3, Smi::FromInt(flags)); __ LoadSmiLiteral(r3, Smi::FromInt(expr->ComputeFlags()));
__ Push(r6, r5, r4, r3); __ Push(r6, r5, r4, r3);
__ CallRuntime(Runtime::kCreateArrayLiteral, 4); __ CallRuntime(Runtime::kCreateArrayLiteral, 4);
} else { } else {
...@@ -1888,6 +1875,8 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -1888,6 +1875,8 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG);
bool result_saved = false; // Is the result saved to the stack? bool result_saved = false; // Is the result saved to the stack?
ZoneList<Expression*>* subexprs = expr->values();
int length = subexprs->length();
// Emit code to evaluate all the non-constant subexpressions and to store // Emit code to evaluate all the non-constant subexpressions and to store
// them into the newly cloned array. // them into the newly cloned array.
...@@ -1904,7 +1893,7 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -1904,7 +1893,7 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
} }
VisitForAccumulatorValue(subexpr); VisitForAccumulatorValue(subexpr);
if (IsFastObjectElementsKind(constant_elements_kind)) { if (has_fast_elements) {
int offset = FixedArray::kHeaderSize + (i * kPointerSize); int offset = FixedArray::kHeaderSize + (i * kPointerSize);
__ LoadP(r8, MemOperand(sp, kPointerSize)); // Copy of array literal. __ LoadP(r8, MemOperand(sp, kPointerSize)); // Copy of array literal.
__ LoadP(r4, FieldMemOperand(r8, JSObject::kElementsOffset)); __ LoadP(r4, FieldMemOperand(r8, JSObject::kElementsOffset));
......
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