Chromium Code Reviews| 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 } | 1469 } |
| 1467 | 1470 |
| 1468 PreParserExpression NewThrowReferenceError(MessageTemplate::Template message, | 1471 PreParserExpression NewThrowReferenceError(MessageTemplate::Template message, |
| 1469 int pos) { | 1472 int pos) { |
| 1470 return PreParserExpression::Default(); | 1473 return PreParserExpression::Default(); |
| 1471 } | 1474 } |
| 1472 PreParserExpression NewThrowSyntaxError(MessageTemplate::Template message, | 1475 PreParserExpression NewThrowSyntaxError(MessageTemplate::Template message, |
| 1473 Handle<Object> arg, int pos) { | 1476 Handle<Object> arg, int pos) { |
| 1474 return PreParserExpression::Default(); | 1477 return PreParserExpression::Default(); |
| 1475 } | 1478 } |
| 1479 PreParserExpression NewThrowSyntaxError(MessageTemplate::Template message, | |
| 1480 int pos) { | |
| 1481 return PreParserExpression::Default(); | |
| 1482 } | |
| 1476 PreParserExpression NewThrowTypeError(MessageTemplate::Template message, | 1483 PreParserExpression NewThrowTypeError(MessageTemplate::Template message, |
| 1477 Handle<Object> arg, int pos) { | 1484 Handle<Object> arg, int pos) { |
| 1478 return PreParserExpression::Default(); | 1485 return PreParserExpression::Default(); |
| 1479 } | 1486 } |
| 1480 | 1487 |
| 1481 // Reporting errors. | 1488 // Reporting errors. |
| 1482 void ReportMessageAt(Scanner::Location location, | 1489 void ReportMessageAt(Scanner::Location location, |
| 1483 MessageTemplate::Template message, | 1490 MessageTemplate::Template message, |
| 1484 const char* arg = NULL, | 1491 const char* arg = NULL, |
| 1485 ParseErrorType error_type = kSyntaxError); | 1492 ParseErrorType error_type = kSyntaxError); |
| (...skipping 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3930 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. | 3937 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. |
| 3931 return Traits::CloseTemplateLiteral(&ts, start, tag); | 3938 return Traits::CloseTemplateLiteral(&ts, start, tag); |
| 3932 } | 3939 } |
| 3933 | 3940 |
| 3934 | 3941 |
| 3935 template <typename Traits> | 3942 template <typename Traits> |
| 3936 typename ParserBase<Traits>::ExpressionT | 3943 typename ParserBase<Traits>::ExpressionT |
| 3937 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 3944 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
| 3938 ExpressionT expression, int beg_pos, int end_pos, | 3945 ExpressionT expression, int beg_pos, int end_pos, |
| 3939 MessageTemplate::Template message, bool* ok) { | 3946 MessageTemplate::Template message, bool* ok) { |
| 3947 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, | |
| 3948 message, kReferenceError, ok); | |
| 3949 } | |
| 3950 | |
| 3951 | |
| 3952 template <typename Traits> | |
| 3953 typename ParserBase<Traits>::ExpressionT | |
| 3954 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | |
| 3955 ExpressionT expression, int beg_pos, int end_pos, | |
| 3956 MessageTemplate::Template message, ParseErrorType type, bool* ok) { | |
| 3940 Scanner::Location location(beg_pos, end_pos); | 3957 Scanner::Location location(beg_pos, end_pos); |
| 3941 if (this->IsIdentifier(expression)) { | 3958 if (this->IsIdentifier(expression)) { |
| 3942 if (is_strict(language_mode()) && | 3959 if (is_strict(language_mode()) && |
| 3943 this->IsEvalOrArguments(this->AsIdentifier(expression))) { | 3960 this->IsEvalOrArguments(this->AsIdentifier(expression))) { |
| 3944 this->ReportMessageAt(location, MessageTemplate::kStrictEvalArguments, | 3961 this->ReportMessageAt(location, MessageTemplate::kStrictEvalArguments, |
| 3945 kSyntaxError); | 3962 kSyntaxError); |
| 3946 *ok = false; | 3963 *ok = false; |
| 3947 return this->EmptyExpression(); | 3964 return this->EmptyExpression(); |
| 3948 } | 3965 } |
| 3949 if (is_strong(language_mode()) && | 3966 if (is_strong(language_mode()) && |
| 3950 this->IsUndefined(this->AsIdentifier(expression))) { | 3967 this->IsUndefined(this->AsIdentifier(expression))) { |
| 3951 this->ReportMessageAt(location, MessageTemplate::kStrongUndefined, | 3968 this->ReportMessageAt(location, MessageTemplate::kStrongUndefined, |
| 3952 kSyntaxError); | 3969 kSyntaxError); |
| 3953 *ok = false; | 3970 *ok = false; |
| 3954 return this->EmptyExpression(); | 3971 return this->EmptyExpression(); |
| 3955 } | 3972 } |
| 3956 } | 3973 } |
| 3957 if (expression->IsValidReferenceExpression()) { | 3974 if (expression->IsValidReferenceExpression()) { |
| 3958 return expression; | 3975 return expression; |
| 3959 } else if (expression->IsCall()) { | 3976 } else if (expression->IsCall()) { |
| 3960 // If it is a call, make it a runtime error for legacy web compatibility. | 3977 // If it is a call, make it a runtime error for legacy web compatibility. |
| 3961 // Rewrite `expr' to `expr[throw ReferenceError]'. | 3978 // Rewrite `expr' to `expr[throw ReferenceError]'. |
| 3962 int pos = location.beg_pos; | 3979 int pos = location.beg_pos; |
| 3963 ExpressionT error = this->NewThrowReferenceError(message, pos); | 3980 ExpressionT error = type == kReferenceError |
| 3981 ? this->NewThrowReferenceError(message, pos) | |
| 3982 : this->NewThrowSyntaxError(message, pos); | |
|
caitp (gmail)
2015/08/14 17:06:17
I'm not sure if this distinction is necessary or g
adamk
2015/08/15 01:06:15
Seems fine to me, and also makes sense tonot throw
| |
| 3964 return factory()->NewProperty(expression, error, pos); | 3983 return factory()->NewProperty(expression, error, pos); |
| 3965 } else { | 3984 } else { |
| 3966 this->ReportMessageAt(location, message, kReferenceError); | 3985 this->ReportMessageAt(location, message, type); |
| 3967 *ok = false; | 3986 *ok = false; |
| 3968 return this->EmptyExpression(); | 3987 return this->EmptyExpression(); |
| 3969 } | 3988 } |
| 3970 } | 3989 } |
| 3971 | 3990 |
| 3972 | 3991 |
| 3973 #undef CHECK_OK | 3992 #undef CHECK_OK |
| 3974 #undef CHECK_OK_CUSTOM | 3993 #undef CHECK_OK_CUSTOM |
| 3975 | 3994 |
| 3976 | 3995 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4023 *ok = false; | 4042 *ok = false; |
| 4024 return; | 4043 return; |
| 4025 } | 4044 } |
| 4026 has_seen_constructor_ = true; | 4045 has_seen_constructor_ = true; |
| 4027 return; | 4046 return; |
| 4028 } | 4047 } |
| 4029 } | 4048 } |
| 4030 } } // v8::internal | 4049 } } // v8::internal |
| 4031 | 4050 |
| 4032 #endif // V8_PREPARSER_H | 4051 #endif // V8_PREPARSER_H |
| OLD | NEW |