@@ -139,7 +139,7 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token,
139
139
// ----------------------------------------------------------------------------
140
140
// The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error
141
141
// handling for functions that may fail (by returning if there was an parser
142
- // error scanner()->has_parser_error() ).
142
+ // error).
143
143
//
144
144
// Usage:
145
145
// foo = ParseFoo(); // may fail
@@ -148,12 +148,11 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token,
148
148
// SAFE_USE(foo);
149
149
150
150
#define RETURN_IF_PARSE_ERROR_VALUE (x ) \
151
- if (scanner()->has_parser_error ()) { \
152
- return x; \
153
- }
151
+ if (has_error()) return x;
154
152
155
153
#define RETURN_IF_PARSE_ERROR RETURN_IF_PARSE_ERROR_VALUE (nullptr )
156
- #define RETURN_IF_PARSE_ERROR_VOID RETURN_IF_PARSE_ERROR_VALUE (this ->Void ())
154
+ #define RETURN_IF_PARSE_ERROR_VOID \
155
+ if (has_error()) return ;
157
156
158
157
// ----------------------------------------------------------------------------
159
158
// Implementation of Parser
@@ -589,9 +588,8 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
589
588
zone ());
590
589
591
590
ParseModuleItemList (body);
592
- ok = !scanner_.has_parser_error () &&
593
- module ()->Validate (this ->scope ()->AsModuleScope (),
594
- pending_error_handler (), zone ());
591
+ ok = !has_error () && module ()->Validate (this ->scope ()->AsModuleScope (),
592
+ pending_error_handler (), zone ());
595
593
} else if (info->is_wrapped_as_function ()) {
596
594
ParseWrapped (isolate, info, body, scope, zone (), &ok);
597
595
} else {
@@ -600,15 +598,15 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
600
598
this ->scope ()->SetLanguageMode (info->language_mode ());
601
599
ParseStatementList (body, Token::EOS);
602
600
}
603
- ok = ok && !scanner_. has_parser_error ();
601
+ ok = ok && !has_error ();
604
602
605
603
// The parser will peek but not consume EOS. Our scope logically goes all
606
604
// the way to the EOS, though.
607
605
scope->set_end_position (scanner ()->peek_location ().beg_pos );
608
606
609
607
if (ok && is_strict (language_mode ())) {
610
608
CheckStrictOctalLiteral (beg_pos, scanner ()->location ().end_pos );
611
- ok = !scanner_. has_parser_error ();
609
+ ok = !has_error ();
612
610
}
613
611
if (ok && is_sloppy (language_mode ())) {
614
612
// TODO(littledan): Function bindings on the global object that modify
@@ -619,7 +617,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
619
617
}
620
618
if (ok) {
621
619
CheckConflictingVarDeclarations (scope);
622
- ok = !scanner_. has_parser_error ();
620
+ ok = !has_error ();
623
621
}
624
622
625
623
if (ok && info->parse_restriction () == ONLY_SINGLE_FUNCTION_LITERAL) {
@@ -815,12 +813,12 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
815
813
if (Check (Token::LPAREN)) {
816
814
// '(' StrictFormalParameters ')'
817
815
ParseFormalParameterList (&formals);
818
- ok = !scanner_. has_parser_error ();
816
+ ok = !has_error ();
819
817
if (ok) ok = Check (Token::RPAREN);
820
818
} else {
821
819
// BindingIdentifier
822
820
ParseFormalParameter (&formals);
823
- ok = !scanner_. has_parser_error ();
821
+ ok = !has_error ();
824
822
if (ok) {
825
823
DeclareFormalParameters (&formals);
826
824
}
@@ -853,7 +851,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
853
851
const int rewritable_length = 0 ;
854
852
Expression* expression =
855
853
ParseArrowFunctionLiteral (accept_IN, formals, rewritable_length);
856
- ok = !scanner_. has_parser_error ();
854
+ ok = !has_error ();
857
855
if (ok) {
858
856
// Scanning must end at the same position that was recorded
859
857
// previously. If not, parsing has been interrupted due to a stack
@@ -884,10 +882,10 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
884
882
raw_name, Scanner::Location::invalid (), kSkipFunctionNameCheck , kind,
885
883
kNoSourcePosition , function_type, info->language_mode (),
886
884
arguments_for_wrapped_function);
887
- ok = !scanner_. has_parser_error ();
885
+ ok = !has_error ();
888
886
}
889
887
890
- DCHECK_EQ (ok, !scanner_. has_parser_error ());
888
+ DCHECK_EQ (ok, !has_error ());
891
889
if (ok) {
892
890
result->set_requires_instance_fields_initializer (
893
891
info->requires_instance_fields_initializer ());
@@ -1734,7 +1732,7 @@ void Parser::ParseAndRewriteGeneratorFunctionBody(
1734
1732
Expression* initial_yield = BuildInitialYield (pos, kind);
1735
1733
body->Add (factory ()->NewExpressionStatement (initial_yield, kNoSourcePosition ),
1736
1734
zone ());
1737
- ParseStatementList (body, Token::RBRACE, !scanner ()-> has_parser_error ());
1735
+ ParseStatementList (body, Token::RBRACE, !has_error ());
1738
1736
}
1739
1737
1740
1738
void Parser::ParseAndRewriteAsyncGeneratorFunctionBody (
@@ -1766,8 +1764,7 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
1766
1764
try_block->statements ()->Add (
1767
1765
factory ()->NewExpressionStatement (initial_yield, kNoSourcePosition ),
1768
1766
zone ());
1769
- ParseStatementList (try_block->statements (), Token::RBRACE,
1770
- !scanner ()->has_parser_error ());
1767
+ ParseStatementList (try_block->statements (), Token::RBRACE, !has_error ());
1771
1768
1772
1769
// Don't create iterator result for async generators, as the resume methods
1773
1770
// will create it.
@@ -2779,7 +2776,7 @@ bool Parser::SkipFunction(
2779
2776
return false ;
2780
2777
} else if (pending_error_handler ()->has_pending_error ()) {
2781
2778
DCHECK (!pending_error_handler ()->stack_overflow ());
2782
- DCHECK (scanner ()-> has_parser_error ());
2779
+ DCHECK (has_error ());
2783
2780
} else {
2784
2781
DCHECK (!pending_error_handler ()->stack_overflow ());
2785
2782
set_allow_eval_cache (reusable_preparser ()->allow_eval_cache ());
@@ -2925,7 +2922,6 @@ Block* Parser::BuildParameterInitializationBlock(
2925
2922
param_scope = param_scope->FinalizeBlockScope ();
2926
2923
if (param_scope != nullptr ) {
2927
2924
CheckConflictingVarDeclarations (param_scope);
2928
- RETURN_IF_PARSE_ERROR;
2929
2925
}
2930
2926
init_block->statements ()->Add (param_block, zone ());
2931
2927
}
@@ -3031,7 +3027,6 @@ ZonePtrList<Statement>* Parser::ParseFunction(
3031
3027
// For a regular function, the function arguments are parsed from source.
3032
3028
DCHECK_NULL (arguments_for_wrapped_function);
3033
3029
ParseFormalParameterList (&formals);
3034
- RETURN_IF_PARSE_ERROR;
3035
3030
if (expected_parameters_end_pos != kNoSourcePosition ) {
3036
3031
// Check for '(' or ')' shenanigans in the parameter string for dynamic
3037
3032
// functions.
@@ -3048,14 +3043,12 @@ ZonePtrList<Statement>* Parser::ParseFunction(
3048
3043
}
3049
3044
}
3050
3045
Expect (Token::RPAREN);
3051
- RETURN_IF_PARSE_ERROR;
3052
3046
int formals_end_position = scanner ()->location ().end_pos ;
3053
3047
3054
3048
CheckArityRestrictions (formals.arity , kind, formals.has_rest ,
3055
3049
function_scope->start_position (),
3056
3050
formals_end_position);
3057
3051
Expect (Token::LBRACE);
3058
- RETURN_IF_PARSE_ERROR;
3059
3052
}
3060
3053
*num_parameters = formals.num_parameters ();
3061
3054
*function_length = formals.function_length ;
@@ -3609,6 +3602,7 @@ void Parser::QueueDestructuringAssignmentForRewriting(
3609
3602
void Parser::SetFunctionNameFromPropertyName (LiteralProperty* property,
3610
3603
const AstRawString* name,
3611
3604
const AstRawString* prefix) {
3605
+ if (has_error ()) return ;
3612
3606
// Ensure that the function we are going to create has shared name iff
3613
3607
// we are not going to set it later.
3614
3608
if (property->NeedsSetFunctionName ()) {
@@ -3634,7 +3628,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
3634
3628
// Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
3635
3629
// of an object literal.
3636
3630
// See ES #sec-__proto__-property-names-in-object-initializers.
3637
- if (property->IsPrototype ()) return ;
3631
+ if (property->IsPrototype () || has_error () ) return ;
3638
3632
3639
3633
DCHECK (!property->value ()->IsAnonymousFunctionDefinition () ||
3640
3634
property->kind () == ObjectLiteralProperty::COMPUTED);
@@ -3645,7 +3639,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
3645
3639
3646
3640
void Parser::SetFunctionNameFromIdentifierRef (Expression* value,
3647
3641
Expression* identifier) {
3648
- if (!identifier->IsVariableProxy ()) return ;
3642
+ if (has_error () || !identifier->IsVariableProxy ()) return ;
3649
3643
SetFunctionName (value, identifier->AsVariableProxy ()->raw_name ());
3650
3644
}
3651
3645
0 commit comments