Commit 3f967aed authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Get rid of the last remaining 'bool ok'

Bug: v8:7926
Change-Id: I012b5bbf25b7aa4cbef64cce302c8ae971589663
Reviewed-on: https://chromium-review.googlesource.com/c/1309758Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57170}
parent 0f15ed05
......@@ -5665,7 +5665,6 @@ ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations(
int stmt_pos, StatementT init, ForInfo* for_info,
ZonePtrList<const AstRawString>* labels,
ZonePtrList<const AstRawString>* own_labels) {
bool ok = true;
// The condition and the next statement of the for loop must be parsed
// in a new scope.
Scope* inner_scope = NewScope(BLOCK_SCOPE);
......@@ -5687,7 +5686,7 @@ ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations(
function_state_->contains_function_or_eval()) {
scope()->set_is_hidden();
return impl()->DesugarLexicalBindingsInForStatement(
loop, init, cond, next, body, inner_scope, *for_info, &ok);
loop, init, cond, next, body, inner_scope, *for_info);
} else {
inner_scope = inner_scope->FinalizeBlockScope();
DCHECK_NULL(inner_scope);
......
......@@ -568,7 +568,6 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
FunctionState function_state(&function_state_, &scope_, scope);
ZonePtrList<Statement>* body =
new (zone()) ZonePtrList<Statement>(16, zone());
bool ok = true;
int beg_pos = scanner()->location().beg_pos;
if (parsing_module_) {
DCHECK(info->is_module());
......@@ -588,63 +587,58 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
zone());
ParseModuleItemList(body);
ok = !has_error() && module()->Validate(this->scope()->AsModuleScope(),
pending_error_handler(), zone());
if (!module()->Validate(this->scope()->AsModuleScope(),
pending_error_handler(), zone())) {
scanner()->set_parser_error();
}
} else if (info->is_wrapped_as_function()) {
ParseWrapped(isolate, info, body, scope, zone(), &ok);
ParseWrapped(isolate, info, body, scope, zone());
} else {
// Don't count the mode in the use counters--give the program a chance
// to enable script-wide strict mode below.
this->scope()->SetLanguageMode(info->language_mode());
ParseStatementList(body, Token::EOS);
}
ok = ok && !has_error();
// The parser will peek but not consume EOS. Our scope logically goes all
// the way to the EOS, though.
scope->set_end_position(scanner()->peek_location().beg_pos);
scope->set_end_position(peek_position());
if (ok && is_strict(language_mode())) {
CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos);
ok = !has_error();
if (is_strict(language_mode())) {
CheckStrictOctalLiteral(beg_pos, end_position());
}
if (ok && is_sloppy(language_mode())) {
if (is_sloppy(language_mode())) {
// TODO(littledan): Function bindings on the global object that modify
// pre-existing bindings should be made writable, enumerable and
// nonconfigurable if possible, whereas this code will leave attributes
// unchanged if the property already exists.
InsertSloppyBlockFunctionVarBindings(scope);
}
if (ok) {
RETURN_IF_PARSE_ERROR;
CheckConflictingVarDeclarations(scope);
ok = !has_error();
}
if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
if (info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
if (body->length() != 1 ||
!body->at(0)->IsExpressionStatement() ||
!body->at(0)->AsExpressionStatement()->
expression()->IsFunctionLiteral()) {
ReportMessage(MessageTemplate::kSingleFunctionLiteral);
ok = false;
}
}
if (ok) {
RewriteDestructuringAssignments();
int parameter_count = parsing_module_ ? 1 : 0;
result = factory()->NewScriptOrEvalFunctionLiteral(
scope, body, function_state.expected_property_count(),
parameter_count);
scope, body, function_state.expected_property_count(), parameter_count);
result->set_suspend_count(function_state.suspend_count());
}
}
info->set_max_function_literal_id(GetLastFunctionLiteralId());
// Make sure the target stack is empty.
DCHECK_NULL(target_stack_);
RETURN_IF_PARSE_ERROR;
return result;
}
......@@ -666,7 +660,7 @@ ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments(
void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
ZonePtrList<Statement>* body,
DeclarationScope* outer_scope, Zone* zone, bool* ok) {
DeclarationScope* outer_scope, Zone* zone) {
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
DCHECK(info->is_wrapped_as_function());
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
......@@ -777,7 +771,6 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
is_strict(info->language_mode()));
FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
FunctionKind kind = info->function_kind();
bool ok = true;
if (IsArrowFunction(kind)) {
if (IsAsyncFunction(kind)) {
......@@ -813,19 +806,14 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')'
ParseFormalParameterList(&formals);
ok = !has_error();
if (ok) ok = Check(Token::RPAREN);
Expect(Token::RPAREN);
} else {
// BindingIdentifier
ParseFormalParameter(&formals);
ok = !has_error();
if (ok) {
DeclareFormalParameters(&formals);
}
}
}
if (ok) {
if (GetLastFunctionLiteralId() != info->function_literal_id() - 1) {
// If there were FunctionLiterals in the parameters, we need to
// renumber them to shift down so the next function literal id for
......@@ -851,8 +839,6 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
const int rewritable_length = 0;
Expression* expression =
ParseArrowFunctionLiteral(accept_IN, formals, rewritable_length);
ok = !has_error();
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
// overflow, at which point the partially parsed arrow function
......@@ -864,10 +850,6 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
// must produce a FunctionLiteral.
DCHECK(expression->IsFunctionLiteral());
result = expression->AsFunctionLiteral();
} else {
ok = false;
}
}
}
} else if (IsDefaultConstructor(kind)) {
DCHECK_EQ(scope(), outer);
......@@ -882,17 +864,12 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, function_type, info->language_mode(),
arguments_for_wrapped_function);
ok = !has_error();
}
DCHECK_EQ(ok, !has_error());
if (ok) {
RETURN_IF_PARSE_ERROR;
result->set_requires_instance_fields_initializer(
info->requires_instance_fields_initializer());
}
// Make sure the results agree.
DCHECK(ok == (result != nullptr));
}
// Make sure the target stack is empty.
DCHECK_NULL(target_stack_);
......@@ -2142,7 +2119,7 @@ Statement* Parser::InitializeForOfStatement(
Statement* Parser::DesugarLexicalBindingsInForStatement(
ForStatement* loop, Statement* init, Expression* cond, Statement* next,
Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok) {
Statement* body, Scope* inner_scope, const ForInfo& for_info) {
// ES6 13.7.4.8 specifies that on each loop iteration the let variables are
// copied into a new environment. Moreover, the "next" statement must be
// evaluated not in the environment of the just completed iteration but in
......
......@@ -244,7 +244,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// function wrapper.
void ParseWrapped(Isolate* isolate, ParseInfo* info,
ZonePtrList<Statement>* body, DeclarationScope* scope,
Zone* zone, bool* ok);
Zone* zone);
ZonePtrList<const AstRawString>* PrepareWrappedArguments(Isolate* isolate,
ParseInfo* info,
......@@ -390,7 +390,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
Statement* DesugarLexicalBindingsInForStatement(
ForStatement* loop, Statement* init, Expression* cond, Statement* next,
Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok);
Statement* body, Scope* inner_scope, const ForInfo& for_info);
Expression* RewriteDoExpression(Block* body, int pos);
......
......@@ -81,16 +81,12 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
FunctionState top_scope(&function_state_, &scope_, scope);
original_scope_ = scope_;
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
PreParserStatementList body;
ParseStatementList(body, Token::EOS);
ok = !has_error();
original_scope_ = nullptr;
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
} else if (is_strict(language_mode())) {
if (is_strict(language_mode())) {
CheckStrictOctalLiteral(start_position, scanner()->location().end_pos);
}
return kPreParseSuccess;
......
......@@ -1424,8 +1424,7 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE StatementT DesugarLexicalBindingsInForStatement(
PreParserStatement loop, PreParserStatement init,
const PreParserExpression& cond, PreParserStatement next,
PreParserStatement body, Scope* inner_scope, const ForInfo& for_info,
bool* ok) {
PreParserStatement body, Scope* inner_scope, const ForInfo& for_info) {
// See Parser::DesugarLexicalBindingsInForStatement.
for (auto name : for_info.bound_names) {
inner_scope->DeclareVariableName(name,
......
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