OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 Expression* ParseMemberExpression(bool* ok); | 151 Expression* ParseMemberExpression(bool* ok); |
152 Expression* ParseMemberWithNewPrefixesExpression(List<int>* new_prefixes, | 152 Expression* ParseMemberWithNewPrefixesExpression(List<int>* new_prefixes, |
153 bool* ok); | 153 bool* ok); |
154 Expression* ParsePrimaryExpression(bool* ok); | 154 Expression* ParsePrimaryExpression(bool* ok); |
155 Expression* ParseArrayLiteral(bool* ok); | 155 Expression* ParseArrayLiteral(bool* ok); |
156 Expression* ParseObjectLiteral(bool* ok); | 156 Expression* ParseObjectLiteral(bool* ok); |
157 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); | 157 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); |
158 | 158 |
159 // Decide if a property should be the object boilerplate. | 159 // Decide if a property should be the object boilerplate. |
160 bool IsBoilerplateProperty(ObjectLiteral::Property* property); | 160 bool IsBoilerplateProperty(ObjectLiteral::Property* property); |
161 // If the property is CONSTANT type, it returns the literal value, | 161 // If the property is CONSTANT type, return the literal value; |
162 // otherwise, it return undefined literal as the placeholder | 162 // if the property is OBJECT_LITERAL and the object literal is |
163 // simple return a fixed array containing the keys and values of the | |
164 // object literal. | |
165 // Otherwise, it return undefined literal as the placeholder | |
Mads Ager (chromium)
2009/03/06 09:30:54
it return -> return.
| |
163 // in the object literal boilerplate. | 166 // in the object literal boilerplate. |
164 Literal* GetBoilerplateValue(ObjectLiteral::Property* property); | 167 Handle<Object> GetBoilerplateValue(ObjectLiteral::Property* property); |
165 | 168 |
166 enum FunctionLiteralType { | 169 enum FunctionLiteralType { |
167 EXPRESSION, | 170 EXPRESSION, |
168 DECLARATION, | 171 DECLARATION, |
169 NESTED | 172 NESTED |
170 }; | 173 }; |
171 | 174 |
172 ZoneList<Expression*>* ParseArguments(bool* ok); | 175 ZoneList<Expression*>* ParseArguments(bool* ok); |
173 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, | 176 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, |
174 int function_token_position, | 177 int function_token_position, |
(...skipping 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3076 return NEW(ArrayLiteral(literals, values.elements())); | 3079 return NEW(ArrayLiteral(literals, values.elements())); |
3077 } | 3080 } |
3078 | 3081 |
3079 | 3082 |
3080 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3083 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
3081 return property != NULL && | 3084 return property != NULL && |
3082 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 3085 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
3083 } | 3086 } |
3084 | 3087 |
3085 | 3088 |
3086 Literal* Parser::GetBoilerplateValue(ObjectLiteral::Property* property) { | 3089 Handle<Object> Parser::GetBoilerplateValue(ObjectLiteral::Property* property) { |
3087 if (property->kind() == ObjectLiteral::Property::CONSTANT) | 3090 if (property->kind() == ObjectLiteral::Property::CONSTANT) |
3088 return property->value()->AsLiteral(); | 3091 return property->value()->AsLiteral()->handle(); |
3089 return GetLiteralUndefined(); | 3092 if (property->kind() == ObjectLiteral::Property::OBJECT_LITERAL) { |
3093 ObjectLiteral* object_literal = property->value()->AsObjectLiteral(); | |
3094 if (object_literal->is_simple()) { | |
3095 return object_literal->constant_properties(); | |
3096 } | |
3097 } | |
3098 return Factory::undefined_value(); | |
3090 } | 3099 } |
3091 | 3100 |
3092 | 3101 |
3093 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3102 Expression* Parser::ParseObjectLiteral(bool* ok) { |
3094 // ObjectLiteral :: | 3103 // ObjectLiteral :: |
3095 // '{' ( | 3104 // '{' ( |
3096 // ((Identifier | String | Number) ':' AssignmentExpression) | 3105 // ((Identifier | String | Number) ':' AssignmentExpression) |
3097 // | (('get' | 'set') FunctionLiteral) | 3106 // | (('get' | 'set') FunctionLiteral) |
3098 // )*[','] '}' | 3107 // )*[','] '}' |
3099 | 3108 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3174 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 3183 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
3175 } | 3184 } |
3176 Expect(Token::RBRACE, CHECK_OK); | 3185 Expect(Token::RBRACE, CHECK_OK); |
3177 // Computation of literal_index must happen before pre parse bailout. | 3186 // Computation of literal_index must happen before pre parse bailout. |
3178 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); | 3187 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); |
3179 if (is_pre_parsing_) return NULL; | 3188 if (is_pre_parsing_) return NULL; |
3180 | 3189 |
3181 Handle<FixedArray> constant_properties = | 3190 Handle<FixedArray> constant_properties = |
3182 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); | 3191 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); |
3183 int position = 0; | 3192 int position = 0; |
3193 bool is_simple = true; | |
3184 for (int i = 0; i < properties.length(); i++) { | 3194 for (int i = 0; i < properties.length(); i++) { |
3185 ObjectLiteral::Property* property = properties.at(i); | 3195 ObjectLiteral::Property* property = properties.at(i); |
3186 if (!IsBoilerplateProperty(property)) continue; | 3196 if (!IsBoilerplateProperty(property)) { |
3197 is_simple = false; | |
3198 continue; | |
3199 } | |
3187 | 3200 |
3188 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined | 3201 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined |
3189 // value for COMPUTED properties, the real value is filled in at | 3202 // value for COMPUTED properties, the real value is filled in at |
3190 // runtime. The enumeration order is maintained. | 3203 // runtime. The enumeration order is maintained. |
3191 Handle<Object> key = property->key()->handle(); | 3204 Handle<Object> key = property->key()->handle(); |
3192 Literal* literal = GetBoilerplateValue(property); | 3205 Handle<Object> value = GetBoilerplateValue(property); |
3206 is_simple = is_simple && !value->IsUndefined(); | |
3193 | 3207 |
3194 // Add name, value pair to the fixed array. | 3208 // Add name, value pair to the fixed array. |
3195 constant_properties->set(position++, *key); | 3209 constant_properties->set(position++, *key); |
3196 constant_properties->set(position++, *literal->handle()); | 3210 constant_properties->set(position++, *value); |
3197 } | 3211 } |
3198 | 3212 |
3199 return new ObjectLiteral(constant_properties, | 3213 return new ObjectLiteral(constant_properties, |
3200 properties.elements(), | 3214 properties.elements(), |
3201 literal_index); | 3215 literal_index, |
3216 is_simple); | |
3202 } | 3217 } |
3203 | 3218 |
3204 | 3219 |
3205 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3220 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
3206 if (!scanner_.ScanRegExpPattern(seen_equal)) { | 3221 if (!scanner_.ScanRegExpPattern(seen_equal)) { |
3207 Next(); | 3222 Next(); |
3208 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3223 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
3209 *ok = false; | 3224 *ok = false; |
3210 return NULL; | 3225 return NULL; |
3211 } | 3226 } |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4513 start_position, | 4528 start_position, |
4514 is_expression); | 4529 is_expression); |
4515 return result; | 4530 return result; |
4516 } | 4531 } |
4517 | 4532 |
4518 | 4533 |
4519 #undef NEW | 4534 #undef NEW |
4520 | 4535 |
4521 | 4536 |
4522 } } // namespace v8::internal | 4537 } } // namespace v8::internal |
OLD | NEW |