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 3720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3731 ReportUnexpectedToken(tok); | 3731 ReportUnexpectedToken(tok); |
3732 *ok = false; | 3732 *ok = false; |
3733 return NULL; | 3733 return NULL; |
3734 } | 3734 } |
3735 } | 3735 } |
3736 | 3736 |
3737 return result; | 3737 return result; |
3738 } | 3738 } |
3739 | 3739 |
3740 | 3740 |
3741 void Parser::BuildArrayLiteralBoilerplateLiterals(ZoneList<Expression*>* values, | |
3742 Handle<FixedArray> literals, | |
3743 bool* is_simple, | |
3744 int* depth) { | |
3745 // Fill in the literals. | |
3746 // Accumulate output values in local variables. | |
3747 bool is_simple_acc = true; | |
3748 int depth_acc = 1; | |
3749 for (int i = 0; i < values->length(); i++) { | |
3750 MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral(); | |
3751 if (m_literal != NULL && m_literal->depth() >= depth_acc) { | |
3752 depth_acc = m_literal->depth() + 1; | |
3753 } | |
3754 Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i)); | |
3755 if (boilerplate_value->IsUndefined()) { | |
3756 literals->set_the_hole(i); | |
3757 is_simple_acc = false; | |
3758 } else { | |
3759 literals->set(i, *boilerplate_value); | |
3760 } | |
3761 } | |
3762 | |
3763 *is_simple = is_simple_acc; | |
3764 *depth = depth_acc; | |
3765 } | |
3766 | |
3767 | |
3768 Expression* Parser::ParseArrayLiteral(bool* ok) { | 3741 Expression* Parser::ParseArrayLiteral(bool* ok) { |
3769 // ArrayLiteral :: | 3742 // ArrayLiteral :: |
3770 // '[' Expression? (',' Expression?)* ']' | 3743 // '[' Expression? (',' Expression?)* ']' |
3771 | 3744 |
3772 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone()); | 3745 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone()); |
3773 Expect(Token::LBRACK, CHECK_OK); | 3746 Expect(Token::LBRACK, CHECK_OK); |
3774 while (peek() != Token::RBRACK) { | 3747 while (peek() != Token::RBRACK) { |
3775 Expression* elem; | 3748 Expression* elem; |
3776 if (peek() == Token::COMMA) { | 3749 if (peek() == Token::COMMA) { |
3777 elem = GetLiteralTheHole(); | 3750 elem = GetLiteralTheHole(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3984 entry->value = reinterpret_cast<void*> (prev | curr); | 3957 entry->value = reinterpret_cast<void*> (prev | curr); |
3985 *ok = true; | 3958 *ok = true; |
3986 } | 3959 } |
3987 | 3960 |
3988 | 3961 |
3989 void Parser::BuildObjectLiteralConstantProperties( | 3962 void Parser::BuildObjectLiteralConstantProperties( |
3990 ZoneList<ObjectLiteral::Property*>* properties, | 3963 ZoneList<ObjectLiteral::Property*>* properties, |
3991 Handle<FixedArray> constant_properties, | 3964 Handle<FixedArray> constant_properties, |
3992 bool* is_simple, | 3965 bool* is_simple, |
3993 bool* fast_elements, | 3966 bool* fast_elements, |
3994 int* depth) { | 3967 int* depth, |
| 3968 bool* may_store_doubles) { |
3995 int position = 0; | 3969 int position = 0; |
3996 // Accumulate the value in local variables and store it at the end. | 3970 // Accumulate the value in local variables and store it at the end. |
3997 bool is_simple_acc = true; | 3971 bool is_simple_acc = true; |
3998 int depth_acc = 1; | 3972 int depth_acc = 1; |
3999 uint32_t max_element_index = 0; | 3973 uint32_t max_element_index = 0; |
4000 uint32_t elements = 0; | 3974 uint32_t elements = 0; |
4001 for (int i = 0; i < properties->length(); i++) { | 3975 for (int i = 0; i < properties->length(); i++) { |
4002 ObjectLiteral::Property* property = properties->at(i); | 3976 ObjectLiteral::Property* property = properties->at(i); |
4003 if (!IsBoilerplateProperty(property)) { | 3977 if (!IsBoilerplateProperty(property)) { |
4004 is_simple_acc = false; | 3978 is_simple_acc = false; |
4005 continue; | 3979 continue; |
4006 } | 3980 } |
4007 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral(); | 3981 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral(); |
4008 if (m_literal != NULL && m_literal->depth() >= depth_acc) { | 3982 if (m_literal != NULL && m_literal->depth() >= depth_acc) { |
4009 depth_acc = m_literal->depth() + 1; | 3983 depth_acc = m_literal->depth() + 1; |
4010 } | 3984 } |
4011 | 3985 |
4012 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined | 3986 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined |
4013 // value for COMPUTED properties, the real value is filled in at | 3987 // value for COMPUTED properties, the real value is filled in at |
4014 // runtime. The enumeration order is maintained. | 3988 // runtime. The enumeration order is maintained. |
4015 Handle<Object> key = property->key()->handle(); | 3989 Handle<Object> key = property->key()->handle(); |
4016 Handle<Object> value = GetBoilerplateValue(property->value()); | 3990 Handle<Object> value = GetBoilerplateValue(property->value()); |
| 3991 |
| 3992 // Ensure objects with doubles are always treated as nested objects. |
| 3993 // TODO(verwaest): Remove once we can store them inline. |
| 3994 if (FLAG_track_double_fields && value->IsNumber()) { |
| 3995 *may_store_doubles = true; |
| 3996 } |
| 3997 |
4017 is_simple_acc = is_simple_acc && !value->IsUndefined(); | 3998 is_simple_acc = is_simple_acc && !value->IsUndefined(); |
4018 | 3999 |
4019 // Keep track of the number of elements in the object literal and | 4000 // Keep track of the number of elements in the object literal and |
4020 // the largest element index. If the largest element index is | 4001 // the largest element index. If the largest element index is |
4021 // much larger than the number of elements, creating an object | 4002 // much larger than the number of elements, creating an object |
4022 // literal with fast elements will be a waste of space. | 4003 // literal with fast elements will be a waste of space. |
4023 uint32_t element_index = 0; | 4004 uint32_t element_index = 0; |
4024 if (key->IsString() | 4005 if (key->IsString() |
4025 && Handle<String>::cast(key)->AsArrayIndex(&element_index) | 4006 && Handle<String>::cast(key)->AsArrayIndex(&element_index) |
4026 && element_index > max_element_index) { | 4007 && element_index > max_element_index) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4208 | 4189 |
4209 // Computation of literal_index must happen before pre parse bailout. | 4190 // Computation of literal_index must happen before pre parse bailout. |
4210 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 4191 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
4211 | 4192 |
4212 Handle<FixedArray> constant_properties = isolate()->factory()->NewFixedArray( | 4193 Handle<FixedArray> constant_properties = isolate()->factory()->NewFixedArray( |
4213 number_of_boilerplate_properties * 2, TENURED); | 4194 number_of_boilerplate_properties * 2, TENURED); |
4214 | 4195 |
4215 bool is_simple = true; | 4196 bool is_simple = true; |
4216 bool fast_elements = true; | 4197 bool fast_elements = true; |
4217 int depth = 1; | 4198 int depth = 1; |
| 4199 bool may_store_doubles = false; |
4218 BuildObjectLiteralConstantProperties(properties, | 4200 BuildObjectLiteralConstantProperties(properties, |
4219 constant_properties, | 4201 constant_properties, |
4220 &is_simple, | 4202 &is_simple, |
4221 &fast_elements, | 4203 &fast_elements, |
4222 &depth); | 4204 &depth, |
| 4205 &may_store_doubles); |
4223 return factory()->NewObjectLiteral(constant_properties, | 4206 return factory()->NewObjectLiteral(constant_properties, |
4224 properties, | 4207 properties, |
4225 literal_index, | 4208 literal_index, |
4226 is_simple, | 4209 is_simple, |
4227 fast_elements, | 4210 fast_elements, |
4228 depth, | 4211 depth, |
| 4212 may_store_doubles, |
4229 has_function); | 4213 has_function); |
4230 } | 4214 } |
4231 | 4215 |
4232 | 4216 |
4233 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 4217 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
4234 if (!scanner().ScanRegExpPattern(seen_equal)) { | 4218 if (!scanner().ScanRegExpPattern(seen_equal)) { |
4235 Next(); | 4219 Next(); |
4236 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 4220 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
4237 *ok = false; | 4221 *ok = false; |
4238 return NULL; | 4222 return NULL; |
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6036 ASSERT(info()->isolate()->has_pending_exception()); | 6020 ASSERT(info()->isolate()->has_pending_exception()); |
6037 } else { | 6021 } else { |
6038 result = ParseProgram(); | 6022 result = ParseProgram(); |
6039 } | 6023 } |
6040 } | 6024 } |
6041 info()->SetFunction(result); | 6025 info()->SetFunction(result); |
6042 return (result != NULL); | 6026 return (result != NULL); |
6043 } | 6027 } |
6044 | 6028 |
6045 } } // namespace v8::internal | 6029 } } // namespace v8::internal |
OLD | NEW |