| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3707 if (peek() != Token::RBRACK) { | 3707 if (peek() != Token::RBRACK) { |
| 3708 Expect(Token::COMMA, CHECK_OK); | 3708 Expect(Token::COMMA, CHECK_OK); |
| 3709 } | 3709 } |
| 3710 } | 3710 } |
| 3711 Expect(Token::RBRACK, CHECK_OK); | 3711 Expect(Token::RBRACK, CHECK_OK); |
| 3712 | 3712 |
| 3713 // Update the scope information before the pre-parsing bailout. | 3713 // Update the scope information before the pre-parsing bailout. |
| 3714 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 3714 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
| 3715 | 3715 |
| 3716 // Allocate a fixed array to hold all the object literals. | 3716 // Allocate a fixed array to hold all the object literals. |
| 3717 Handle<FixedArray> object_literals = | 3717 Handle<JSArray> array = |
| 3718 isolate()->factory()->NewFixedArray(values->length(), TENURED); | 3718 isolate()->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); |
| 3719 Handle<FixedDoubleArray> double_literals; | 3719 isolate()->factory()->SetElementsCapacityAndLength( |
| 3720 ElementsKind elements_kind = FAST_SMI_ELEMENTS; | 3720 array, values->length(), values->length()); |
| 3721 bool has_hole_values = false; | |
| 3722 | 3721 |
| 3723 // Fill in the literals. | 3722 // Fill in the literals. |
| 3724 Heap* heap = isolate()->heap(); | 3723 Heap* heap = isolate()->heap(); |
| 3725 bool is_simple = true; | 3724 bool is_simple = true; |
| 3726 int depth = 1; | 3725 int depth = 1; |
| 3726 bool is_holey = false; |
| 3727 for (int i = 0, n = values->length(); i < n; i++) { | 3727 for (int i = 0, n = values->length(); i < n; i++) { |
| 3728 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | 3728 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); |
| 3729 if (m_literal != NULL && m_literal->depth() + 1 > depth) { | 3729 if (m_literal != NULL && m_literal->depth() + 1 > depth) { |
| 3730 depth = m_literal->depth() + 1; | 3730 depth = m_literal->depth() + 1; |
| 3731 } | 3731 } |
| 3732 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); | 3732 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); |
| 3733 if (boilerplate_value->IsTheHole()) { | 3733 if (boilerplate_value->IsTheHole()) { |
| 3734 has_hole_values = true; | 3734 is_holey = true; |
| 3735 object_literals->set_the_hole(i); | |
| 3736 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | |
| 3737 double_literals->set_the_hole(i); | |
| 3738 } | |
| 3739 } else if (boilerplate_value->IsUndefined()) { | 3735 } else if (boilerplate_value->IsUndefined()) { |
| 3740 is_simple = false; | 3736 is_simple = false; |
| 3741 object_literals->set(i, Smi::FromInt(0)); | 3737 JSObject::SetOwnElement( |
| 3742 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | 3738 array, i, handle(Smi::FromInt(0), isolate()), kNonStrictMode); |
| 3743 double_literals->set(i, 0); | |
| 3744 } | |
| 3745 } else { | 3739 } else { |
| 3746 // Examine each literal element, and adjust the ElementsKind if the | 3740 JSObject::SetOwnElement(array, i, boilerplate_value, kNonStrictMode); |
| 3747 // literal element is not of a type that can be stored in the current | |
| 3748 // ElementsKind. Start with FAST_SMI_ONLY_ELEMENTS, and transition to | |
| 3749 // FAST_DOUBLE_ELEMENTS and FAST_ELEMENTS as necessary. Always remember | |
| 3750 // the tagged value, no matter what the ElementsKind is in case we | |
| 3751 // ultimately end up in FAST_ELEMENTS. | |
| 3752 object_literals->set(i, *boilerplate_value); | |
| 3753 if (elements_kind == FAST_SMI_ELEMENTS) { | |
| 3754 // Smi only elements. Notice if a transition to FAST_DOUBLE_ELEMENTS or | |
| 3755 // FAST_ELEMENTS is required. | |
| 3756 if (!boilerplate_value->IsSmi()) { | |
| 3757 if (boilerplate_value->IsNumber() && FLAG_smi_only_arrays) { | |
| 3758 // Allocate a double array on the FAST_DOUBLE_ELEMENTS transition to | |
| 3759 // avoid over-allocating in TENURED space. | |
| 3760 double_literals = isolate()->factory()->NewFixedDoubleArray( | |
| 3761 values->length(), TENURED); | |
| 3762 // Copy the contents of the FAST_SMI_ONLY_ELEMENT array to the | |
| 3763 // FAST_DOUBLE_ELEMENTS array so that they are in sync. | |
| 3764 for (int j = 0; j < i; ++j) { | |
| 3765 Object* smi_value = object_literals->get(j); | |
| 3766 if (smi_value->IsTheHole()) { | |
| 3767 double_literals->set_the_hole(j); | |
| 3768 } else { | |
| 3769 double_literals->set(j, Smi::cast(smi_value)->value()); | |
| 3770 } | |
| 3771 } | |
| 3772 double_literals->set(i, boilerplate_value->Number()); | |
| 3773 elements_kind = FAST_DOUBLE_ELEMENTS; | |
| 3774 } else { | |
| 3775 elements_kind = FAST_ELEMENTS; | |
| 3776 } | |
| 3777 } | |
| 3778 } else if (elements_kind == FAST_DOUBLE_ELEMENTS) { | |
| 3779 // Continue to store double values in to FAST_DOUBLE_ELEMENTS arrays | |
| 3780 // until the first value is seen that can't be stored as a double. | |
| 3781 if (boilerplate_value->IsNumber()) { | |
| 3782 double_literals->set(i, boilerplate_value->Number()); | |
| 3783 } else { | |
| 3784 elements_kind = FAST_ELEMENTS; | |
| 3785 } | |
| 3786 } | |
| 3787 } | 3741 } |
| 3788 } | 3742 } |
| 3789 | 3743 |
| 3744 Handle<FixedArrayBase> element_values(array->elements()); |
| 3745 |
| 3790 // Simple and shallow arrays can be lazily copied, we transform the | 3746 // Simple and shallow arrays can be lazily copied, we transform the |
| 3791 // elements array to a copy-on-write array. | 3747 // elements array to a copy-on-write array. |
| 3792 if (is_simple && depth == 1 && values->length() > 0 && | 3748 if (is_simple && depth == 1 && values->length() > 0 && |
| 3793 elements_kind != FAST_DOUBLE_ELEMENTS) { | 3749 array->HasFastSmiOrObjectElements()) { |
| 3794 object_literals->set_map(heap->fixed_cow_array_map()); | 3750 element_values->set_map(heap->fixed_cow_array_map()); |
| 3795 } | 3751 } |
| 3796 | 3752 |
| 3797 Handle<FixedArrayBase> element_values = elements_kind == FAST_DOUBLE_ELEMENTS | |
| 3798 ? Handle<FixedArrayBase>(double_literals) | |
| 3799 : Handle<FixedArrayBase>(object_literals); | |
| 3800 | |
| 3801 // Remember both the literal's constant values as well as the ElementsKind | 3753 // Remember both the literal's constant values as well as the ElementsKind |
| 3802 // in a 2-element FixedArray. | 3754 // in a 2-element FixedArray. |
| 3803 Handle<FixedArray> literals = | 3755 Handle<FixedArray> literals = isolate()->factory()->NewFixedArray(2, TENURED); |
| 3804 isolate()->factory()->NewFixedArray(2, TENURED); | |
| 3805 | 3756 |
| 3806 if (has_hole_values || !FLAG_packed_arrays) { | 3757 ElementsKind kind = array->GetElementsKind(); |
| 3807 elements_kind = GetHoleyElementsKind(elements_kind); | 3758 kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind); |
| 3808 } | |
| 3809 | 3759 |
| 3810 literals->set(0, Smi::FromInt(elements_kind)); | 3760 literals->set(0, Smi::FromInt(kind)); |
| 3811 literals->set(1, *element_values); | 3761 literals->set(1, *element_values); |
| 3812 | 3762 |
| 3813 return factory()->NewArrayLiteral( | 3763 return factory()->NewArrayLiteral( |
| 3814 literals, values, literal_index, is_simple, depth); | 3764 literals, values, literal_index, is_simple, depth); |
| 3815 } | 3765 } |
| 3816 | 3766 |
| 3817 | 3767 |
| 3818 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3768 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
| 3819 return property != NULL && | 3769 return property != NULL && |
| 3820 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 3770 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
| (...skipping 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5974 ASSERT(info->isolate()->has_pending_exception()); | 5924 ASSERT(info->isolate()->has_pending_exception()); |
| 5975 } else { | 5925 } else { |
| 5976 result = parser.ParseProgram(); | 5926 result = parser.ParseProgram(); |
| 5977 } | 5927 } |
| 5978 } | 5928 } |
| 5979 info->SetFunction(result); | 5929 info->SetFunction(result); |
| 5980 return (result != NULL); | 5930 return (result != NULL); |
| 5981 } | 5931 } |
| 5982 | 5932 |
| 5983 } } // namespace v8::internal | 5933 } } // namespace v8::internal |
| OLD | NEW |