Chromium Code Reviews| Index: src/parsing/parser-base.h |
| diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
| index 0a2bf4e45a045c2146c90f6ebcf90cdfa58070f8..9e0051107e3954e2b9a7f17f77d8502c8b9073da 100644 |
| --- a/src/parsing/parser-base.h |
| +++ b/src/parsing/parser-base.h |
| @@ -909,16 +909,18 @@ class ParserBase : public Traits { |
| } |
| void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { |
| - if (!classifier->is_valid_expression() || |
| - classifier->has_cover_initialized_name()) { |
| - const Scanner::Location& a = classifier->expression_error().location; |
| - const Scanner::Location& b = |
| - classifier->cover_initialized_name_error().location; |
| - if (a.beg_pos < 0 || (b.beg_pos >= 0 && a.beg_pos > b.beg_pos)) { |
|
adamk
2016/08/19 20:17:08
Ugh, I forgot about this logic, it's trying to det
caitp
2016/08/19 23:11:19
IIRC, the reason for this is related to how arrow
gsathya
2016/08/19 23:22:57
I combined CoverInitializedName with this for now.
|
| - ReportClassifierError(classifier->cover_initialized_name_error()); |
| - } else { |
| + if (!classifier->is_valid_expression()) { |
| ReportClassifierError(classifier->expression_error()); |
| - } |
| + *ok = false; |
| + } |
| + |
| + if (classifier->has_cover_initialized_name()) { |
| + ReportClassifierError(classifier->cover_initialized_name_error()); |
| + *ok = false; |
| + } |
| + |
| + if (classifier->has_annexb_duplicate_proto()) { |
| + ReportClassifierError(classifier->annexb_duplicate_proto_error()); |
| *ok = false; |
| } |
| } |
| @@ -1202,7 +1204,8 @@ class ParserBase : public Traits { |
| explicit ObjectLiteralCheckerBase(ParserBase* parser) : parser_(parser) {} |
| virtual void CheckProperty(Token::Value property, PropertyKind type, |
| - MethodKind method_type, bool* ok) = 0; |
| + MethodKind method_type, |
| + ExpressionClassifier* classifier, bool* ok) = 0; |
| virtual ~ObjectLiteralCheckerBase() {} |
| @@ -1221,7 +1224,8 @@ class ParserBase : public Traits { |
| : ObjectLiteralCheckerBase(parser), has_seen_proto_(false) {} |
| void CheckProperty(Token::Value property, PropertyKind type, |
| - MethodKind method_type, bool* ok) override; |
| + MethodKind method_type, ExpressionClassifier* classifier, |
| + bool* ok) override; |
| private: |
| bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } |
| @@ -1236,7 +1240,8 @@ class ParserBase : public Traits { |
| : ObjectLiteralCheckerBase(parser), has_seen_constructor_(false) {} |
| void CheckProperty(Token::Value property, PropertyKind type, |
| - MethodKind method_type, bool* ok) override; |
| + MethodKind method_type, ExpressionClassifier* classifier, |
| + bool* ok) override; |
| private: |
| bool IsConstructor() { |
| @@ -1980,6 +1985,7 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| // PropertyName ':' AssignmentExpression |
| if (!*is_computed_name) { |
| checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal, |
| + classifier, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| } |
| Consume(Token::COLON); |
| @@ -2080,6 +2086,7 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| // '*' PropertyName '(' StrictFormalParameters ')' '{' FunctionBody '}' |
| if (!*is_computed_name) { |
| checker->CheckProperty(name_token, kMethodProperty, method_kind, |
| + classifier, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| } |
| @@ -2130,6 +2137,7 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| if (!*is_computed_name) { |
| checker->CheckProperty(name_token, kAccessorProperty, method_kind, |
| + classifier, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| } |
| @@ -2417,6 +2425,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| ExpressionClassifier::PatternProductions | |
| ExpressionClassifier::FormalParametersProductions | |
| ExpressionClassifier::CoverInitializedNameProduction | |
| + ExpressionClassifier::AnnexBDuplicateProtoProduction | |
| ExpressionClassifier::AsyncArrowFormalParametersProduction, |
| false); |
| @@ -2434,6 +2443,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| if (IsValidPattern(expression) && peek() == Token::ASSIGN) { |
| classifier->ForgiveCoverInitializedNameError(); |
| + classifier->ForgiveAnnexBDuplicateProtoError(); |
| ValidateAssignmentPattern(classifier, CHECK_OK); |
| is_destructuring_assignment = true; |
| } else { |
| @@ -2462,6 +2472,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| &rhs_classifier, |
| ExpressionClassifier::ExpressionProductions | |
| ExpressionClassifier::CoverInitializedNameProduction | |
| + ExpressionClassifier::AnnexBDuplicateProtoProduction | |
| ExpressionClassifier::AsyncArrowFormalParametersProduction); |
| // TODO(1231235): We try to estimate the set of properties set by |
| @@ -3702,7 +3713,7 @@ void ParserBase<Traits>::CheckDestructuringElement( |
| template <typename Traits> |
| void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| Token::Value property, PropertyKind type, MethodKind method_type, |
| - bool* ok) { |
| + ExpressionClassifier* classifier, bool* ok) { |
| DCHECK(!IsStaticMethod(method_type)); |
| DCHECK(!IsSpecialMethod(method_type) || type == kMethodProperty); |
| @@ -3710,19 +3721,18 @@ void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| if (type == kValueProperty && IsProto()) { |
| if (has_seen_proto_) { |
| - this->parser()->ReportMessage(MessageTemplate::kDuplicateProto); |
| - *ok = false; |
| + classifier->RecordAnnexBDuplicateProtoError( |
| + this->scanner()->location(), MessageTemplate::kDuplicateProto); |
| return; |
| } |
| has_seen_proto_ = true; |
| - return; |
| } |
| } |
| template <typename Traits> |
| void ParserBase<Traits>::ClassLiteralChecker::CheckProperty( |
| Token::Value property, PropertyKind type, MethodKind method_type, |
| - bool* ok) { |
| + ExpressionClassifier* classifier, bool* ok) { |
| DCHECK(type == kMethodProperty || type == kAccessorProperty); |
| if (property == Token::SMI || property == Token::NUMBER) return; |