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

Side by Side Diff: src/ast/ast.cc

Issue 2479123002: 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/inspector/debugger/get-possible-breakpoints-array-literal.js » ('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/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 8
9 #include "src/ast/compile-time-value.h" 9 #include "src/ast/compile-time-value.h"
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 set_depth(depth_acc); 573 set_depth(depth_acc);
574 } 574 }
575 575
576 576
577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) { 577 void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
578 DCHECK_LT(first_spread_index_, 0); 578 DCHECK_LT(first_spread_index_, 0);
579 579
580 if (!constant_elements_.is_null()) return; 580 if (!constant_elements_.is_null()) return;
581 581
582 int constants_length = values()->length(); 582 int constants_length = values()->length();
583 583 ElementsKind kind = FAST_SMI_ELEMENTS;
584 // Allocate a fixed array to hold all the object literals. 584 Handle<FixedArray> fixed_array =
585 Handle<JSArray> array = isolate->factory()->NewJSArray( 585 isolate->factory()->NewFixedArrayWithHoles(constants_length);
586 FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length,
587 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
588 586
589 // Fill in the literals. 587 // Fill in the literals.
590 bool is_simple = true; 588 bool is_simple = true;
591 int depth_acc = 1; 589 int depth_acc = 1;
592 bool is_holey = false; 590 bool is_holey = false;
593 int array_index = 0; 591 int array_index = 0;
594 for (; array_index < constants_length; array_index++) { 592 for (; array_index < constants_length; array_index++) {
595 Expression* element = values()->at(array_index); 593 Expression* element = values()->at(array_index);
596 DCHECK(!element->IsSpread()); 594 DCHECK(!element->IsSpread());
597 MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); 595 MaterializedLiteral* m_literal = element->AsMaterializedLiteral();
(...skipping 10 matching lines...) Expand all
608 if (boilerplate_value->IsTheHole(isolate)) { 606 if (boilerplate_value->IsTheHole(isolate)) {
609 is_holey = true; 607 is_holey = true;
610 continue; 608 continue;
611 } 609 }
612 610
613 if (boilerplate_value->IsUninitialized(isolate)) { 611 if (boilerplate_value->IsUninitialized(isolate)) {
614 boilerplate_value = handle(Smi::kZero, isolate); 612 boilerplate_value = handle(Smi::kZero, isolate);
615 is_simple = false; 613 is_simple = false;
616 } 614 }
617 615
618 JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) 616 kind = GetMoreGeneralElementsKind(kind,
619 .Assert(); 617 boilerplate_value->OptimalElementsKind());
618 fixed_array->set(array_index, *boilerplate_value);
620 } 619 }
621 620
622 JSObject::ValidateElements(array);
623 Handle<FixedArrayBase> element_values(array->elements());
624
625 // Simple and shallow arrays can be lazily copied, we transform the 621 // Simple and shallow arrays can be lazily copied, we transform the
626 // elements array to a copy-on-write array. 622 // elements array to a copy-on-write array.
627 if (is_simple && depth_acc == 1 && array_index > 0 && 623 if (is_simple && depth_acc == 1 && array_index > 0 &&
628 array->HasFastSmiOrObjectElements()) { 624 IsFastSmiOrObjectElementsKind(kind)) {
629 element_values->set_map(isolate->heap()->fixed_cow_array_map()); 625 fixed_array->set_map(isolate->heap()->fixed_cow_array_map());
630 } 626 }
631 627
628 Handle<FixedArrayBase> elements = fixed_array;
629
630 // In case of only double elements, copy over into a FixedDoubleArray.
631 if (IsDoubleOrFloatElementsKind(kind)) {
Igor Sheludko 2016/11/07 14:55:51 Maybe IsFastDoubleElementsKind(kind)? We don't inv
632 Handle<FixedDoubleArray> fixed_double_array =
633 Handle<FixedDoubleArray>::cast(
634 isolate->factory()->NewFixedDoubleArray(constants_length));
635 for (int i = 0; i < constants_length; i++) {
636 Object* element = fixed_array->get(i);
637 if (element->IsTheHole(isolate)) {
638 fixed_double_array->set_the_hole(i);
639 } else {
640 fixed_double_array->set(i, element->Number());
641 }
642 }
643 elements = fixed_double_array;
644 }
645
646 if (is_holey) kind = GetHoleyElementsKind(kind);
647
632 // Remember both the literal's constant values as well as the ElementsKind 648 // Remember both the literal's constant values as well as the ElementsKind
633 // in a 2-element FixedArray. 649 // in a 2-element FixedArray.
634 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); 650 Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED);
635
636 ElementsKind kind = array->GetElementsKind();
637 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind);
638
639 literals->set(0, Smi::FromInt(kind)); 651 literals->set(0, Smi::FromInt(kind));
640 literals->set(1, *element_values); 652 literals->set(1, *elements);
641 653
642 constant_elements_ = literals; 654 constant_elements_ = literals;
643 set_is_simple(is_simple); 655 set_is_simple(is_simple);
644 set_depth(depth_acc); 656 set_depth(depth_acc);
645 } 657 }
646 658
647 659
648 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate, 660 void ArrayLiteral::AssignFeedbackVectorSlots(Isolate* isolate,
649 FeedbackVectorSpec* spec, 661 FeedbackVectorSpec* spec,
650 FeedbackVectorSlotCache* cache) { 662 FeedbackVectorSlotCache* cache) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 // static 955 // static
944 bool Literal::Match(void* literal1, void* literal2) { 956 bool Literal::Match(void* literal1, void* literal2) {
945 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 957 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
946 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 958 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
947 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 959 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
948 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 960 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
949 } 961 }
950 962
951 } // namespace internal 963 } // namespace internal
952 } // namespace v8 964 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/inspector/debugger/get-possible-breakpoints-array-literal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698