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 3322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3333 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3333 Expression* Parser::ParseObjectLiteral(bool* ok) { |
3334 // ObjectLiteral :: | 3334 // ObjectLiteral :: |
3335 // '{' ( | 3335 // '{' ( |
3336 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 3336 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
3337 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 3337 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
3338 // )*[','] '}' | 3338 // )*[','] '}' |
3339 | 3339 |
3340 ZoneList<ObjectLiteral::Property*>* properties = | 3340 ZoneList<ObjectLiteral::Property*>* properties = |
3341 new ZoneList<ObjectLiteral::Property*>(4); | 3341 new ZoneList<ObjectLiteral::Property*>(4); |
3342 int number_of_boilerplate_properties = 0; | 3342 int number_of_boilerplate_properties = 0; |
| 3343 bool has_function = false; |
3343 | 3344 |
3344 ObjectLiteralPropertyChecker checker(this, top_scope_->is_strict_mode()); | 3345 ObjectLiteralPropertyChecker checker(this, top_scope_->is_strict_mode()); |
3345 | 3346 |
3346 Expect(Token::LBRACE, CHECK_OK); | 3347 Expect(Token::LBRACE, CHECK_OK); |
3347 Scanner::Location loc = scanner().location(); | 3348 Scanner::Location loc = scanner().location(); |
3348 | 3349 |
3349 while (peek() != Token::RBRACE) { | 3350 while (peek() != Token::RBRACE) { |
3350 if (fni_ != NULL) fni_->Enter(); | 3351 if (fni_ != NULL) fni_->Enter(); |
3351 | 3352 |
3352 Literal* key = NULL; | 3353 Literal* key = NULL; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 return NULL; | 3422 return NULL; |
3422 } | 3423 } |
3423 } | 3424 } |
3424 | 3425 |
3425 Expect(Token::COLON, CHECK_OK); | 3426 Expect(Token::COLON, CHECK_OK); |
3426 Expression* value = ParseAssignmentExpression(true, CHECK_OK); | 3427 Expression* value = ParseAssignmentExpression(true, CHECK_OK); |
3427 | 3428 |
3428 ObjectLiteral::Property* property = | 3429 ObjectLiteral::Property* property = |
3429 new ObjectLiteral::Property(key, value); | 3430 new ObjectLiteral::Property(key, value); |
3430 | 3431 |
| 3432 // Mark object literals that contain function literals and pretenure the |
| 3433 // literal so it can be added as a constant function property. |
| 3434 if (value->AsFunctionLiteral() != NULL) { |
| 3435 has_function = true; |
| 3436 value->AsFunctionLiteral()->set_pretenure(true); |
| 3437 } |
| 3438 |
3431 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 3439 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
3432 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; | 3440 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; |
3433 // Validate the property | 3441 // Validate the property |
3434 checker.CheckProperty(property, loc, CHECK_OK); | 3442 checker.CheckProperty(property, loc, CHECK_OK); |
3435 properties->Add(property); | 3443 properties->Add(property); |
3436 | 3444 |
3437 // TODO(1240767): Consider allowing trailing comma. | 3445 // TODO(1240767): Consider allowing trailing comma. |
3438 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 3446 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
3439 | 3447 |
3440 if (fni_ != NULL) { | 3448 if (fni_ != NULL) { |
(...skipping 15 matching lines...) Expand all Loading... |
3456 BuildObjectLiteralConstantProperties(properties, | 3464 BuildObjectLiteralConstantProperties(properties, |
3457 constant_properties, | 3465 constant_properties, |
3458 &is_simple, | 3466 &is_simple, |
3459 &fast_elements, | 3467 &fast_elements, |
3460 &depth); | 3468 &depth); |
3461 return new ObjectLiteral(constant_properties, | 3469 return new ObjectLiteral(constant_properties, |
3462 properties, | 3470 properties, |
3463 literal_index, | 3471 literal_index, |
3464 is_simple, | 3472 is_simple, |
3465 fast_elements, | 3473 fast_elements, |
3466 depth); | 3474 depth, |
| 3475 has_function); |
3467 } | 3476 } |
3468 | 3477 |
3469 | 3478 |
3470 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3479 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
3471 if (!scanner().ScanRegExpPattern(seen_equal)) { | 3480 if (!scanner().ScanRegExpPattern(seen_equal)) { |
3472 Next(); | 3481 Next(); |
3473 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3482 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
3474 *ok = false; | 3483 *ok = false; |
3475 return NULL; | 3484 return NULL; |
3476 } | 3485 } |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5155 info->is_global(), | 5164 info->is_global(), |
5156 info->StrictMode()); | 5165 info->StrictMode()); |
5157 } | 5166 } |
5158 } | 5167 } |
5159 | 5168 |
5160 info->SetFunction(result); | 5169 info->SetFunction(result); |
5161 return (result != NULL); | 5170 return (result != NULL); |
5162 } | 5171 } |
5163 | 5172 |
5164 } } // namespace v8::internal | 5173 } } // namespace v8::internal |
OLD | NEW |