Commit 70ce3103 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Remove RETURN_IF* part 15

Bug: v8:8363, v8:7926
Change-Id: I227febcb3aafb56e1c5138650b6639ddeb883b52
Reviewed-on: https://chromium-review.googlesource.com/c/1309813Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57166}
parent 1c2394dd
...@@ -1667,7 +1667,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBindingPattern() { ...@@ -1667,7 +1667,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBindingPattern() {
if (Token::IsAnyIdentifier(token)) { if (Token::IsAnyIdentifier(token)) {
IdentifierT name = ParseAndClassifyIdentifier(); IdentifierT name = ParseAndClassifyIdentifier();
RETURN_IF_PARSE_ERROR;
result = impl()->ExpressionFromIdentifier(name, beg_pos); result = impl()->ExpressionFromIdentifier(name, beg_pos);
} else { } else {
classifier()->RecordNonSimpleParameter(); classifier()->RecordNonSimpleParameter();
...@@ -1734,7 +1733,6 @@ ParserBase<Impl>::ParsePrimaryExpression() { ...@@ -1734,7 +1733,6 @@ ParserBase<Impl>::ParsePrimaryExpression() {
infer = InferName::kNo; infer = InferName::kNo;
} }
} }
RETURN_IF_PARSE_ERROR;
return impl()->ExpressionFromIdentifier(name, beg_pos, infer); return impl()->ExpressionFromIdentifier(name, beg_pos, infer);
} }
DCHECK_IMPLIES(Token::IsAnyIdentifier(token), token == Token::ENUM); DCHECK_IMPLIES(Token::IsAnyIdentifier(token), token == Token::ENUM);
...@@ -2224,7 +2222,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2224,7 +2222,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
ClassLiteralPropertyT result = factory()->NewClassLiteralProperty( ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
name_expression, initializer, *property_kind, *is_static, name_expression, initializer, *property_kind, *is_static,
*is_computed_name, *is_private); *is_computed_name, *is_private);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
impl()->SetFunctionNameFromPropertyName(result, *name); impl()->SetFunctionNameFromPropertyName(result, *name);
return result; return result;
...@@ -2245,7 +2242,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2245,7 +2242,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
if (!*is_computed_name) { if (!*is_computed_name) {
checker->CheckClassMethodName(name_token, ParsePropertyKind::kMethod, checker->CheckClassMethodName(name_token, ParsePropertyKind::kMethod,
function_flags, *is_static); function_flags, *is_static);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty)
} }
FunctionKind kind = MethodKindFor(function_flags); FunctionKind kind = MethodKindFor(function_flags);
...@@ -2260,7 +2256,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2260,7 +2256,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
*name, scanner()->location(), kSkipFunctionNameCheck, kind, *name, scanner()->location(), kSkipFunctionNameCheck, kind,
name_token_position, FunctionLiteral::kAccessorOrMethod, name_token_position, FunctionLiteral::kAccessorOrMethod,
language_mode(), nullptr); language_mode(), nullptr);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
*property_kind = ClassLiteralProperty::METHOD; *property_kind = ClassLiteralProperty::METHOD;
ClassLiteralPropertyT result = factory()->NewClassLiteralProperty( ClassLiteralPropertyT result = factory()->NewClassLiteralProperty(
...@@ -2293,7 +2288,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2293,7 +2288,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
*name, scanner()->location(), kSkipFunctionNameCheck, kind, *name, scanner()->location(), kSkipFunctionNameCheck, kind,
name_token_position, FunctionLiteral::kAccessorOrMethod, name_token_position, FunctionLiteral::kAccessorOrMethod,
language_mode(), nullptr); language_mode(), nullptr);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
*property_kind = *property_kind =
is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER;
...@@ -2378,7 +2372,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, ...@@ -2378,7 +2372,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
bool is_private = false; bool is_private = false;
ExpressionT name_expression = ParsePropertyName( ExpressionT name_expression = ParsePropertyName(
&name, &kind, &function_flags, is_computed_name, &is_private); &name, &kind, &function_flags, is_computed_name, &is_private);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
if (is_private) { if (is_private) {
// TODO(joyee): private names in object literals should be Syntax Errors // TODO(joyee): private names in object literals should be Syntax Errors
...@@ -2464,7 +2457,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, ...@@ -2464,7 +2457,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
Scanner::Location(next_beg_pos, end_position()), Scanner::Location(next_beg_pos, end_position()),
MessageTemplate::kInvalidCoverInitializedName); MessageTemplate::kInvalidCoverInitializedName);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
impl()->SetFunctionNameFromIdentifierRef(rhs, lhs); impl()->SetFunctionNameFromIdentifierRef(rhs, lhs);
} else { } else {
value = lhs; value = lhs;
...@@ -2495,7 +2487,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, ...@@ -2495,7 +2487,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty( ObjectLiteralPropertyT result = factory()->NewObjectLiteralProperty(
name_expression, value, ObjectLiteralProperty::COMPUTED, name_expression, value, ObjectLiteralProperty::COMPUTED,
*is_computed_name); *is_computed_name);
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
impl()->SetFunctionNameFromPropertyName(result, name); impl()->SetFunctionNameFromPropertyName(result, name);
return result; return result;
} }
...@@ -2513,6 +2504,7 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, ...@@ -2513,6 +2504,7 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
// Make sure the name expression is a string since we need a Name for // Make sure the name expression is a string since we need a Name for
// Runtime_DefineAccessorPropertyUnchecked and since we can determine // Runtime_DefineAccessorPropertyUnchecked and since we can determine
// this statically we can skip the extra runtime check. // this statically we can skip the extra runtime check.
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
name_expression = name_expression =
factory()->NewStringLiteral(name, name_expression->position()); factory()->NewStringLiteral(name, name_expression->position());
} }
...@@ -2533,7 +2525,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, ...@@ -2533,7 +2525,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker,
const AstRawString* prefix = const AstRawString* prefix =
is_get ? ast_value_factory()->get_space_string() is_get ? ast_value_factory()->get_space_string()
: ast_value_factory()->set_space_string(); : ast_value_factory()->set_space_string();
RETURN_IF_PARSE_ERROR_CUSTOM(NullLiteralProperty);
impl()->SetFunctionNameFromPropertyName(result, name, prefix); impl()->SetFunctionNameFromPropertyName(result, name, prefix);
return result; return result;
} }
...@@ -3562,7 +3553,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) { ...@@ -3562,7 +3553,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) {
FuncNameInferrerState fni_state(&fni_); FuncNameInferrerState fni_state(&fni_);
ExpressionT pattern = ParseBindingPattern(); ExpressionT pattern = ParseBindingPattern();
// TODO(verwaest): Remove once we have FailureExpression. // TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR_CUSTOM(Void); RETURN_IF_PARSE_ERROR_VOID;
if (!impl()->IsIdentifier(pattern)) { if (!impl()->IsIdentifier(pattern)) {
parameters->is_simple = false; parameters->is_simple = false;
ValidateFormalParameterInitializer(); ValidateFormalParameterInitializer();
...@@ -3582,8 +3573,6 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) { ...@@ -3582,8 +3573,6 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters) {
parameters->is_simple = false; parameters->is_simple = false;
} }
classifier()->RecordNonSimpleParameter(); classifier()->RecordNonSimpleParameter();
// TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR_CUSTOM(Void);
impl()->SetFunctionNameFromIdentifierRef(initializer, pattern); impl()->SetFunctionNameFromIdentifierRef(initializer, pattern);
} }
...@@ -3633,7 +3622,6 @@ void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters) { ...@@ -3633,7 +3622,6 @@ void ParserBase<Impl>::ParseFormalParameterList(FormalParametersT* parameters) {
} }
} }
RETURN_IF_PARSE_ERROR_CUSTOM(Void);
impl()->DeclareFormalParameters(parameters); impl()->DeclareFormalParameters(parameters);
} }
...@@ -3699,7 +3687,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations( ...@@ -3699,7 +3687,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
Scanner::Location variable_loc = scanner()->location(); Scanner::Location variable_loc = scanner()->location();
// TODO(verwaest): Remove once we have FailureExpression. // TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR_CUSTOM(NullStatement);
bool single_name = impl()->IsIdentifier(pattern); bool single_name = impl()->IsIdentifier(pattern);
if (single_name) { if (single_name) {
impl()->PushVariableName(impl()->AsIdentifier(pattern)); impl()->PushVariableName(impl()->AsIdentifier(pattern));
...@@ -3720,11 +3707,10 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations( ...@@ -3720,11 +3707,10 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
parsing_result->first_initializer_loc = variable_loc; parsing_result->first_initializer_loc = variable_loc;
} }
// TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR_CUSTOM(NullStatement);
// Don't infer if it is "a = function(){...}();"-like expression. // Don't infer if it is "a = function(){...}();"-like expression.
if (single_name) { if (single_name) {
// TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR_CUSTOM(NullStatement);
if (!value->IsCall() && !value->IsCallNew()) { if (!value->IsCall() && !value->IsCallNew()) {
fni_.Infer(); fni_.Infer();
} else { } else {
...@@ -5470,7 +5456,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( ...@@ -5470,7 +5456,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
Expect(Token::SEMICOLON); Expect(Token::SEMICOLON);
RETURN_IF_PARSE_ERROR;
StatementT init = impl()->BuildInitializationBlock(&for_info.parsing_result, StatementT init = impl()->BuildInitializationBlock(&for_info.parsing_result,
&for_info.bound_names); &for_info.bound_names);
...@@ -5493,7 +5478,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement( ...@@ -5493,7 +5478,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
own_labels, nullptr); own_labels, nullptr);
} }
RETURN_IF_PARSE_ERROR;
init = impl()->BuildInitializationBlock(&for_info.parsing_result, nullptr); init = impl()->BuildInitializationBlock(&for_info.parsing_result, nullptr);
} else if (peek() != Token::SEMICOLON) { } else if (peek() != Token::SEMICOLON) {
// The initializer does not contain declarations. // The initializer does not contain declarations.
...@@ -5647,7 +5631,6 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations( ...@@ -5647,7 +5631,6 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
expression = CheckAndRewriteReferenceExpression( expression = CheckAndRewriteReferenceExpression(
expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, expression, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
kSyntaxError); kSyntaxError);
RETURN_IF_PARSE_ERROR;
} }
auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels, auto loop = factory()->NewForEachStatement(for_info->mode, labels, own_labels,
......
...@@ -153,7 +153,8 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token, ...@@ -153,7 +153,8 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token,
} }
#define RETURN_IF_PARSE_ERROR RETURN_IF_PARSE_ERROR_VALUE(nullptr) #define RETURN_IF_PARSE_ERROR RETURN_IF_PARSE_ERROR_VALUE(nullptr)
#define RETURN_IF_PARSE_ERROR_VOID RETURN_IF_PARSE_ERROR_VALUE(this->Void()) #define RETURN_IF_PARSE_ERROR_VOID \
if (scanner()->has_parser_error()) return;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of Parser // Implementation of Parser
...@@ -2925,7 +2926,6 @@ Block* Parser::BuildParameterInitializationBlock( ...@@ -2925,7 +2926,6 @@ Block* Parser::BuildParameterInitializationBlock(
param_scope = param_scope->FinalizeBlockScope(); param_scope = param_scope->FinalizeBlockScope();
if (param_scope != nullptr) { if (param_scope != nullptr) {
CheckConflictingVarDeclarations(param_scope); CheckConflictingVarDeclarations(param_scope);
RETURN_IF_PARSE_ERROR;
} }
init_block->statements()->Add(param_block, zone()); init_block->statements()->Add(param_block, zone());
} }
...@@ -3031,7 +3031,6 @@ ZonePtrList<Statement>* Parser::ParseFunction( ...@@ -3031,7 +3031,6 @@ ZonePtrList<Statement>* Parser::ParseFunction(
// For a regular function, the function arguments are parsed from source. // For a regular function, the function arguments are parsed from source.
DCHECK_NULL(arguments_for_wrapped_function); DCHECK_NULL(arguments_for_wrapped_function);
ParseFormalParameterList(&formals); ParseFormalParameterList(&formals);
RETURN_IF_PARSE_ERROR;
if (expected_parameters_end_pos != kNoSourcePosition) { if (expected_parameters_end_pos != kNoSourcePosition) {
// Check for '(' or ')' shenanigans in the parameter string for dynamic // Check for '(' or ')' shenanigans in the parameter string for dynamic
// functions. // functions.
...@@ -3048,14 +3047,12 @@ ZonePtrList<Statement>* Parser::ParseFunction( ...@@ -3048,14 +3047,12 @@ ZonePtrList<Statement>* Parser::ParseFunction(
} }
} }
Expect(Token::RPAREN); Expect(Token::RPAREN);
RETURN_IF_PARSE_ERROR;
int formals_end_position = scanner()->location().end_pos; int formals_end_position = scanner()->location().end_pos;
CheckArityRestrictions(formals.arity, kind, formals.has_rest, CheckArityRestrictions(formals.arity, kind, formals.has_rest,
function_scope->start_position(), function_scope->start_position(),
formals_end_position); formals_end_position);
Expect(Token::LBRACE); Expect(Token::LBRACE);
RETURN_IF_PARSE_ERROR;
} }
*num_parameters = formals.num_parameters(); *num_parameters = formals.num_parameters();
*function_length = formals.function_length; *function_length = formals.function_length;
...@@ -3609,6 +3606,7 @@ void Parser::QueueDestructuringAssignmentForRewriting( ...@@ -3609,6 +3606,7 @@ void Parser::QueueDestructuringAssignmentForRewriting(
void Parser::SetFunctionNameFromPropertyName(LiteralProperty* property, void Parser::SetFunctionNameFromPropertyName(LiteralProperty* property,
const AstRawString* name, const AstRawString* name,
const AstRawString* prefix) { const AstRawString* prefix) {
if (has_error()) return;
// Ensure that the function we are going to create has shared name iff // Ensure that the function we are going to create has shared name iff
// we are not going to set it later. // we are not going to set it later.
if (property->NeedsSetFunctionName()) { if (property->NeedsSetFunctionName()) {
...@@ -3634,7 +3632,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, ...@@ -3634,7 +3632,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
// Ignore "__proto__" as a name when it's being used to set the [[Prototype]] // Ignore "__proto__" as a name when it's being used to set the [[Prototype]]
// of an object literal. // of an object literal.
// See ES #sec-__proto__-property-names-in-object-initializers. // See ES #sec-__proto__-property-names-in-object-initializers.
if (property->IsPrototype()) return; if (property->IsPrototype() || has_error()) return;
DCHECK(!property->value()->IsAnonymousFunctionDefinition() || DCHECK(!property->value()->IsAnonymousFunctionDefinition() ||
property->kind() == ObjectLiteralProperty::COMPUTED); property->kind() == ObjectLiteralProperty::COMPUTED);
...@@ -3645,7 +3643,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, ...@@ -3645,7 +3643,7 @@ void Parser::SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
void Parser::SetFunctionNameFromIdentifierRef(Expression* value, void Parser::SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier) { Expression* identifier) {
if (!identifier->IsVariableProxy()) return; if (has_error() || !identifier->IsVariableProxy()) return;
SetFunctionName(value, identifier->AsVariableProxy()->raw_name()); SetFunctionName(value, identifier->AsVariableProxy()->raw_name());
} }
......
...@@ -609,7 +609,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -609,7 +609,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// inside a variable proxy). We exclude the case of 'this', which // inside a variable proxy). We exclude the case of 'this', which
// has been converted to a variable proxy. // has been converted to a variable proxy.
V8_INLINE static bool IsIdentifier(Expression* expression) { V8_INLINE static bool IsIdentifier(Expression* expression) {
DCHECK_NOT_NULL(expression); // TODO(verwaest): Rely on FailureExpression instead.
if (expression == nullptr) return false;
VariableProxy* operand = expression->AsVariableProxy(); VariableProxy* operand = expression->AsVariableProxy();
return operand != nullptr && !operand->is_this() && return operand != nullptr && !operand->is_this() &&
!operand->is_new_target(); !operand->is_new_target();
...@@ -861,6 +862,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -861,6 +862,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
V8_INLINE VariableProxy* ExpressionFromIdentifier( V8_INLINE VariableProxy* ExpressionFromIdentifier(
const AstRawString* name, int start_position, const AstRawString* name, int start_position,
InferName infer = InferName::kYes) { InferName infer = InferName::kYes) {
if (has_error()) return nullptr;
if (infer == InferName::kYes) { if (infer == InferName::kYes) {
fni_.PushVariableName(name); fni_.PushVariableName(name);
} }
......
...@@ -392,7 +392,8 @@ PreParserStatement PreParser::BuildParameterInitializationBlock( ...@@ -392,7 +392,8 @@ PreParserStatement PreParser::BuildParameterInitializationBlock(
PreParserExpression PreParser::ExpressionFromIdentifier( PreParserExpression PreParser::ExpressionFromIdentifier(
const PreParserIdentifier& name, int start_position, InferName infer) { const PreParserIdentifier& name, int start_position, InferName infer) {
VariableProxy* proxy = nullptr; VariableProxy* proxy = nullptr;
DCHECK_NOT_NULL(name.string_); DCHECK_EQ(name.string_ == nullptr, has_error());
if (name.string_ == nullptr) return PreParserExpression::Default();
proxy = scope()->NewUnresolved(factory()->ast_node_factory(), name.string_, proxy = scope()->NewUnresolved(factory()->ast_node_factory(), name.string_,
start_position, NORMAL_VARIABLE); start_position, NORMAL_VARIABLE);
return PreParserExpression::FromIdentifier(name, proxy, zone()); return PreParserExpression::FromIdentifier(name, proxy, zone());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment