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