OLD | NEW |
---|---|
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 Loading... | |
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 scanner_(scanner), | 81 scanner_(scanner), |
82 stack_limit_(stack_limit), | 82 stack_limit_(stack_limit), |
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 Loading... | |
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); | |
490 IdentifierT ParsePropertyName(bool* ok); | |
484 typename Traits::Type::ExpressionList ParseArguments(bool* ok); | 491 typename Traits::Type::ExpressionList ParseArguments(bool* ok); |
485 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); | 492 ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); |
486 ExpressionT ParseYieldExpression(bool* ok); | 493 ExpressionT ParseYieldExpression(bool* ok); |
487 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); | 494 ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok); |
488 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 495 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
489 ExpressionT ParseUnaryExpression(bool* ok); | 496 ExpressionT ParseUnaryExpression(bool* ok); |
490 ExpressionT ParsePostfixExpression(bool* ok); | 497 ExpressionT ParsePostfixExpression(bool* ok); |
491 ExpressionT ParseLeftHandSideExpression(bool* ok); | 498 ExpressionT ParseLeftHandSideExpression(bool* ok); |
492 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 499 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
493 ExpressionT ParseMemberExpression(bool* ok); | 500 ExpressionT ParseMemberExpression(bool* ok); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 | 579 |
573 private: | 580 private: |
574 Scanner* scanner_; | 581 Scanner* scanner_; |
575 uintptr_t stack_limit_; | 582 uintptr_t stack_limit_; |
576 bool stack_overflow_; | 583 bool stack_overflow_; |
577 | 584 |
578 bool allow_lazy_; | 585 bool allow_lazy_; |
579 bool allow_natives_syntax_; | 586 bool allow_natives_syntax_; |
580 bool allow_generators_; | 587 bool allow_generators_; |
581 bool allow_arrow_functions_; | 588 bool allow_arrow_functions_; |
589 bool allow_harmony_object_literals_; | |
582 | 590 |
583 typename Traits::Type::Zone* zone_; // Only used by Parser. | 591 typename Traits::Type::Zone* zone_; // Only used by Parser. |
584 AstNode::IdGen* ast_node_id_gen_; | 592 AstNode::IdGen* ast_node_id_gen_; |
585 }; | 593 }; |
586 | 594 |
587 | 595 |
588 class PreParserIdentifier { | 596 class PreParserIdentifier { |
589 public: | 597 public: |
590 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 598 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
591 static PreParserIdentifier Default() { | 599 static PreParserIdentifier Default() { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1047 return PreParserStatement::Default(); | 1055 return PreParserStatement::Default(); |
1048 } | 1056 } |
1049 PreParserExpression NewFunctionLiteral( | 1057 PreParserExpression NewFunctionLiteral( |
1050 PreParserIdentifier name, AstValueFactory* ast_value_factory, | 1058 PreParserIdentifier name, AstValueFactory* ast_value_factory, |
1051 const PreParserScope& scope, PreParserStatementList body, | 1059 const PreParserScope& scope, PreParserStatementList body, |
1052 int materialized_literal_count, int expected_property_count, | 1060 int materialized_literal_count, int expected_property_count, |
1053 int handler_count, int parameter_count, | 1061 int handler_count, int parameter_count, |
1054 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1062 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1055 FunctionLiteral::FunctionType function_type, | 1063 FunctionLiteral::FunctionType function_type, |
1056 FunctionLiteral::IsFunctionFlag is_function, | 1064 FunctionLiteral::IsFunctionFlag is_function, |
1057 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 1065 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
1058 FunctionLiteral::KindFlag kind, int position) { | 1066 int position) { |
1059 return PreParserExpression::Default(); | 1067 return PreParserExpression::Default(); |
1060 } | 1068 } |
1061 | 1069 |
1062 // Return the object itself as AstVisitor and implement the needed | 1070 // Return the object itself as AstVisitor and implement the needed |
1063 // dummy method right in this class. | 1071 // dummy method right in this class. |
1064 PreParserFactory* visitor() { return this; } | 1072 PreParserFactory* visitor() { return this; } |
1065 BailoutReason dont_optimize_reason() { return kNoReason; } | 1073 BailoutReason dont_optimize_reason() { return kNoReason; } |
1066 int* ast_properties() { | 1074 int* ast_properties() { |
1067 static int dummy = 42; | 1075 static int dummy = 42; |
1068 return &dummy; | 1076 return &dummy; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1324 return 0; | 1332 return 0; |
1325 } | 1333 } |
1326 | 1334 |
1327 static AstValueFactory* ast_value_factory() { return NULL; } | 1335 static AstValueFactory* ast_value_factory() { return NULL; } |
1328 | 1336 |
1329 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} | 1337 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} |
1330 | 1338 |
1331 // Temporary glue; these functions will move to ParserBase. | 1339 // Temporary glue; these functions will move to ParserBase. |
1332 PreParserExpression ParseV8Intrinsic(bool* ok); | 1340 PreParserExpression ParseV8Intrinsic(bool* ok); |
1333 PreParserExpression ParseFunctionLiteral( | 1341 PreParserExpression ParseFunctionLiteral( |
1334 PreParserIdentifier name, | 1342 PreParserIdentifier name, Scanner::Location function_name_location, |
1335 Scanner::Location function_name_location, | 1343 bool name_is_strict_reserved, FunctionKind kind, |
1336 bool name_is_strict_reserved, | 1344 int function_token_position, FunctionLiteral::FunctionType type, |
1337 bool is_generator, | 1345 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1338 int function_token_position, | |
1339 FunctionLiteral::FunctionType type, | |
1340 FunctionLiteral::ArityRestriction arity_restriction, | |
1341 bool* ok); | |
1342 | 1346 |
1343 private: | 1347 private: |
1344 PreParser* pre_parser_; | 1348 PreParser* pre_parser_; |
1345 }; | 1349 }; |
1346 | 1350 |
1347 | 1351 |
1348 // Preparsing checks a JavaScript program and emits preparse-data that helps | 1352 // Preparsing checks a JavaScript program and emits preparse-data that helps |
1349 // a later parsing to be faster. | 1353 // a later parsing to be faster. |
1350 // See preparse-data-format.h for the data format. | 1354 // See preparse-data-format.h for the data format. |
1351 | 1355 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 | 1466 |
1463 V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name, | 1467 V8_INLINE void SkipLazyFunctionBody(PreParserIdentifier function_name, |
1464 int* materialized_literal_count, | 1468 int* materialized_literal_count, |
1465 int* expected_property_count, bool* ok); | 1469 int* expected_property_count, bool* ok); |
1466 V8_INLINE PreParserStatementList | 1470 V8_INLINE PreParserStatementList |
1467 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1471 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, |
1468 Variable* fvar, Token::Value fvar_init_op, | 1472 Variable* fvar, Token::Value fvar_init_op, |
1469 bool is_generator, bool* ok); | 1473 bool is_generator, bool* ok); |
1470 | 1474 |
1471 Expression ParseFunctionLiteral( | 1475 Expression ParseFunctionLiteral( |
1472 Identifier name, | 1476 Identifier name, Scanner::Location function_name_location, |
1473 Scanner::Location function_name_location, | 1477 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, | 1478 FunctionLiteral::FunctionType function_type, |
1478 FunctionLiteral::ArityRestriction arity_restriction, | 1479 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1479 bool* ok); | |
1480 void ParseLazyFunctionLiteralBody(bool* ok); | 1480 void ParseLazyFunctionLiteralBody(bool* ok); |
1481 | 1481 |
1482 bool CheckInOrOf(bool accept_OF); | 1482 bool CheckInOrOf(bool accept_OF); |
1483 }; | 1483 }; |
1484 | 1484 |
1485 | 1485 |
1486 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1486 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1487 PreParserIdentifier function_name, int pos, Variable* fvar, | 1487 PreParserIdentifier function_name, int pos, Variable* fvar, |
1488 Token::Value fvar_init_op, bool is_generator, bool* ok) { | 1488 Token::Value fvar_init_op, bool is_generator, bool* ok) { |
1489 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1489 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1845 Expect(Token::RBRACK, CHECK_OK); | 1845 Expect(Token::RBRACK, CHECK_OK); |
1846 | 1846 |
1847 // Update the scope information before the pre-parsing bailout. | 1847 // Update the scope information before the pre-parsing bailout. |
1848 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1848 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1849 | 1849 |
1850 return factory()->NewArrayLiteral(values, literal_index, pos); | 1850 return factory()->NewArrayLiteral(values, literal_index, pos); |
1851 } | 1851 } |
1852 | 1852 |
1853 | 1853 |
1854 template <class Traits> | 1854 template <class Traits> |
1855 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName( | |
1856 bool* is_getter, bool* is_setter, bool* ok) { | |
1857 Token::Value next = peek(); | |
1858 switch (next) { | |
1859 case Token::STRING: | |
1860 Consume(Token::STRING); | |
1861 return this->GetSymbol(scanner_); | |
1862 case Token::NUMBER: | |
1863 Consume(Token::NUMBER); | |
1864 return this->GetNumberAsSymbol(scanner_); | |
1865 default: | |
1866 return ParseIdentifierNameOrGetOrSet(is_getter, is_setter, | |
1867 CHECK_OK_CUSTOM(EmptyIdentifier)); | |
1868 } | |
1869 } | |
1870 | |
1871 | |
1872 template <class Traits> | |
1873 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParsePropertyName( | |
rossberg
2014/08/25 09:39:30
Nit: Given that it's called only in one place, I d
arv (Not doing code reviews)
2014/09/02 14:42:48
This was done done for readability. The out params
arv (Not doing code reviews)
2014/09/09 22:24:27
Removed.
| |
1874 bool* ok) { | |
1875 bool is_getter = false; | |
1876 bool is_setter = false; | |
1877 return ParsePropertyName(&is_getter, &is_setter, | |
1878 CHECK_OK_CUSTOM(EmptyIdentifier)); | |
1879 } | |
1880 | |
1881 | |
1882 template <class Traits> | |
1855 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< | 1883 typename ParserBase<Traits>::ObjectLiteralPropertyT ParserBase< |
1856 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) { | 1884 Traits>::ParsePropertyDefinition(ObjectLiteralChecker* checker, bool* ok) { |
1857 LiteralT key = this->EmptyLiteral(); | 1885 // TODO(arv): Add support for concise generator methods. |
1886 ExpressionT value = this->EmptyExpression(); | |
1887 bool is_getter = false; | |
1888 bool is_setter = false; | |
1858 Token::Value next = peek(); | 1889 Token::Value next = peek(); |
1859 int next_pos = peek_position(); | 1890 int next_pos = peek_position(); |
1891 IdentifierT name = ParsePropertyName( | |
1892 &is_getter, &is_setter, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | |
1893 if (fni_ != NULL) this->PushLiteralName(fni_, name); | |
1860 | 1894 |
1861 switch (next) { | 1895 // PropertyDefinition : PropertyName ':' AssignmentExpression |
1862 case Token::STRING: { | 1896 if (peek() == Token::COLON) { |
1863 Consume(Token::STRING); | 1897 checker->CheckProperty(next, kValueProperty, |
rossberg
2014/08/25 09:39:30
Can this check be factored out and moved after the
arv (Not doing code reviews)
2014/09/02 14:42:48
I had that at first but the call to CheckProperty
arv (Not doing code reviews)
2014/09/09 22:24:27
Decided not to change this.
1. The duplicate chec
| |
1864 IdentifierT string = this->GetSymbol(scanner_); | 1898 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1865 if (fni_ != NULL) this->PushLiteralName(fni_, string); | 1899 Consume(Token::COLON); |
1866 uint32_t index; | 1900 value = this->ParseAssignmentExpression( |
1867 if (this->IsArrayIndex(string, &index)) { | 1901 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 | 1902 |
1887 if ((is_getter || is_setter) && peek() != Token::COLON) { | 1903 // Concise Method |
rossberg
2014/08/25 09:39:30
Nit: V8 typically uses a style where a comment lik
arv (Not doing code reviews)
2014/09/09 22:24:27
Done.
| |
1888 // Special handling of getter and setter syntax: | 1904 } else if (allow_harmony_object_literals_ && peek() == Token::LPAREN) { |
1889 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } | 1905 checker->CheckProperty(next, kValueProperty, |
1890 // We have already read the "get" or "set" keyword. | 1906 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1891 IdentifierT name = this->EmptyIdentifier(); | 1907 value = this->ParseFunctionLiteral( |
1892 switch (peek()) { | 1908 name, scanner()->location(), |
1893 case Token::STRING: | 1909 false, // reserved words are allowed here |
1894 Consume(Token::STRING); | 1910 FunctionKind::kConciseMethod, RelocInfo::kNoPosition, |
1895 name = this->GetSymbol(scanner_); | 1911 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::NORMAL_ARITY, |
1896 break; | 1912 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1897 case Token::NUMBER: | 1913 |
1898 Consume(Token::NUMBER); | 1914 // Accessor |
1899 name = this->GetNumberAsSymbol(scanner_); | 1915 } else if (is_getter || is_setter) { |
1900 break; | 1916 name = ParsePropertyName(CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1901 default: | 1917 // Validate the property. |
1902 name = ParseIdentifierName( | 1918 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; |
1903 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1919 checker->CheckProperty(next, type, |
1904 } | 1920 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1905 // Validate the property. | 1921 typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral( |
1906 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; | 1922 name, scanner()->location(), |
1907 checker->CheckProperty(next, type, | 1923 false, // reserved words are allowed here |
1908 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1924 FunctionKind::kNormalFunction, RelocInfo::kNoPosition, |
1909 typename Traits::Type::FunctionLiteral value = | 1925 FunctionLiteral::ANONYMOUS_EXPRESSION, |
1910 this->ParseFunctionLiteral( | 1926 is_getter ? FunctionLiteral::GETTER_ARITY |
1911 name, scanner()->location(), | 1927 : FunctionLiteral::SETTER_ARITY, |
1912 false, // reserved words are allowed here | 1928 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1913 false, // not a generator | 1929 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos); |
1914 RelocInfo::kNoPosition, FunctionLiteral::ANONYMOUS_EXPRESSION, | 1930 } else { |
1915 is_getter ? FunctionLiteral::GETTER_ARITY | 1931 Token::Value next = Next(); |
1916 : FunctionLiteral::SETTER_ARITY, | 1932 ReportUnexpectedToken(next); |
1917 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1933 *ok = false; |
1918 return factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 1934 return this->EmptyObjectLiteralProperty(); |
1919 } | |
1920 // Failed to parse as get/set property, so it's just a normal property | |
1921 // (which might be called "get" or "set" or something else). | |
1922 key = factory()->NewStringLiteral(id, next_pos); | |
1923 } | |
1924 } | 1935 } |
1925 | 1936 |
1926 // Validate the property | 1937 LiteralT key = this->EmptyLiteral(); |
rossberg
2014/08/25 09:39:30
Nit: use ?: instead of `if` to avoid the redundant
arv (Not doing code reviews)
2014/09/09 22:24:27
Done.
| |
1927 checker->CheckProperty(next, kValueProperty, | 1938 uint32_t index; |
1928 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1939 if (this->IsArrayIndex(name, &index)) { |
1929 | 1940 key = factory()->NewNumberLiteral(index, next_pos); |
1930 Expect(Token::COLON, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1941 } else { |
1931 ExpressionT value = this->ParseAssignmentExpression( | 1942 key = factory()->NewStringLiteral(name, next_pos); |
1932 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1943 } |
1933 | 1944 |
1934 return factory()->NewObjectLiteralProperty(key, value); | 1945 return factory()->NewObjectLiteralProperty(key, value); |
1935 } | 1946 } |
1936 | 1947 |
1937 | 1948 |
1938 template <class Traits> | 1949 template <class Traits> |
1939 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( | 1950 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( |
1940 bool* ok) { | 1951 bool* ok) { |
1941 // ObjectLiteral :: | 1952 // ObjectLiteral :: |
1942 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' | 1953 // '{' (PropertyDefinition (',' PropertyDefinition)* ','? )? '}' |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2421 bool is_strict_reserved_name = false; | 2432 bool is_strict_reserved_name = false; |
2422 Scanner::Location function_name_location = Scanner::Location::invalid(); | 2433 Scanner::Location function_name_location = Scanner::Location::invalid(); |
2423 FunctionLiteral::FunctionType function_type = | 2434 FunctionLiteral::FunctionType function_type = |
2424 FunctionLiteral::ANONYMOUS_EXPRESSION; | 2435 FunctionLiteral::ANONYMOUS_EXPRESSION; |
2425 if (peek_any_identifier()) { | 2436 if (peek_any_identifier()) { |
2426 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 2437 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
2427 CHECK_OK); | 2438 CHECK_OK); |
2428 function_name_location = scanner()->location(); | 2439 function_name_location = scanner()->location(); |
2429 function_type = FunctionLiteral::NAMED_EXPRESSION; | 2440 function_type = FunctionLiteral::NAMED_EXPRESSION; |
2430 } | 2441 } |
2431 result = this->ParseFunctionLiteral(name, | 2442 result = this->ParseFunctionLiteral( |
2432 function_name_location, | 2443 name, function_name_location, is_strict_reserved_name, |
2433 is_strict_reserved_name, | 2444 is_generator ? FunctionKind::kGeneratorFunction |
2434 is_generator, | 2445 : FunctionKind::kNormalFunction, |
2435 function_token_position, | 2446 function_token_position, function_type, FunctionLiteral::NORMAL_ARITY, |
2436 function_type, | 2447 CHECK_OK); |
2437 FunctionLiteral::NORMAL_ARITY, | |
2438 CHECK_OK); | |
2439 } else if (peek() == Token::SUPER) { | 2448 } else if (peek() == Token::SUPER) { |
2440 int beg_pos = position(); | 2449 int beg_pos = position(); |
2441 Consume(Token::SUPER); | 2450 Consume(Token::SUPER); |
2442 Token::Value next = peek(); | 2451 Token::Value next = peek(); |
2443 if (next == Token::PERIOD || next == Token::LBRACK || | 2452 if (next == Token::PERIOD || next == Token::LBRACK || |
2444 next == Token::LPAREN) { | 2453 next == Token::LPAREN) { |
2445 result = this->SuperReference(scope_, factory()); | 2454 result = this->SuperReference(scope_, factory()); |
2446 } else { | 2455 } else { |
2447 ReportMessageAt(Scanner::Location(beg_pos, position()), | 2456 ReportMessageAt(Scanner::Location(beg_pos, position()), |
2448 "unexpected_super"); | 2457 "unexpected_super"); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2589 | 2598 |
2590 ast_properties = *factory()->visitor()->ast_properties(); | 2599 ast_properties = *factory()->visitor()->ast_properties(); |
2591 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); | 2600 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
2592 } | 2601 } |
2593 | 2602 |
2594 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 2603 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
2595 this->EmptyIdentifierString(), this->ast_value_factory(), scope, body, | 2604 this->EmptyIdentifierString(), this->ast_value_factory(), scope, body, |
2596 materialized_literal_count, expected_property_count, handler_count, | 2605 materialized_literal_count, expected_property_count, handler_count, |
2597 num_parameters, FunctionLiteral::kNoDuplicateParameters, | 2606 num_parameters, FunctionLiteral::kNoDuplicateParameters, |
2598 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 2607 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
2599 FunctionLiteral::kNotParenthesized, FunctionLiteral::kArrowFunction, | 2608 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, |
2600 start_pos); | 2609 start_pos); |
2601 | 2610 |
2602 function_literal->set_function_token_position(start_pos); | 2611 function_literal->set_function_token_position(start_pos); |
2603 function_literal->set_ast_properties(&ast_properties); | 2612 function_literal->set_ast_properties(&ast_properties); |
2604 function_literal->set_dont_optimize_reason(dont_optimize_reason); | 2613 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
2605 | 2614 |
2606 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 2615 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
2607 | 2616 |
2608 return function_literal; | 2617 return function_literal; |
2609 } | 2618 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2661 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2670 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2662 // Both accessors of the same type. | 2671 // Both accessors of the same type. |
2663 parser()->ReportMessage("accessor_get_set"); | 2672 parser()->ReportMessage("accessor_get_set"); |
2664 } | 2673 } |
2665 *ok = false; | 2674 *ok = false; |
2666 } | 2675 } |
2667 } | 2676 } |
2668 } } // v8::internal | 2677 } } // v8::internal |
2669 | 2678 |
2670 #endif // V8_PREPARSER_H | 2679 #endif // V8_PREPARSER_H |
OLD | NEW |