OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |