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

Side by Side Diff: src/ast.cc

Issue 1225223004: Fix spread array inside array literal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add flag Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « src/ast.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast.h" 5 #include "src/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "src/builtins.h" 8 #include "src/builtins.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/contexts.h" 10 #include "src/contexts.h"
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 (max_element_index <= 32) || ((2 * elements) >= max_element_index); 498 (max_element_index <= 32) || ((2 * elements) >= max_element_index);
499 has_elements_ = elements > 0; 499 has_elements_ = elements > 0;
500 set_is_simple(is_simple); 500 set_is_simple(is_simple);
501 set_depth(depth_acc); 501 set_depth(depth_acc);
502 } 502 }
503 503
504 504
505 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { 505 void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
506 if (!constant_elements_.is_null()) return; 506 if (!constant_elements_.is_null()) return;
507 507
508 int constants_length =
509 first_spread_index_ >= 0 ? first_spread_index_ : values()->length();
510
508 // Allocate a fixed array to hold all the object literals. 511 // Allocate a fixed array to hold all the object literals.
509 Handle<JSArray> array = isolate->factory()->NewJSArray( 512 Handle<JSArray> array = isolate->factory()->NewJSArray(
510 FAST_HOLEY_SMI_ELEMENTS, values()->length(), values()->length(), 513 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
511 Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); 514 Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
512 515
513 // Fill in the literals. 516 // Fill in the literals.
514 bool is_simple = true; 517 bool is_simple = true;
515 int depth_acc = 1; 518 int depth_acc = 1;
516 bool is_holey = false; 519 bool is_holey = false;
517 int array_index = 0; 520 int array_index = 0;
518 for (int n = values()->length(); array_index < n; array_index++) { 521 for (; array_index < constants_length; array_index++) {
519 Expression* element = values()->at(array_index); 522 Expression* element = values()->at(array_index);
520 if (element->IsSpread()) break; 523 DCHECK(!element->IsSpread());
521 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); 524 MaterializedLiteral* m_literal = element->AsMaterializedLiteral();
522 if (m_literal != NULL) { 525 if (m_literal != NULL) {
523 m_literal->BuildConstants(isolate); 526 m_literal->BuildConstants(isolate);
524 if (m_literal->depth() + 1 > depth_acc) { 527 if (m_literal->depth() + 1 > depth_acc) {
525 depth_acc = m_literal->depth() + 1; 528 depth_acc = m_literal->depth() + 1;
526 } 529 }
527 } 530 }
528 531
529 // New handle scope here, needs to be after BuildContants(). 532 // New handle scope here, needs to be after BuildContants().
530 HandleScope scope(isolate); 533 HandleScope scope(isolate);
531 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate); 534 Handle<Object> boilerplate_value = GetBoilerplateValue(element, isolate);
532 if (boilerplate_value->IsTheHole()) { 535 if (boilerplate_value->IsTheHole()) {
533 is_holey = true; 536 is_holey = true;
534 continue; 537 continue;
535 } 538 }
536 539
537 if (boilerplate_value->IsUninitialized()) { 540 if (boilerplate_value->IsUninitialized()) {
538 boilerplate_value = handle(Smi::FromInt(0), isolate); 541 boilerplate_value = handle(Smi::FromInt(0), isolate);
539 is_simple = false; 542 is_simple = false;
540 } 543 }
541 544
542 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) 545 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE)
543 .Assert(); 546 .Assert();
544 } 547 }
545 548
546 if (array_index != values()->length()) {
547 JSArray::SetLength(array, array_index);
548 }
549 JSObject::ValidateElements(array); 549 JSObject::ValidateElements(array);
550 Handle<FixedArrayBase> element_values(array->elements()); 550 Handle<FixedArrayBase> element_values(array->elements());
551 551
552 // Simple and shallow arrays can be lazily copied, we transform the 552 // Simple and shallow arrays can be lazily copied, we transform the
553 // elements array to a copy-on-write array. 553 // elements array to a copy-on-write array.
554 if (is_simple && depth_acc == 1 && array_index > 0 && 554 if (is_simple && depth_acc == 1 && array_index > 0 &&
555 array->HasFastSmiOrObjectElements()) { 555 array->HasFastSmiOrObjectElements()) {
556 element_values->set_map(isolate->heap()->fixed_cow_array_map()); 556 element_values->set_map(isolate->heap()->fixed_cow_array_map());
557 } 557 }
558 558
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 bool Literal::Match(void* literal1, void* literal2) { 1145 bool Literal::Match(void* literal1, void* literal2) {
1146 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1146 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1147 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1147 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1148 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 1148 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
1149 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1149 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1150 } 1150 }
1151 1151
1152 1152
1153 } // namespace internal 1153 } // namespace internal
1154 } // namespace v8 1154 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698