OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 3239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3250 Expression* Parser::ParseObjectLiteral(bool* ok) { |
3251 // ObjectLiteral :: | 3251 // ObjectLiteral :: |
3252 // '{' ( | 3252 // '{' ( |
3253 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 3253 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
3254 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 3254 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
3255 // )*[','] '}' | 3255 // )*[','] '}' |
3256 | 3256 |
3257 ZoneList<ObjectLiteral::Property*>* properties = | 3257 ZoneList<ObjectLiteral::Property*>* properties = |
3258 new ZoneList<ObjectLiteral::Property*>(4); | 3258 new ZoneList<ObjectLiteral::Property*>(4); |
3259 int number_of_boilerplate_properties = 0; | 3259 int number_of_boilerplate_properties = 0; |
| 3260 bool has_function = false; |
3260 | 3261 |
3261 ObjectLiteralPropertyChecker checker(this, temp_scope_->StrictMode()); | 3262 ObjectLiteralPropertyChecker checker(this, temp_scope_->StrictMode()); |
3262 | 3263 |
3263 Expect(Token::LBRACE, CHECK_OK); | 3264 Expect(Token::LBRACE, CHECK_OK); |
3264 Scanner::Location loc = scanner().location(); | 3265 Scanner::Location loc = scanner().location(); |
3265 | 3266 |
3266 while (peek() != Token::RBRACE) { | 3267 while (peek() != Token::RBRACE) { |
3267 if (fni_ != NULL) fni_->Enter(); | 3268 if (fni_ != NULL) fni_->Enter(); |
3268 | 3269 |
3269 Literal* key = NULL; | 3270 Literal* key = NULL; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3337 return NULL; | 3338 return NULL; |
3338 } | 3339 } |
3339 } | 3340 } |
3340 | 3341 |
3341 Expect(Token::COLON, CHECK_OK); | 3342 Expect(Token::COLON, CHECK_OK); |
3342 Expression* value = ParseAssignmentExpression(true, CHECK_OK); | 3343 Expression* value = ParseAssignmentExpression(true, CHECK_OK); |
3343 | 3344 |
3344 ObjectLiteral::Property* property = | 3345 ObjectLiteral::Property* property = |
3345 new ObjectLiteral::Property(key, value); | 3346 new ObjectLiteral::Property(key, value); |
3346 | 3347 |
| 3348 if (value->AsFunctionLiteral() != NULL) has_function = true; |
| 3349 |
3347 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 3350 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
3348 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; | 3351 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; |
3349 // Validate the property | 3352 // Validate the property |
3350 checker.CheckProperty(property, loc, CHECK_OK); | 3353 checker.CheckProperty(property, loc, CHECK_OK); |
3351 properties->Add(property); | 3354 properties->Add(property); |
3352 | 3355 |
3353 // TODO(1240767): Consider allowing trailing comma. | 3356 // TODO(1240767): Consider allowing trailing comma. |
3354 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 3357 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
3355 | 3358 |
3356 if (fni_ != NULL) { | 3359 if (fni_ != NULL) { |
(...skipping 15 matching lines...) Expand all Loading... |
3372 BuildObjectLiteralConstantProperties(properties, | 3375 BuildObjectLiteralConstantProperties(properties, |
3373 constant_properties, | 3376 constant_properties, |
3374 &is_simple, | 3377 &is_simple, |
3375 &fast_elements, | 3378 &fast_elements, |
3376 &depth); | 3379 &depth); |
3377 return new ObjectLiteral(constant_properties, | 3380 return new ObjectLiteral(constant_properties, |
3378 properties, | 3381 properties, |
3379 literal_index, | 3382 literal_index, |
3380 is_simple, | 3383 is_simple, |
3381 fast_elements, | 3384 fast_elements, |
3382 depth); | 3385 depth, |
| 3386 has_function); |
3383 } | 3387 } |
3384 | 3388 |
3385 | 3389 |
3386 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3390 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
3387 if (!scanner().ScanRegExpPattern(seen_equal)) { | 3391 if (!scanner().ScanRegExpPattern(seen_equal)) { |
3388 Next(); | 3392 Next(); |
3389 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3393 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
3390 *ok = false; | 3394 *ok = false; |
3391 return NULL; | 3395 return NULL; |
3392 } | 3396 } |
(...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5027 Handle<String> source = Handle<String>(String::cast(script->source())); | 5031 Handle<String> source = Handle<String>(String::cast(script->source())); |
5028 result = parser.ParseProgram(source, info->is_global()); | 5032 result = parser.ParseProgram(source, info->is_global()); |
5029 } | 5033 } |
5030 } | 5034 } |
5031 | 5035 |
5032 info->SetFunction(result); | 5036 info->SetFunction(result); |
5033 return (result != NULL); | 5037 return (result != NULL); |
5034 } | 5038 } |
5035 | 5039 |
5036 } } // namespace v8::internal | 5040 } } // namespace v8::internal |
OLD | NEW |