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