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

Side by Side Diff: src/parsing/parser-base.h

Issue 2632503003: [runtime] Allocate space for computed property names (Closed)
Patch Set: Comments and reorder. Created 3 years, 11 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
« no previous file with comments | « src/objects-inl.h ('k') | src/parsing/preparser.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/scopes.h" 9 #include "src/ast/scopes.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 template <typename Impl> 2533 template <typename Impl>
2534 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( 2534 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
2535 bool* ok) { 2535 bool* ok) {
2536 // ObjectLiteral :: 2536 // ObjectLiteral ::
2537 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2537 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2538 2538
2539 int pos = peek_position(); 2539 int pos = peek_position();
2540 typename Types::ObjectPropertyList properties = 2540 typename Types::ObjectPropertyList properties =
2541 impl()->NewObjectPropertyList(4); 2541 impl()->NewObjectPropertyList(4);
2542 int number_of_boilerplate_properties = 0; 2542 int number_of_boilerplate_properties = 0;
2543 bool has_seen_proto = false;
2544
2543 bool has_computed_names = false; 2545 bool has_computed_names = false;
2544 bool has_rest_property = false; 2546 bool has_rest_property = false;
2545 ObjectLiteralChecker checker(this); 2547 ObjectLiteralChecker checker(this);
2546 2548
2547 Expect(Token::LBRACE, CHECK_OK); 2549 Expect(Token::LBRACE, CHECK_OK);
2548 2550
2549 while (peek() != Token::RBRACE) { 2551 while (peek() != Token::RBRACE) {
2550 FuncNameInferrer::State fni_state(fni_); 2552 FuncNameInferrer::State fni_state(fni_);
2551 2553
2552 bool is_computed_name = false; 2554 bool is_computed_name = false;
2553 bool is_rest_property = false; 2555 bool is_rest_property = false;
2554 ObjectLiteralPropertyT property = ParseObjectPropertyDefinition( 2556 ObjectLiteralPropertyT property = ParseObjectPropertyDefinition(
2555 &checker, &is_computed_name, &is_rest_property, CHECK_OK); 2557 &checker, &is_computed_name, &is_rest_property, CHECK_OK);
2556 2558
2557 if (is_computed_name) { 2559 if (is_computed_name) {
2558 has_computed_names = true; 2560 has_computed_names = true;
2559 } 2561 }
2560 2562
2561 if (is_rest_property) { 2563 if (is_rest_property) {
2562 has_rest_property = true; 2564 has_rest_property = true;
2563 } 2565 }
2564 2566
2565 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 2567 if (!impl()->IsBoilerplateProperty(property)) {
2566 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) { 2568 has_seen_proto = true;
2569 } else if (!has_computed_names) {
2570 // Count CONSTANT or COMPUTED properties to maintain the enumeration
2571 // order.
2567 number_of_boilerplate_properties++; 2572 number_of_boilerplate_properties++;
2568 } 2573 }
2574
2569 properties->Add(property, zone()); 2575 properties->Add(property, zone());
2570 2576
2571 if (peek() != Token::RBRACE) { 2577 if (peek() != Token::RBRACE) {
2572 // Need {} because of the CHECK_OK macro. 2578 // Need {} because of the CHECK_OK macro.
2573 Expect(Token::COMMA, CHECK_OK); 2579 Expect(Token::COMMA, CHECK_OK);
2574 } 2580 }
2575 2581
2576 if (fni_ != nullptr) fni_->Infer(); 2582 if (fni_ != nullptr) fni_->Infer();
2577 } 2583 }
2578 Expect(Token::RBRACE, CHECK_OK); 2584 Expect(Token::RBRACE, CHECK_OK);
2579 2585
2580 // Computation of literal_index must happen before pre parse bailout. 2586 // Computation of literal_index must happen before pre parse bailout.
2581 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2587 int literal_index = function_state_->NextMaterializedLiteralIndex();
2582 2588
2583 return factory()->NewObjectLiteral(properties, literal_index, 2589 return factory()->NewObjectLiteral(properties, literal_index,
2584 number_of_boilerplate_properties, pos, 2590 number_of_boilerplate_properties,
2585 has_rest_property); 2591 has_seen_proto, pos, has_rest_property);
2586 } 2592 }
2587 2593
2588 template <typename Impl> 2594 template <typename Impl>
2589 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments( 2595 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments(
2590 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) { 2596 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) {
2591 // Arguments :: 2597 // Arguments ::
2592 // '(' (AssignmentExpression)*[','] ')' 2598 // '(' (AssignmentExpression)*[','] ')'
2593 2599
2594 Scanner::Location spread_arg = Scanner::Location::invalid(); 2600 Scanner::Location spread_arg = Scanner::Location::invalid();
2595 ExpressionListT result = impl()->NewExpressionList(4); 2601 ExpressionListT result = impl()->NewExpressionList(4);
(...skipping 2965 matching lines...) Expand 10 before | Expand all | Expand 10 after
5561 has_seen_constructor_ = true; 5567 has_seen_constructor_ = true;
5562 return; 5568 return;
5563 } 5569 }
5564 } 5570 }
5565 5571
5566 5572
5567 } // namespace internal 5573 } // namespace internal
5568 } // namespace v8 5574 } // namespace v8
5569 5575
5570 #endif // V8_PARSING_PARSER_BASE_H 5576 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698