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

Side by Side Diff: src/parser.cc

Issue 46088: Revert 1469 and 1472 due to a bug with array literals. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/runtime.h » ('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 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
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 expression is a literal, return the literal value; 161 // If the property is CONSTANT type, it returns the literal value,
162 // if the expression is a materialized literal and is simple return a 162 // otherwise, it return undefined literal as the placeholder
163 // compile time value as encoded by CompileTimeValue::GetValue().
164 // Otherwise, return undefined literal as the placeholder
165 // in the object literal boilerplate. 163 // in the object literal boilerplate.
166 Handle<Object> GetBoilerplateValue(Expression* expression); 164 Literal* GetBoilerplateValue(ObjectLiteral::Property* property);
167 165
168 enum FunctionLiteralType { 166 enum FunctionLiteralType {
169 EXPRESSION, 167 EXPRESSION,
170 DECLARATION, 168 DECLARATION,
171 NESTED 169 NESTED
172 }; 170 };
173 171
174 ZoneList<Expression*>* ParseArguments(bool* ok); 172 ZoneList<Expression*>* ParseArguments(bool* ok);
175 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, 173 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name,
176 int function_token_position, 174 int function_token_position,
(...skipping 2874 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 } 3049 }
3052 values.Add(elem); 3050 values.Add(elem);
3053 if (peek() != Token::RBRACK) { 3051 if (peek() != Token::RBRACK) {
3054 Expect(Token::COMMA, CHECK_OK); 3052 Expect(Token::COMMA, CHECK_OK);
3055 } 3053 }
3056 } 3054 }
3057 Expect(Token::RBRACK, CHECK_OK); 3055 Expect(Token::RBRACK, CHECK_OK);
3058 3056
3059 // Update the scope information before the pre-parsing bailout. 3057 // Update the scope information before the pre-parsing bailout.
3060 temp_scope_->set_contains_array_literal(); 3058 temp_scope_->set_contains_array_literal();
3061 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3062 3059
3063 if (is_pre_parsing_) return NULL; 3060 if (is_pre_parsing_) return NULL;
3064 3061
3065 // Allocate a fixed array with all the literals. 3062 // Allocate a fixed array with all the literals.
3066 Handle<FixedArray> literals = 3063 Handle<FixedArray> literals =
3067 Factory::NewFixedArray(values.length(), TENURED); 3064 Factory::NewFixedArray(values.length(), TENURED);
3068 3065
3069 // Fill in the literals. 3066 // Fill in the literals.
3070 bool is_simple = true;
3071 for (int i = 0; i < values.length(); i++) { 3067 for (int i = 0; i < values.length(); i++) {
3072 Handle<Object> boilerplate_value = GetBoilerplateValue(values.at(i)); 3068 Literal* literal = values.at(i)->AsLiteral();
3073 if (boilerplate_value->IsUndefined()) { 3069 if (literal == NULL) {
3074 literals->set_the_hole(i); 3070 literals->set_the_hole(i);
3075 is_simple = false;
3076 } else { 3071 } else {
3077 literals->set(i, *boilerplate_value); 3072 literals->set(i, *literal->handle());
3078 } 3073 }
3079 } 3074 }
3080 3075
3081 return NEW(ArrayLiteral(literals, values.elements(), 3076 return NEW(ArrayLiteral(literals, values.elements()));
3082 literal_index, is_simple));
3083 } 3077 }
3084 3078
3085 3079
3086 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 3080 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
3087 return property != NULL && 3081 return property != NULL &&
3088 property->kind() != ObjectLiteral::Property::PROTOTYPE; 3082 property->kind() != ObjectLiteral::Property::PROTOTYPE;
3089 } 3083 }
3090 3084
3091 3085
3092 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3086 Literal* Parser::GetBoilerplateValue(ObjectLiteral::Property* property) {
3093 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3087 if (property->kind() == ObjectLiteral::Property::CONSTANT)
3094 return lit != NULL && lit->is_simple(); 3088 return property->value()->AsLiteral();
3095 } 3089 return GetLiteralUndefined();
3096
3097 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) {
3098 ASSERT(IsCompileTimeValue(expression));
3099 Handle<FixedArray> result = Factory::NewFixedArray(2, TENURED);
3100 ObjectLiteral* object_literal = expression->AsObjectLiteral();
3101 if (object_literal != NULL) {
3102 ASSERT(object_literal->is_simple());
3103 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL));
3104 result->set(kElementsSlot, *object_literal->constant_properties());
3105 } else {
3106 ArrayLiteral* array_literal = expression->AsArrayLiteral();
3107 ASSERT(array_literal != NULL && array_literal->is_simple());
3108 result->set(kTypeSlot, Smi::FromInt(ARRAY_LITERAL));
3109 result->set(kElementsSlot, *array_literal->literals());
3110 }
3111 return result;
3112 }
3113
3114
3115 CompileTimeValue::Type CompileTimeValue::GetType(Handle<FixedArray> value) {
3116 Smi* type_value = Smi::cast(value->get(kTypeSlot));
3117 return static_cast<Type>(type_value->value());
3118 }
3119
3120
3121 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) {
3122 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot)));
3123 }
3124
3125
3126 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) {
3127 if (expression->AsLiteral() != NULL) {
3128 return expression->AsLiteral()->handle();
3129 }
3130 if (CompileTimeValue::IsCompileTimeValue(expression)) {
3131 return CompileTimeValue::GetValue(expression);
3132 }
3133 return Factory::undefined_value();
3134 } 3090 }
3135 3091
3136 3092
3137 Expression* Parser::ParseObjectLiteral(bool* ok) { 3093 Expression* Parser::ParseObjectLiteral(bool* ok) {
3138 // ObjectLiteral :: 3094 // ObjectLiteral ::
3139 // '{' ( 3095 // '{' (
3140 // ((Identifier | String | Number) ':' AssignmentExpression) 3096 // ((Identifier | String | Number) ':' AssignmentExpression)
3141 // | (('get' | 'set') FunctionLiteral) 3097 // | (('get' | 'set') FunctionLiteral)
3142 // )*[','] '}' 3098 // )*[','] '}'
3143 3099
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3218 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); 3174 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
3219 } 3175 }
3220 Expect(Token::RBRACE, CHECK_OK); 3176 Expect(Token::RBRACE, CHECK_OK);
3221 // Computation of literal_index must happen before pre parse bailout. 3177 // Computation of literal_index must happen before pre parse bailout.
3222 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); 3178 int literal_index = temp_scope_->NextMaterializedLiteralIndex();
3223 if (is_pre_parsing_) return NULL; 3179 if (is_pre_parsing_) return NULL;
3224 3180
3225 Handle<FixedArray> constant_properties = 3181 Handle<FixedArray> constant_properties =
3226 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); 3182 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED);
3227 int position = 0; 3183 int position = 0;
3228 bool is_simple = true;
3229 for (int i = 0; i < properties.length(); i++) { 3184 for (int i = 0; i < properties.length(); i++) {
3230 ObjectLiteral::Property* property = properties.at(i); 3185 ObjectLiteral::Property* property = properties.at(i);
3231 if (!IsBoilerplateProperty(property)) { 3186 if (!IsBoilerplateProperty(property)) continue;
3232 is_simple = false;
3233 continue;
3234 }
3235 3187
3236 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined 3188 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined
3237 // value for COMPUTED properties, the real value is filled in at 3189 // value for COMPUTED properties, the real value is filled in at
3238 // runtime. The enumeration order is maintained. 3190 // runtime. The enumeration order is maintained.
3239 Handle<Object> key = property->key()->handle(); 3191 Handle<Object> key = property->key()->handle();
3240 Handle<Object> value = GetBoilerplateValue(property->value()); 3192 Literal* literal = GetBoilerplateValue(property);
3241 is_simple = is_simple && !value->IsUndefined();
3242 3193
3243 // Add name, value pair to the fixed array. 3194 // Add name, value pair to the fixed array.
3244 constant_properties->set(position++, *key); 3195 constant_properties->set(position++, *key);
3245 constant_properties->set(position++, *value); 3196 constant_properties->set(position++, *literal->handle());
3246 } 3197 }
3247 3198
3248 return new ObjectLiteral(constant_properties, 3199 return new ObjectLiteral(constant_properties,
3249 properties.elements(), 3200 properties.elements(),
3250 literal_index, 3201 literal_index);
3251 is_simple);
3252 } 3202 }
3253 3203
3254 3204
3255 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { 3205 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
3256 if (!scanner_.ScanRegExpPattern(seen_equal)) { 3206 if (!scanner_.ScanRegExpPattern(seen_equal)) {
3257 Next(); 3207 Next();
3258 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); 3208 ReportMessage("unterminated_regexp", Vector<const char*>::empty());
3259 *ok = false; 3209 *ok = false;
3260 return NULL; 3210 return NULL;
3261 } 3211 }
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4561 start_position, 4511 start_position,
4562 is_expression); 4512 is_expression);
4563 return result; 4513 return result;
4564 } 4514 }
4565 4515
4566 4516
4567 #undef NEW 4517 #undef NEW
4568 4518
4569 4519
4570 } } // namespace v8::internal 4520 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698