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/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 483 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
484 ExpressionT ParseUnaryExpression(bool* ok); | 484 ExpressionT ParseUnaryExpression(bool* ok); |
485 ExpressionT ParsePostfixExpression(bool* ok); | 485 ExpressionT ParsePostfixExpression(bool* ok); |
486 ExpressionT ParseLeftHandSideExpression(bool* ok); | 486 ExpressionT ParseLeftHandSideExpression(bool* ok); |
487 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); | 487 ExpressionT ParseMemberWithNewPrefixesExpression(bool* ok); |
488 ExpressionT ParseMemberExpression(bool* ok); | 488 ExpressionT ParseMemberExpression(bool* ok); |
489 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, | 489 ExpressionT ParseMemberExpressionContinuation(ExpressionT expression, |
490 bool* ok); | 490 bool* ok); |
491 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, | 491 ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, |
492 bool* ok); | 492 bool* ok); |
493 ExpressionT ParseClassLiteral(IdentifierT name, | |
494 Scanner::Location function_name_location, | |
495 bool name_is_strict_reserved, int pos, | |
496 bool* ok); | |
497 | 493 |
498 // Checks if the expression is a valid reference expression (e.g., on the | 494 // Checks if the expression is a valid reference expression (e.g., on the |
499 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 495 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
500 // we allow calls for web compatibility and rewrite them to a runtime throw. | 496 // we allow calls for web compatibility and rewrite them to a runtime throw. |
501 ExpressionT CheckAndRewriteReferenceExpression( | 497 ExpressionT CheckAndRewriteReferenceExpression( |
502 ExpressionT expression, | 498 ExpressionT expression, |
503 Scanner::Location location, const char* message, bool* ok); | 499 Scanner::Location location, const char* message, bool* ok); |
504 | 500 |
505 // Used to detect duplicates in object literals. Each of the values | 501 // Used to detect duplicates in object literals. Each of the values |
506 // kGetterProperty, kSetterProperty and kValueProperty represents | 502 // kGetterProperty, kSetterProperty and kValueProperty represents |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 const PreParserScope& scope, PreParserStatementList body, | 1080 const PreParserScope& scope, PreParserStatementList body, |
1085 int materialized_literal_count, int expected_property_count, | 1081 int materialized_literal_count, int expected_property_count, |
1086 int handler_count, int parameter_count, | 1082 int handler_count, int parameter_count, |
1087 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1083 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1088 FunctionLiteral::FunctionType function_type, | 1084 FunctionLiteral::FunctionType function_type, |
1089 FunctionLiteral::IsFunctionFlag is_function, | 1085 FunctionLiteral::IsFunctionFlag is_function, |
1090 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1086 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
1091 int position) { | 1087 int position) { |
1092 return PreParserExpression::Default(); | 1088 return PreParserExpression::Default(); |
1093 } | 1089 } |
1094 PreParserExpression NewClassLiteral(PreParserIdentifier name, | |
1095 PreParserExpression extends, | |
1096 PreParserExpression constructor, | |
1097 PreParserExpressionList properties, | |
1098 int start_position, int end_position) { | |
1099 return PreParserExpression::Default(); | |
1100 } | |
1101 | 1090 |
1102 // Return the object itself as AstVisitor and implement the needed | 1091 // Return the object itself as AstVisitor and implement the needed |
1103 // dummy method right in this class. | 1092 // dummy method right in this class. |
1104 PreParserFactory* visitor() { return this; } | 1093 PreParserFactory* visitor() { return this; } |
1105 int* ast_properties() { | 1094 int* ast_properties() { |
1106 static int dummy = 42; | 1095 static int dummy = 42; |
1107 return &dummy; | 1096 return &dummy; |
1108 } | 1097 } |
1109 }; | 1098 }; |
1110 | 1099 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 static PreParserExpression ThisExpression(PreParserScope* scope, | 1299 static PreParserExpression ThisExpression(PreParserScope* scope, |
1311 PreParserFactory* factory) { | 1300 PreParserFactory* factory) { |
1312 return PreParserExpression::This(); | 1301 return PreParserExpression::This(); |
1313 } | 1302 } |
1314 | 1303 |
1315 static PreParserExpression SuperReference(PreParserScope* scope, | 1304 static PreParserExpression SuperReference(PreParserScope* scope, |
1316 PreParserFactory* factory) { | 1305 PreParserFactory* factory) { |
1317 return PreParserExpression::Super(); | 1306 return PreParserExpression::Super(); |
1318 } | 1307 } |
1319 | 1308 |
1320 static PreParserExpression ClassExpression( | |
1321 PreParserIdentifier name, PreParserExpression extends, | |
1322 PreParserExpression constructor, PreParserExpressionList properties, | |
1323 int start_position, int end_position, PreParserFactory* factory) { | |
1324 return PreParserExpression::Default(); | |
1325 } | |
1326 | |
1327 static PreParserExpression DefaultConstructor(bool call_super, | 1309 static PreParserExpression DefaultConstructor(bool call_super, |
1328 PreParserScope* scope, int pos, | 1310 PreParserScope* scope, int pos, |
1329 int end_pos) { | 1311 int end_pos) { |
1330 return PreParserExpression::Default(); | 1312 return PreParserExpression::Default(); |
1331 } | 1313 } |
1332 | 1314 |
1333 static PreParserExpression ExpressionFromLiteral( | 1315 static PreParserExpression ExpressionFromLiteral( |
1334 Token::Value token, int pos, Scanner* scanner, | 1316 Token::Value token, int pos, Scanner* scanner, |
1335 PreParserFactory* factory) { | 1317 PreParserFactory* factory) { |
1336 return PreParserExpression::Default(); | 1318 return PreParserExpression::Default(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} | 1371 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} |
1390 | 1372 |
1391 // Temporary glue; these functions will move to ParserBase. | 1373 // Temporary glue; these functions will move to ParserBase. |
1392 PreParserExpression ParseV8Intrinsic(bool* ok); | 1374 PreParserExpression ParseV8Intrinsic(bool* ok); |
1393 PreParserExpression ParseFunctionLiteral( | 1375 PreParserExpression ParseFunctionLiteral( |
1394 PreParserIdentifier name, Scanner::Location function_name_location, | 1376 PreParserIdentifier name, Scanner::Location function_name_location, |
1395 bool name_is_strict_reserved, FunctionKind kind, | 1377 bool name_is_strict_reserved, FunctionKind kind, |
1396 int function_token_position, FunctionLiteral::FunctionType type, | 1378 int function_token_position, FunctionLiteral::FunctionType type, |
1397 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1379 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1398 | 1380 |
| 1381 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 1382 Scanner::Location class_name_location, |
| 1383 bool name_is_strict_reserved, int pos, |
| 1384 bool* ok); |
| 1385 |
1399 private: | 1386 private: |
1400 PreParser* pre_parser_; | 1387 PreParser* pre_parser_; |
1401 }; | 1388 }; |
1402 | 1389 |
1403 | 1390 |
1404 // Preparsing checks a JavaScript program and emits preparse-data that helps | 1391 // Preparsing checks a JavaScript program and emits preparse-data that helps |
1405 // a later parsing to be faster. | 1392 // a later parsing to be faster. |
1406 // See preparse-data-format.h for the data format. | 1393 // See preparse-data-format.h for the data format. |
1407 | 1394 |
1408 // The PreParser checks that the syntax follows the grammar for JavaScript, | 1395 // The PreParser checks that the syntax follows the grammar for JavaScript, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 Variable* fvar, Token::Value fvar_init_op, | 1513 Variable* fvar, Token::Value fvar_init_op, |
1527 bool is_generator, bool* ok); | 1514 bool is_generator, bool* ok); |
1528 | 1515 |
1529 Expression ParseFunctionLiteral( | 1516 Expression ParseFunctionLiteral( |
1530 Identifier name, Scanner::Location function_name_location, | 1517 Identifier name, Scanner::Location function_name_location, |
1531 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, | 1518 bool name_is_strict_reserved, FunctionKind kind, int function_token_pos, |
1532 FunctionLiteral::FunctionType function_type, | 1519 FunctionLiteral::FunctionType function_type, |
1533 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1520 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1534 void ParseLazyFunctionLiteralBody(bool* ok); | 1521 void ParseLazyFunctionLiteralBody(bool* ok); |
1535 | 1522 |
| 1523 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 1524 Scanner::Location class_name_location, |
| 1525 bool name_is_strict_reserved, int pos, |
| 1526 bool* ok); |
| 1527 |
1536 bool CheckInOrOf(bool accept_OF); | 1528 bool CheckInOrOf(bool accept_OF); |
1537 }; | 1529 }; |
1538 | 1530 |
1539 | 1531 |
1540 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1532 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1541 PreParserIdentifier function_name, int pos, Variable* fvar, | 1533 PreParserIdentifier function_name, int pos, Variable* fvar, |
1542 Token::Value fvar_init_op, bool is_generator, bool* ok) { | 1534 Token::Value fvar_init_op, bool is_generator, bool* ok) { |
1543 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1535 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1544 | 1536 |
1545 ParseSourceElements(Token::RBRACE, ok); | 1537 ParseSourceElements(Token::RBRACE, ok); |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2728 | 2720 |
2729 function_literal->set_function_token_position(start_pos); | 2721 function_literal->set_function_token_position(start_pos); |
2730 function_literal->set_ast_properties(&ast_properties); | 2722 function_literal->set_ast_properties(&ast_properties); |
2731 | 2723 |
2732 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 2724 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
2733 | 2725 |
2734 return function_literal; | 2726 return function_literal; |
2735 } | 2727 } |
2736 | 2728 |
2737 | 2729 |
2738 template <class Traits> | |
2739 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral( | |
2740 IdentifierT name, Scanner::Location class_name_location, | |
2741 bool name_is_strict_reserved, int pos, bool* ok) { | |
2742 // All parts of a ClassDeclaration or a ClassExpression are strict code. | |
2743 if (name_is_strict_reserved) { | |
2744 ReportMessageAt(class_name_location, "unexpected_strict_reserved"); | |
2745 *ok = false; | |
2746 return this->EmptyExpression(); | |
2747 } | |
2748 if (this->IsEvalOrArguments(name)) { | |
2749 ReportMessageAt(class_name_location, "strict_eval_arguments"); | |
2750 *ok = false; | |
2751 return this->EmptyExpression(); | |
2752 } | |
2753 | |
2754 bool has_extends = false; | |
2755 ExpressionT extends = this->EmptyExpression(); | |
2756 if (Check(Token::EXTENDS)) { | |
2757 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); | |
2758 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); | |
2759 scope_->SetStrictMode(STRICT); | |
2760 extends = this->ParseLeftHandSideExpression(CHECK_OK); | |
2761 has_extends = true; | |
2762 } | |
2763 | |
2764 // TODO(arv): Implement scopes and name binding in class body only. | |
2765 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); | |
2766 BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); | |
2767 scope_->SetStrictMode(STRICT); | |
2768 scope_->SetScopeName(name); | |
2769 | |
2770 typename Traits::Type::PropertyList properties = | |
2771 this->NewPropertyList(4, zone_); | |
2772 ExpressionT constructor = this->EmptyExpression(); | |
2773 bool has_seen_constructor = false; | |
2774 | |
2775 Expect(Token::LBRACE, CHECK_OK); | |
2776 while (peek() != Token::RBRACE) { | |
2777 if (Check(Token::SEMICOLON)) continue; | |
2778 if (fni_ != NULL) fni_->Enter(); | |
2779 const bool in_class = true; | |
2780 const bool is_static = false; | |
2781 bool old_has_seen_constructor = has_seen_constructor; | |
2782 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | |
2783 NULL, in_class, is_static, &has_seen_constructor, CHECK_OK); | |
2784 | |
2785 if (has_seen_constructor != old_has_seen_constructor) { | |
2786 constructor = this->GetPropertyValue(property); | |
2787 } else { | |
2788 properties->Add(property, zone()); | |
2789 } | |
2790 | |
2791 if (fni_ != NULL) { | |
2792 fni_->Infer(); | |
2793 fni_->Leave(); | |
2794 } | |
2795 } | |
2796 | |
2797 int end_pos = peek_position(); | |
2798 Expect(Token::RBRACE, CHECK_OK); | |
2799 | |
2800 if (!has_seen_constructor) { | |
2801 constructor = | |
2802 this->DefaultConstructor(has_extends, scope_, pos, end_pos + 1); | |
2803 } | |
2804 | |
2805 return this->ClassExpression(name, extends, constructor, properties, pos, | |
2806 end_pos + 1, factory()); | |
2807 } | |
2808 | |
2809 | |
2810 template <typename Traits> | 2730 template <typename Traits> |
2811 typename ParserBase<Traits>::ExpressionT | 2731 typename ParserBase<Traits>::ExpressionT |
2812 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 2732 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
2813 ExpressionT expression, | 2733 ExpressionT expression, |
2814 Scanner::Location location, const char* message, bool* ok) { | 2734 Scanner::Location location, const char* message, bool* ok) { |
2815 if (strict_mode() == STRICT && this->IsIdentifier(expression) && | 2735 if (strict_mode() == STRICT && this->IsIdentifier(expression) && |
2816 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 2736 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
2817 this->ReportMessageAt(location, "strict_eval_arguments", false); | 2737 this->ReportMessageAt(location, "strict_eval_arguments", false); |
2818 *ok = false; | 2738 *ok = false; |
2819 return this->EmptyExpression(); | 2739 return this->EmptyExpression(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2859 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2779 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
2860 // Both accessors of the same type. | 2780 // Both accessors of the same type. |
2861 parser()->ReportMessage("accessor_get_set"); | 2781 parser()->ReportMessage("accessor_get_set"); |
2862 } | 2782 } |
2863 *ok = false; | 2783 *ok = false; |
2864 } | 2784 } |
2865 } | 2785 } |
2866 } } // v8::internal | 2786 } } // v8::internal |
2867 | 2787 |
2868 #endif // V8_PREPARSER_H | 2788 #endif // V8_PREPARSER_H |
OLD | NEW |