| 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/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 void CheckArityRestrictions( | 707 void CheckArityRestrictions( |
| 708 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 708 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 709 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 709 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); |
| 710 | 710 |
| 711 // Checks if the expression is a valid reference expression (e.g., on the | 711 // Checks if the expression is a valid reference expression (e.g., on the |
| 712 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 712 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
| 713 // we allow calls for web compatibility and rewrite them to a runtime throw. | 713 // we allow calls for web compatibility and rewrite them to a runtime throw. |
| 714 ExpressionT CheckAndRewriteReferenceExpression( | 714 ExpressionT CheckAndRewriteReferenceExpression( |
| 715 ExpressionT expression, int beg_pos, int end_pos, | 715 ExpressionT expression, int beg_pos, int end_pos, |
| 716 MessageTemplate::Template message, bool* ok); | 716 MessageTemplate::Template message, bool* ok); |
| 717 ExpressionT CheckAndRewriteReferenceExpression( |
| 718 ExpressionT expression, int beg_pos, int end_pos, |
| 719 MessageTemplate::Template message, ParseErrorType type, bool* ok); |
| 717 | 720 |
| 718 // Used to validate property names in object literals and class literals | 721 // Used to validate property names in object literals and class literals |
| 719 enum PropertyKind { | 722 enum PropertyKind { |
| 720 kAccessorProperty, | 723 kAccessorProperty, |
| 721 kValueProperty, | 724 kValueProperty, |
| 722 kMethodProperty | 725 kMethodProperty |
| 723 }; | 726 }; |
| 724 | 727 |
| 725 class ObjectLiteralCheckerBase { | 728 class ObjectLiteralCheckerBase { |
| 726 public: | 729 public: |
| (...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3930 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. | 3933 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. |
| 3931 return Traits::CloseTemplateLiteral(&ts, start, tag); | 3934 return Traits::CloseTemplateLiteral(&ts, start, tag); |
| 3932 } | 3935 } |
| 3933 | 3936 |
| 3934 | 3937 |
| 3935 template <typename Traits> | 3938 template <typename Traits> |
| 3936 typename ParserBase<Traits>::ExpressionT | 3939 typename ParserBase<Traits>::ExpressionT |
| 3937 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 3940 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
| 3938 ExpressionT expression, int beg_pos, int end_pos, | 3941 ExpressionT expression, int beg_pos, int end_pos, |
| 3939 MessageTemplate::Template message, bool* ok) { | 3942 MessageTemplate::Template message, bool* ok) { |
| 3943 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, |
| 3944 message, kReferenceError, ok); |
| 3945 } |
| 3946 |
| 3947 |
| 3948 template <typename Traits> |
| 3949 typename ParserBase<Traits>::ExpressionT |
| 3950 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
| 3951 ExpressionT expression, int beg_pos, int end_pos, |
| 3952 MessageTemplate::Template message, ParseErrorType type, bool* ok) { |
| 3940 Scanner::Location location(beg_pos, end_pos); | 3953 Scanner::Location location(beg_pos, end_pos); |
| 3941 if (this->IsIdentifier(expression)) { | 3954 if (this->IsIdentifier(expression)) { |
| 3942 if (is_strict(language_mode()) && | 3955 if (is_strict(language_mode()) && |
| 3943 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 3956 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
| 3944 this->ReportMessageAt(location, MessageTemplate::kStrictEvalArguments, | 3957 this->ReportMessageAt(location, MessageTemplate::kStrictEvalArguments, |
| 3945 kSyntaxError); | 3958 kSyntaxError); |
| 3946 *ok = false; | 3959 *ok = false; |
| 3947 return this->EmptyExpression(); | 3960 return this->EmptyExpression(); |
| 3948 } | 3961 } |
| 3949 if (is_strong(language_mode()) && | 3962 if (is_strong(language_mode()) && |
| 3950 this->IsUndefined(this->AsIdentifier(expression))) { | 3963 this->IsUndefined(this->AsIdentifier(expression))) { |
| 3951 this->ReportMessageAt(location, MessageTemplate::kStrongUndefined, | 3964 this->ReportMessageAt(location, MessageTemplate::kStrongUndefined, |
| 3952 kSyntaxError); | 3965 kSyntaxError); |
| 3953 *ok = false; | 3966 *ok = false; |
| 3954 return this->EmptyExpression(); | 3967 return this->EmptyExpression(); |
| 3955 } | 3968 } |
| 3956 } | 3969 } |
| 3957 if (expression->IsValidReferenceExpression()) { | 3970 if (expression->IsValidReferenceExpression()) { |
| 3958 return expression; | 3971 return expression; |
| 3959 } else if (expression->IsCall()) { | 3972 } else if (expression->IsCall()) { |
| 3960 // If it is a call, make it a runtime error for legacy web compatibility. | 3973 // If it is a call, make it a runtime error for legacy web compatibility. |
| 3961 // Rewrite `expr' to `expr[throw ReferenceError]'. | 3974 // Rewrite `expr' to `expr[throw ReferenceError]'. |
| 3962 int pos = location.beg_pos; | 3975 int pos = location.beg_pos; |
| 3963 ExpressionT error = this->NewThrowReferenceError(message, pos); | 3976 ExpressionT error = this->NewThrowReferenceError(message, pos); |
| 3964 return factory()->NewProperty(expression, error, pos); | 3977 return factory()->NewProperty(expression, error, pos); |
| 3965 } else { | 3978 } else { |
| 3966 this->ReportMessageAt(location, message, kReferenceError); | 3979 this->ReportMessageAt(location, message, type); |
| 3967 *ok = false; | 3980 *ok = false; |
| 3968 return this->EmptyExpression(); | 3981 return this->EmptyExpression(); |
| 3969 } | 3982 } |
| 3970 } | 3983 } |
| 3971 | 3984 |
| 3972 | 3985 |
| 3973 #undef CHECK_OK | 3986 #undef CHECK_OK |
| 3974 #undef CHECK_OK_CUSTOM | 3987 #undef CHECK_OK_CUSTOM |
| 3975 | 3988 |
| 3976 | 3989 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4023 *ok = false; | 4036 *ok = false; |
| 4024 return; | 4037 return; |
| 4025 } | 4038 } |
| 4026 has_seen_constructor_ = true; | 4039 has_seen_constructor_ = true; |
| 4027 return; | 4040 return; |
| 4028 } | 4041 } |
| 4029 } | 4042 } |
| 4030 } } // v8::internal | 4043 } } // v8::internal |
| 4031 | 4044 |
| 4032 #endif // V8_PREPARSER_H | 4045 #endif // V8_PREPARSER_H |
| OLD | NEW |