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

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

Issue 2632503003: [runtime] Allocate space for computed property names (Closed)
Patch Set: Fix some variable names. 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
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 2510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 template <typename Impl> 2521 template <typename Impl>
2522 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral( 2522 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseObjectLiteral(
2523 bool* ok) { 2523 bool* ok) {
2524 // ObjectLiteral :: 2524 // ObjectLiteral ::
2525 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 2525 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
2526 2526
2527 int pos = peek_position(); 2527 int pos = peek_position();
2528 typename Types::ObjectPropertyList properties = 2528 typename Types::ObjectPropertyList properties =
2529 impl()->NewObjectPropertyList(4); 2529 impl()->NewObjectPropertyList(4);
2530 int number_of_boilerplate_properties = 0; 2530 int number_of_boilerplate_properties = 0;
2531 int number_of_total_properties = 0;
2532
2531 bool has_computed_names = false; 2533 bool has_computed_names = false;
2532 ObjectLiteralChecker checker(this); 2534 ObjectLiteralChecker checker(this);
2533 2535
2534 Expect(Token::LBRACE, CHECK_OK); 2536 Expect(Token::LBRACE, CHECK_OK);
2535 2537
2536 while (peek() != Token::RBRACE) { 2538 while (peek() != Token::RBRACE) {
2537 FuncNameInferrer::State fni_state(fni_); 2539 FuncNameInferrer::State fni_state(fni_);
2538 2540
2539 bool is_computed_name = false; 2541 bool is_computed_name = false;
2540 ObjectLiteralPropertyT property = 2542 ObjectLiteralPropertyT property =
2541 ParseObjectPropertyDefinition(&checker, &is_computed_name, CHECK_OK); 2543 ParseObjectPropertyDefinition(&checker, &is_computed_name, CHECK_OK);
2542 2544
2543 if (is_computed_name) { 2545 if (is_computed_name) {
2544 has_computed_names = true; 2546 has_computed_names = true;
2545 } 2547 }
2546 2548
2547 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 2549 if (impl()->IsBoilerplateProperty(property)) {
2548 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) { 2550 number_of_total_properties++;
Toon Verwaest 2017/01/18 08:49:53 So this isn't needed given we do properties->Add a
Franzi 2017/01/18 14:23:10 Deleted.
2549 number_of_boilerplate_properties++; 2551 // Count CONSTANT or COMPUTED properties to maintain the enumeration
2552 // order.
2553 if (!has_computed_names) {
2554 number_of_boilerplate_properties++;
2555 }
2550 } 2556 }
2551 properties->Add(property, zone()); 2557 properties->Add(property, zone());
2552 2558
2553 if (peek() != Token::RBRACE) { 2559 if (peek() != Token::RBRACE) {
2554 // Need {} because of the CHECK_OK macro. 2560 // Need {} because of the CHECK_OK macro.
2555 Expect(Token::COMMA, CHECK_OK); 2561 Expect(Token::COMMA, CHECK_OK);
2556 } 2562 }
2557 2563
2558 if (fni_ != nullptr) fni_->Infer(); 2564 if (fni_ != nullptr) fni_->Infer();
2559 } 2565 }
2560 Expect(Token::RBRACE, CHECK_OK); 2566 Expect(Token::RBRACE, CHECK_OK);
2561 2567
2562 // Computation of literal_index must happen before pre parse bailout. 2568 // Computation of literal_index must happen before pre parse bailout.
2563 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2569 int literal_index = function_state_->NextMaterializedLiteralIndex();
2564 2570
2565 return factory()->NewObjectLiteral(properties, 2571 return factory()->NewObjectLiteral(properties, literal_index,
2566 literal_index,
2567 number_of_boilerplate_properties, 2572 number_of_boilerplate_properties,
2568 pos); 2573 number_of_total_properties, pos);
2569 } 2574 }
2570 2575
2571 template <typename Impl> 2576 template <typename Impl>
2572 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments( 2577 typename ParserBase<Impl>::ExpressionListT ParserBase<Impl>::ParseArguments(
2573 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) { 2578 Scanner::Location* first_spread_arg_loc, bool maybe_arrow, bool* ok) {
2574 // Arguments :: 2579 // Arguments ::
2575 // '(' (AssignmentExpression)*[','] ')' 2580 // '(' (AssignmentExpression)*[','] ')'
2576 2581
2577 Scanner::Location spread_arg = Scanner::Location::invalid(); 2582 Scanner::Location spread_arg = Scanner::Location::invalid();
2578 ExpressionListT result = impl()->NewExpressionList(4); 2583 ExpressionListT result = impl()->NewExpressionList(4);
(...skipping 2965 matching lines...) Expand 10 before | Expand all | Expand 10 after
5544 has_seen_constructor_ = true; 5549 has_seen_constructor_ = true;
5545 return; 5550 return;
5546 } 5551 }
5547 } 5552 }
5548 5553
5549 5554
5550 } // namespace internal 5555 } // namespace internal
5551 } // namespace v8 5556 } // namespace v8
5552 5557
5553 #endif // V8_PARSING_PARSER_BASE_H 5558 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/objects.cc ('K') | « src/objects-inl.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698