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

Side by Side Diff: src/preparser.h

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: merge Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 fni_(NULL), 78 fni_(NULL),
79 log_(log), 79 log_(log),
80 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 80 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
81 stack_limit_(stack_limit), 81 stack_limit_(stack_limit),
82 scanner_(scanner), 82 scanner_(scanner),
83 stack_overflow_(false), 83 stack_overflow_(false),
84 allow_lazy_(false), 84 allow_lazy_(false),
85 allow_natives_syntax_(false), 85 allow_natives_syntax_(false),
86 allow_generators_(false), 86 allow_generators_(false),
87 allow_arrow_functions_(false), 87 allow_arrow_functions_(false),
88 allow_harmony_object_literals_(false),
88 zone_(zone), 89 zone_(zone),
89 ast_node_id_gen_(ast_node_id_gen) {} 90 ast_node_id_gen_(ast_node_id_gen) {}
90 91
91 // Getters that indicate whether certain syntactical constructs are 92 // Getters that indicate whether certain syntactical constructs are
92 // allowed to be parsed by this instance of the parser. 93 // allowed to be parsed by this instance of the parser.
93 bool allow_lazy() const { return allow_lazy_; } 94 bool allow_lazy() const { return allow_lazy_; }
94 bool allow_natives_syntax() const { return allow_natives_syntax_; } 95 bool allow_natives_syntax() const { return allow_natives_syntax_; }
95 bool allow_generators() const { return allow_generators_; } 96 bool allow_generators() const { return allow_generators_; }
96 bool allow_arrow_functions() const { return allow_arrow_functions_; } 97 bool allow_arrow_functions() const { return allow_arrow_functions_; }
97 bool allow_modules() const { return scanner()->HarmonyModules(); } 98 bool allow_modules() const { return scanner()->HarmonyModules(); }
98 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } 99 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); }
99 bool allow_harmony_numeric_literals() const { 100 bool allow_harmony_numeric_literals() const {
100 return scanner()->HarmonyNumericLiterals(); 101 return scanner()->HarmonyNumericLiterals();
101 } 102 }
102 bool allow_classes() const { return scanner()->HarmonyClasses(); } 103 bool allow_classes() const { return scanner()->HarmonyClasses(); }
104 bool allow_harmony_object_literals() const {
105 return allow_harmony_object_literals_;
106 }
103 107
104 // Setters that determine whether certain syntactical constructs are 108 // Setters that determine whether certain syntactical constructs are
105 // allowed to be parsed by this instance of the parser. 109 // allowed to be parsed by this instance of the parser.
106 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } 110 void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
107 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; } 111 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; }
108 void set_allow_generators(bool allow) { allow_generators_ = allow; } 112 void set_allow_generators(bool allow) { allow_generators_ = allow; }
109 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } 113 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; }
110 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } 114 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); }
111 void set_allow_harmony_scoping(bool allow) { 115 void set_allow_harmony_scoping(bool allow) {
112 scanner()->SetHarmonyScoping(allow); 116 scanner()->SetHarmonyScoping(allow);
113 } 117 }
114 void set_allow_harmony_numeric_literals(bool allow) { 118 void set_allow_harmony_numeric_literals(bool allow) {
115 scanner()->SetHarmonyNumericLiterals(allow); 119 scanner()->SetHarmonyNumericLiterals(allow);
116 } 120 }
117 void set_allow_classes(bool allow) { 121 void set_allow_classes(bool allow) { scanner()->SetHarmonyClasses(allow); }
118 scanner()->SetHarmonyClasses(allow); 122 void set_allow_harmony_object_literals(bool allow) {
123 allow_harmony_object_literals_ = allow;
119 } 124 }
120 125
121 protected: 126 protected:
122 friend class Traits::Checkpoint; 127 friend class Traits::Checkpoint;
123 128
124 enum AllowEvalOrArgumentsAsIdentifier { 129 enum AllowEvalOrArgumentsAsIdentifier {
125 kAllowEvalOrArguments, 130 kAllowEvalOrArguments,
126 kDontAllowEvalOrArguments 131 kDontAllowEvalOrArguments
127 }; 132 };
128 133
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 bool* ok); 479 bool* ok);
475 480
476 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok); 481 ExpressionT ParseRegExpLiteral(bool seen_equal, bool* ok);
477 482
478 ExpressionT ParsePrimaryExpression(bool* ok); 483 ExpressionT ParsePrimaryExpression(bool* ok);
479 ExpressionT ParseExpression(bool accept_IN, bool* ok); 484 ExpressionT ParseExpression(bool accept_IN, bool* ok);
480 ExpressionT ParseArrayLiteral(bool* ok); 485 ExpressionT ParseArrayLiteral(bool* ok);
481 ExpressionT ParseObjectLiteral(bool* ok); 486 ExpressionT ParseObjectLiteral(bool* ok);
482 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker, 487 ObjectLiteralPropertyT ParsePropertyDefinition(ObjectLiteralChecker* checker,
483 bool* ok); 488 bool* ok);
489 IdentifierT ParsePropertyName(bool* is_getter, bool* is_setter, bool* ok);
484 typename Traits::Type::ExpressionList ParseArguments(bool* ok); 490 typename Traits::Type::ExpressionList ParseArguments(bool* ok);
485 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); 491 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok);
486 ExpressionT ParseYieldExpression(bool* ok); 492 ExpressionT ParseYieldExpression(bool* ok);
487 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); 493 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok);
488 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); 494 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
489 ExpressionT ParseUnaryExpression(bool* ok); 495 ExpressionT ParseUnaryExpression(bool* ok);
490 ExpressionT ParsePostfixExpression(bool* ok); 496 ExpressionT ParsePostfixExpression(bool* ok);
491 ExpressionT ParseLeftHandSideExpression(bool* ok); 497 ExpressionT ParseLeftHandSideExpression(bool* ok);
492 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); 498 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok);
493 ExpressionT ParseMemberExpression(bool* ok); 499 ExpressionT ParseMemberExpression(bool* ok);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 uintptr_t stack_limit_; 578 uintptr_t stack_limit_;
573 579
574 private: 580 private:
575 Scanner* scanner_; 581 Scanner* scanner_;
576 bool stack_overflow_; 582 bool stack_overflow_;
577 583
578 bool allow_lazy_; 584 bool allow_lazy_;
579 bool allow_natives_syntax_; 585 bool allow_natives_syntax_;
580 bool allow_generators_; 586 bool allow_generators_;
581 bool allow_arrow_functions_; 587 bool allow_arrow_functions_;
588 bool allow_harmony_object_literals_;
582 589
583 typename Traits::Type::Zone* zone_; // Only used by Parser. 590 typename Traits::Type::Zone* zone_; // Only used by Parser.
584 AstNode::IdGen* ast_node_id_gen_; 591 AstNode::IdGen* ast_node_id_gen_;
585 }; 592 };
586 593
587 594
588 class PreParserIdentifier { 595 class PreParserIdentifier {
589 public: 596 public:
590 PreParserIdentifier() : type_(kUnknownIdentifier) {} 597 PreParserIdentifier() : type_(kUnknownIdentifier) {}
591 static PreParserIdentifier Default() { 598 static PreParserIdentifier Default() {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 return PreParserStatement::Default(); 1054 return PreParserStatement::Default();
1048 } 1055 }
1049 PreParserExpression NewFunctionLiteral( 1056 PreParserExpression NewFunctionLiteral(
1050 PreParserIdentifier name, AstValueFactory* ast_value_factory, 1057 PreParserIdentifier name, AstValueFactory* ast_value_factory,
1051 const PreParserScope& scope, PreParserStatementList body, 1058 const PreParserScope& scope, PreParserStatementList body,
1052 int materialized_literal_count, int expected_property_count, 1059 int materialized_literal_count, int expected_property_count,
1053 int handler_count, int parameter_count, 1060 int handler_count, int parameter_count,
1054 FunctionLiteral::ParameterFlag has_duplicate_parameters, 1061 FunctionLiteral::ParameterFlag has_duplicate_parameters,
1055 FunctionLiteral::FunctionType function_type, 1062 FunctionLiteral::FunctionType function_type,
1056 FunctionLiteral::IsFunctionFlag is_function, 1063 FunctionLiteral::IsFunctionFlag is_function,
1057 FunctionLiteral::IsParenthesizedFlag is_parenthesized, 1064 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
1058 FunctionLiteral::KindFlag kind, int position) { 1065 int position) {
1059 return PreParserExpression::Default(); 1066 return PreParserExpression::Default();
1060 } 1067 }
1061 1068
1062 // Return the object itself as AstVisitor and implement the needed 1069 // Return the object itself as AstVisitor and implement the needed
1063 // dummy method right in this class. 1070 // dummy method right in this class.
1064 PreParserFactory* visitor() { return this; } 1071 PreParserFactory* visitor() { return this; }
1065 BailoutReason dont_optimize_reason() { return kNoReason; } 1072 BailoutReason dont_optimize_reason() { return kNoReason; }
1066 int* ast_properties() { 1073 int* ast_properties() {
1067 static int dummy = 42; 1074 static int dummy = 42;
1068 return &dummy; 1075 return &dummy;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 return 0; 1331 return 0;
1325 } 1332 }
1326 1333
1327 static AstValueFactory* ast_value_factory() { return NULL; } 1334 static AstValueFactory* ast_value_factory() { return NULL; }
1328 1335
1329 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} 1336 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {}
1330 1337
1331 // Temporary glue; these functions will move to ParserBase. 1338 // Temporary glue; these functions will move to ParserBase.
1332 PreParserExpression ParseV8Intrinsic(bool* ok); 1339 PreParserExpression ParseV8Intrinsic(bool* ok);
1333 PreParserExpression ParseFunctionLiteral( 1340 PreParserExpression ParseFunctionLiteral(
1334 PreParserIdentifier name, 1341 PreParserIdentifier name, Scanner::Location function_name_location,
1335 Scanner::Location function_name_location, 1342 bool name_is_strict_reserved, FunctionKind kind,
1336 bool name_is_strict_reserved, 1343 int function_token_position, FunctionLiteral::FunctionType type,
1337 bool is_generator, 1344 FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
1338 int function_token_position,
1339 FunctionLiteral::FunctionType type,
1340 FunctionLiteral::ArityRestriction arity_restriction,
1341 bool* ok);
1342 1345
1343 private: 1346 private:
1344 PreParser* pre_parser_; 1347 PreParser* pre_parser_;
1345 }; 1348 };
1346 1349
1347 1350
1348 // Preparsing checks a JavaScript program and emits preparse-data that helps 1351 // Preparsing checks a JavaScript program and emits preparse-data that helps
1349 // a later parsing to be faster. 1352 // a later parsing to be faster.
1350 // See preparse-data-format.h for the data format. 1353 // See preparse-data-format.h for the data format.
1351 1354
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1465
1463 V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name, 1466 V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name,
1464 int* materialized_literal_count, 1467 int* materialized_literal_count,
1465 int* expected_property_count, bool* ok); 1468 int* expected_property_count, bool* ok);
1466 V8_INLINE PreParserStatementList 1469 V8_INLINE PreParserStatementList
1467 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, 1470 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos,
1468 Variable* fvar, Token::Value fvar_init_op, 1471 Variable* fvar, Token::Value fvar_init_op,
1469 bool is_generator, bool* ok); 1472 bool is_generator, bool* ok);
1470 1473
1471 Expression ParseFunctionLiteral( 1474 Expression ParseFunctionLiteral(
1472 Identifier name, 1475 Identifier name, Scanner::Location function_name_location,
1473 Scanner::Location function_name_location, 1476 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos,
1474 bool name_is_strict_reserved,
1475 bool is_generator,
1476 int function_token_pos,
1477 FunctionLiteral::FunctionType function_type, 1477 FunctionLiteral::FunctionType function_type,
1478 FunctionLiteral::ArityRestriction arity_restriction, 1478 FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
1479 bool* ok);
1480 void ParseLazyFunctionLiteralBody(bool* ok); 1479 void ParseLazyFunctionLiteralBody(bool* ok);
1481 1480
1482 bool CheckInOrOf(bool accept_OF); 1481 bool CheckInOrOf(bool accept_OF);
1483 }; 1482 };
1484 1483
1485 1484
1486 PreParserStatementList PreParser::ParseEagerFunctionBody( 1485 PreParserStatementList PreParser::ParseEagerFunctionBody(
1487 PreParserIdentifier function_name, int pos, Variable* fvar, 1486 PreParserIdentifier function_name, int pos, Variable* fvar,
1488 Token::Value fvar_init_op, bool is_generator, bool* ok) { 1487 Token::Value fvar_init_op, bool is_generator, bool* ok) {
1489 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1488 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 Expect(Token::RBRACK, CHECK_OK); 1844 Expect(Token::RBRACK, CHECK_OK);
1846 1845
1847 // Update the scope information before the pre-parsing bailout. 1846 // Update the scope information before the pre-parsing bailout.
1848 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1847 int literal_index = function_state_->NextMaterializedLiteralIndex();
1849 1848
1850 return factory()->NewArrayLiteral(values, literal_index, pos); 1849 return factory()->NewArrayLiteral(values, literal_index, pos);
1851 } 1850 }
1852 1851
1853 1852
1854 template <class Traits> 1853 template <class Traits>
1854 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName(
1855 bool* is_getter, bool* is_setter, bool* ok) {
1856 Token::Value next = peek();
1857 switch (next) {
1858 case Token::STRING:
1859 Consume(Token::STRING);
1860 return this->GetSymbol(scanner_);
1861 case Token::NUMBER:
1862 Consume(Token::NUMBER);
1863 return this->GetNumberAsSymbol(scanner_);
1864 default:
1865 return ParseIdentifierNameOrGetOrSet(is_getter, is_setter,
1866 CHECK_OK_CUSTOM(EmptyIdentifier));
1867 }
1868 }
1869
1870
1871 template <class Traits>
1855 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< 1872 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase<
1856 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) { 1873 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) {
1857 LiteralT key = this->EmptyLiteral(); 1874 // TODO(arv): Add support for concise generator methods.
1858 Token::Value next = peek(); 1875 ExpressionT value = this->EmptyExpression();
1876 bool is_getter = false;
1877 bool is_setter = false;
1878 Token::Value name_token = peek();
1859 int next_pos = peek_position(); 1879 int next_pos = peek_position();
1880 IdentifierT name = ParsePropertyName(
1881 &is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1882 if (fni_ != NULL) this->PushLiteralName(fni_, name);
1860 1883
1861 switch (next) { 1884 if (peek() == Token::COLON) {
1862 case Token::STRING: { 1885 // PropertyDefinition : PropertyName ':' AssignmentExpression
1863 Consume(Token::STRING); 1886 checker->CheckProperty(name_token, kValueProperty,
1864 IdentifierT string = this->GetSymbol(scanner_); 1887 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1865 if (fni_ != NULL) this->PushLiteralName(fni_, string); 1888 Consume(Token::COLON);
1866 uint32_t index; 1889 value = this->ParseAssignmentExpression(
1867 if (this->IsArrayIndex(string, &index)) { 1890 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1868 key = factory()->NewNumberLiteral(index, next_pos);
1869 break;
1870 }
1871 key = factory()->NewStringLiteral(string, next_pos);
1872 break;
1873 }
1874 case Token::NUMBER: {
1875 Consume(Token::NUMBER);
1876 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_,
1877 factory());
1878 break;
1879 }
1880 default: {
1881 bool is_getter = false;
1882 bool is_setter = false;
1883 IdentifierT id = ParseIdentifierNameOrGetOrSet(
1884 &is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1885 if (fni_ != NULL) this->PushLiteralName(fni_, id);
1886 1891
1887 if ((is_getter || is_setter) && peek() != Token::COLON) { 1892 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) {
1888 // Special handling of getter and setter syntax: 1893 // Concise Method
1889 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } 1894 checker->CheckProperty(name_token, kValueProperty,
1890 // We have already read the "get" or "set" keyword. 1895 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1891 IdentifierT name = this->EmptyIdentifier(); 1896 value = this->ParseFunctionLiteral(
1892 switch (peek()) { 1897 name, scanner()->location(),
1893 case Token::STRING: 1898 false, // reserved words are allowed here
1894 Consume(Token::STRING); 1899 FunctionKind::kConciseMethod, RelocInfo::kNoPosition,
1895 name = this->GetSymbol(scanner_); 1900 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY,
1896 break; 1901 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1897 case Token::NUMBER: 1902
1898 Consume(Token::NUMBER); 1903 } else if (is_getter || is_setter) {
1899 name = this->GetNumberAsSymbol(scanner_); 1904 // Accessor
1900 break; 1905 bool dont_care = false;
1901 default: 1906 name_token = peek();
1902 name = ParseIdentifierName( 1907 name = ParsePropertyName(&dont_care, &dont_care,
1903 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1908 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1904 } 1909 // Validate the property.
1905 // Validate the property. 1910 checker->CheckProperty(name_token,
1906 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; 1911 is_getter ? kGetterProperty : kSetterProperty,
1907 checker->CheckProperty(next, type, 1912 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1908 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1913 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral(
1909 typename Traits::Type::FunctionLiteral value = 1914 name, scanner()->location(),
1910 this->ParseFunctionLiteral( 1915 false, // reserved words are allowed here
1911 name, scanner()->location(), 1916 FunctionKind::kNormalFunction, RelocInfo::kNoPosition,
1912 false, // reserved words are allowed here 1917 FunctionLiteral::ANONYMOUS_EXPRESSION,
1913 false, // not a generator 1918 is_getter ? FunctionLiteral::GETTER_ARITY
1914 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, 1919 : FunctionLiteral::SETTER_ARITY,
1915 is_getter ? FunctionLiteral::GETTER_ARITY 1920 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1916 : FunctionLiteral::SETTER_ARITY, 1921 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos);
1917 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1922 } else {
1918 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos); 1923 Token::Value next = Next();
1919 } 1924 ReportUnexpectedToken(next);
1920 // Failed to parse as get/set property, so it's just a normal property 1925 *ok = false;
1921 // (which might be called "get" or "set" or something else). 1926 return this->EmptyObjectLiteralProperty();
1922 key = factory()->NewStringLiteral(id, next_pos);
1923 }
1924 } 1927 }
1925 1928
1926 // Validate the property 1929 uint32_t index;
1927 checker->CheckProperty(next, kValueProperty, 1930 LiteralT key = this->IsArrayIndex(name, &index)
1928 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1931 ? factory()->NewNumberLiteral(index, next_pos)
1929 1932 : factory()->NewStringLiteral(name, next_pos);
1930 Expect(Token::COLON, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1931 ExpressionT value = this->ParseAssignmentExpression(
1932 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1933 1933
1934 return factory()->NewObjectLiteralProperty(key, value); 1934 return factory()->NewObjectLiteralProperty(key, value);
1935 } 1935 }
1936 1936
1937 1937
1938 template <class Traits> 1938 template <class Traits>
1939 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( 1939 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
1940 bool* ok) { 1940 bool* ok) {
1941 // ObjectLiteral :: 1941 // ObjectLiteral ::
1942 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' 1942 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}'
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 bool is_strict_reserved_name = false; 2421 bool is_strict_reserved_name = false;
2422 Scanner::Location function_name_location = Scanner::Location::invalid(); 2422 Scanner::Location function_name_location = Scanner::Location::invalid();
2423 FunctionLiteral::FunctionType function_type = 2423 FunctionLiteral::FunctionType function_type =
2424 FunctionLiteral::ANONYMOUS_EXPRESSION; 2424 FunctionLiteral::ANONYMOUS_EXPRESSION;
2425 if (peek_any_identifier()) { 2425 if (peek_any_identifier()) {
2426 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 2426 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
2427 CHECK_OK); 2427 CHECK_OK);
2428 function_name_location = scanner()->location(); 2428 function_name_location = scanner()->location();
2429 function_type = FunctionLiteral::NAMED_EXPRESSION; 2429 function_type = FunctionLiteral::NAMED_EXPRESSION;
2430 } 2430 }
2431 result = this->ParseFunctionLiteral(name, 2431 result = this->ParseFunctionLiteral(
2432 function_name_location, 2432 name, function_name_location, is_strict_reserved_name,
2433 is_strict_reserved_name, 2433 is_generator ? FunctionKind::kGeneratorFunction
2434 is_generator, 2434 : FunctionKind::kNormalFunction,
2435 function_token_position, 2435 function_token_position, function_type, FunctionLiteral::NORMAL_ARITY,
2436 function_type, 2436 CHECK_OK);
2437 FunctionLiteral::NORMAL_ARITY,
2438 CHECK_OK);
2439 } else if (peek() == Token::SUPER) { 2437 } else if (peek() == Token::SUPER) {
2440 int beg_pos = position(); 2438 int beg_pos = position();
2441 Consume(Token::SUPER); 2439 Consume(Token::SUPER);
2442 Token::Value next = peek(); 2440 Token::Value next = peek();
2443 if (next == Token::PERIOD || next == Token::LBRACK || 2441 if (next == Token::PERIOD || next == Token::LBRACK ||
2444 next == Token::LPAREN) { 2442 next == Token::LPAREN) {
2445 result = this->SuperReference(scope_, factory()); 2443 result = this->SuperReference(scope_, factory());
2446 } else { 2444 } else {
2447 ReportMessageAt(Scanner::Location(beg_pos, position()), 2445 ReportMessageAt(Scanner::Location(beg_pos, position()),
2448 "unexpected_super"); 2446 "unexpected_super");
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 2587
2590 ast_properties = *factory()->visitor()->ast_properties(); 2588 ast_properties = *factory()->visitor()->ast_properties();
2591 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); 2589 dont_optimize_reason = factory()->visitor()->dont_optimize_reason();
2592 } 2590 }
2593 2591
2594 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 2592 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
2595 this->EmptyIdentifierString(), this->ast_value_factory(), scope, body, 2593 this->EmptyIdentifierString(), this->ast_value_factory(), scope, body,
2596 materialized_literal_count, expected_property_count, handler_count, 2594 materialized_literal_count, expected_property_count, handler_count,
2597 num_parameters, FunctionLiteral::kNoDuplicateParameters, 2595 num_parameters, FunctionLiteral::kNoDuplicateParameters,
2598 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, 2596 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
2599 FunctionLiteral::kNotParenthesized, FunctionLiteral::kArrowFunction, 2597 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction,
2600 start_pos); 2598 start_pos);
2601 2599
2602 function_literal->set_function_token_position(start_pos); 2600 function_literal->set_function_token_position(start_pos);
2603 function_literal->set_ast_properties(&ast_properties); 2601 function_literal->set_ast_properties(&ast_properties);
2604 function_literal->set_dont_optimize_reason(dont_optimize_reason); 2602 function_literal->set_dont_optimize_reason(dont_optimize_reason);
2605 2603
2606 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 2604 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
2607 2605
2608 return function_literal; 2606 return function_literal;
2609 } 2607 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2659 DCHECK(IsAccessorAccessorConflict(old_type, type));
2662 // Both accessors of the same type. 2660 // Both accessors of the same type.
2663 parser()->ReportMessage("accessor_get_set"); 2661 parser()->ReportMessage("accessor_get_set");
2664 } 2662 }
2665 *ok = false; 2663 *ok = false;
2666 } 2664 }
2667 } 2665 }
2668 } } // v8::internal 2666 } } // v8::internal
2669 2667
2670 #endif // V8_PREPARSER_H 2668 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698