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

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

Issue 1772423002: Don't do any special normalization if a boilerplate contains function literals. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
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/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 template <class Traits> 1813 template <class Traits>
1814 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( 1814 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
1815 ExpressionClassifier* classifier, bool* ok) { 1815 ExpressionClassifier* classifier, bool* ok) {
1816 // ObjectLiteral :: 1816 // ObjectLiteral ::
1817 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 1817 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
1818 1818
1819 int pos = peek_position(); 1819 int pos = peek_position();
1820 typename Traits::Type::PropertyList properties = 1820 typename Traits::Type::PropertyList properties =
1821 this->NewPropertyList(4, zone_); 1821 this->NewPropertyList(4, zone_);
1822 int number_of_boilerplate_properties = 0; 1822 int number_of_boilerplate_properties = 0;
1823 bool has_function = false;
1824 bool has_computed_names = false; 1823 bool has_computed_names = false;
1825 ObjectLiteralChecker checker(this); 1824 ObjectLiteralChecker checker(this);
1826 1825
1827 Expect(Token::LBRACE, CHECK_OK); 1826 Expect(Token::LBRACE, CHECK_OK);
1828 1827
1829 while (peek() != Token::RBRACE) { 1828 while (peek() != Token::RBRACE) {
1830 FuncNameInferrer::State fni_state(fni_); 1829 FuncNameInferrer::State fni_state(fni_);
1831 1830
1832 const bool in_class = false; 1831 const bool in_class = false;
1833 const bool is_static = false; 1832 const bool is_static = false;
1834 const bool has_extends = false; 1833 const bool has_extends = false;
1835 bool is_computed_name = false; 1834 bool is_computed_name = false;
1836 IdentifierT name = this->EmptyIdentifier(); 1835 IdentifierT name = this->EmptyIdentifier();
1837 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 1836 ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
1838 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, 1837 &checker, in_class, has_extends, is_static, &is_computed_name, NULL,
1839 classifier, &name, CHECK_OK); 1838 classifier, &name, CHECK_OK);
1840 1839
1841 if (is_computed_name) { 1840 if (is_computed_name) {
1842 has_computed_names = true; 1841 has_computed_names = true;
1843 } 1842 }
1844 1843
1845 // Mark top-level object literals that contain function literals and 1844 // Mark top-level object literals that contain function literals and
adamk 2016/03/08 19:56:49 This is probably the comment that gave me that ide
1846 // pretenure the literal so it can be added as a constant function 1845 // pretenure the literal so it can be added as a constant function
1847 // property. (Parser only.) 1846 // property. (Parser only.)
1848 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property, 1847 this->CheckFunctionLiteralInsideTopLevelObjectLiteral(scope_, property);
1849 &has_function);
1850 1848
1851 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 1849 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
1852 if (!has_computed_names && this->IsBoilerplateProperty(property)) { 1850 if (!has_computed_names && this->IsBoilerplateProperty(property)) {
1853 number_of_boilerplate_properties++; 1851 number_of_boilerplate_properties++;
1854 } 1852 }
1855 properties->Add(property, zone()); 1853 properties->Add(property, zone());
1856 1854
1857 if (peek() != Token::RBRACE) { 1855 if (peek() != Token::RBRACE) {
1858 // Need {} because of the CHECK_OK macro. 1856 // Need {} because of the CHECK_OK macro.
1859 Expect(Token::COMMA, CHECK_OK); 1857 Expect(Token::COMMA, CHECK_OK);
1860 } 1858 }
1861 1859
1862 if (fni_ != nullptr) fni_->Infer(); 1860 if (fni_ != nullptr) fni_->Infer();
1863 1861
1864 if (allow_harmony_function_name()) { 1862 if (allow_harmony_function_name()) {
1865 Traits::SetFunctionNameFromPropertyName(property, name); 1863 Traits::SetFunctionNameFromPropertyName(property, name);
1866 } 1864 }
1867 } 1865 }
1868 Expect(Token::RBRACE, CHECK_OK); 1866 Expect(Token::RBRACE, CHECK_OK);
1869 1867
1870 // Computation of literal_index must happen before pre parse bailout. 1868 // Computation of literal_index must happen before pre parse bailout.
1871 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1869 int literal_index = function_state_->NextMaterializedLiteralIndex();
1872 1870
1873 return factory()->NewObjectLiteral(properties, 1871 return factory()->NewObjectLiteral(properties,
1874 literal_index, 1872 literal_index,
1875 number_of_boilerplate_properties, 1873 number_of_boilerplate_properties,
1876 has_function,
1877 pos); 1874 pos);
1878 } 1875 }
1879 1876
1880 1877
1881 template <class Traits> 1878 template <class Traits>
1882 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( 1879 typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
1883 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier, 1880 Scanner::Location* first_spread_arg_loc, ExpressionClassifier* classifier,
1884 bool* ok) { 1881 bool* ok) {
1885 // Arguments :: 1882 // Arguments ::
1886 // '(' (AssignmentExpression)*[','] ')' 1883 // '(' (AssignmentExpression)*[','] ')'
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3369 has_seen_constructor_ = true; 3366 has_seen_constructor_ = true;
3370 return; 3367 return;
3371 } 3368 }
3372 } 3369 }
3373 3370
3374 3371
3375 } // namespace internal 3372 } // namespace internal
3376 } // namespace v8 3373 } // namespace v8
3377 3374
3378 #endif // V8_PARSING_PARSER_BASE_H 3375 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/parsing/parser.h ('K') | « src/parsing/parser.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698