Commit c47a8f63 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[preparser] Avoid name.string_ nullptr check in failure mode

By making EmptyIdentifierString (used for failure-mode parsing) point to the
empty_string() we can drop nullptr checks in the preparser. This is similar to
what the parser already does.

Change-Id: I4640f7ae6b24afc8d5275818caed0cca185ca72c
Reviewed-on: https://chromium-review.googlesource.com/c/1488759Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59860}
parent da138ed9
...@@ -1191,18 +1191,16 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1191,18 +1191,16 @@ class PreParser : public ParserBase<PreParser> {
const PreParserExpression& function, VariableMode mode, VariableKind kind, const PreParserExpression& function, VariableMode mode, VariableKind kind,
int beg_pos, int end_pos, ZonePtrList<const AstRawString>* names) { int beg_pos, int end_pos, ZonePtrList<const AstRawString>* names) {
DCHECK_NULL(names); DCHECK_NULL(names);
if (variable_name.string_ != nullptr) { bool was_added;
bool was_added; Variable* var = DeclareVariableName(variable_name.string_, mode, scope(),
Variable* var = DeclareVariableName(variable_name.string_, mode, scope(), &was_added, beg_pos, kind);
&was_added, beg_pos, kind); if (kind == SLOPPY_BLOCK_FUNCTION_VARIABLE) {
if (kind == SLOPPY_BLOCK_FUNCTION_VARIABLE) { Token::Value init =
Token::Value init = loop_nesting_depth() > 0 ? Token::ASSIGN : Token::INIT;
loop_nesting_depth() > 0 ? Token::ASSIGN : Token::INIT; SloppyBlockFunctionStatement* statement =
SloppyBlockFunctionStatement* statement = factory()->ast_node_factory()->NewSloppyBlockFunctionStatement(
factory()->ast_node_factory()->NewSloppyBlockFunctionStatement( end_pos, var, init);
end_pos, var, init); GetDeclarationScope()->DeclareSloppyBlockFunction(statement);
GetDeclarationScope()->DeclareSloppyBlockFunction(statement);
}
} }
return Statement::Default(); return Statement::Default();
} }
...@@ -1213,17 +1211,15 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1213,17 +1211,15 @@ class PreParser : public ParserBase<PreParser> {
int class_token_pos, int end_pos) { int class_token_pos, int end_pos) {
// Preparser shouldn't be used in contexts where we need to track the names. // Preparser shouldn't be used in contexts where we need to track the names.
DCHECK_NULL(names); DCHECK_NULL(names);
if (variable_name.string_ != nullptr) { bool was_added;
bool was_added; DeclareVariableName(variable_name.string_, VariableMode::kLet, scope(),
DeclareVariableName(variable_name.string_, VariableMode::kLet, scope(), &was_added);
&was_added);
}
return PreParserStatement::Default(); return PreParserStatement::Default();
} }
V8_INLINE void DeclareClassVariable(const PreParserIdentifier& name, V8_INLINE void DeclareClassVariable(const PreParserIdentifier& name,
ClassInfo* class_info, ClassInfo* class_info,
int class_token_pos) { int class_token_pos) {
if (name.string_ != nullptr) { if (!IsNull(name)) {
bool was_added; bool was_added;
DeclareVariableName(name.string_, VariableMode::kConst, scope(), DeclareVariableName(name.string_, VariableMode::kConst, scope(),
&was_added); &was_added);
...@@ -1245,7 +1241,7 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1245,7 +1241,7 @@ class PreParser : public ParserBase<PreParser> {
ClassFieldVariableName(ast_value_factory(), ClassFieldVariableName(ast_value_factory(),
class_info->computed_field_count), class_info->computed_field_count),
VariableMode::kConst, scope(), &was_added); VariableMode::kConst, scope(), &was_added);
} else if (is_private && property_name.string_ != nullptr) { } else if (is_private) {
bool was_added; bool was_added;
DeclareVariableName(property_name.string_, VariableMode::kConst, scope(), DeclareVariableName(property_name.string_, VariableMode::kConst, scope(),
&was_added); &was_added);
...@@ -1525,7 +1521,9 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1525,7 +1521,9 @@ class PreParser : public ParserBase<PreParser> {
} }
V8_INLINE PreParserIdentifier EmptyIdentifierString() const { V8_INLINE PreParserIdentifier EmptyIdentifierString() const {
return PreParserIdentifier::Default(); PreParserIdentifier result = PreParserIdentifier::Default();
result.string_ = ast_value_factory()->empty_string();
return result;
} }
// Producing data during the recursive descent. // Producing data during the recursive descent.
...@@ -1578,17 +1576,13 @@ class PreParser : public ParserBase<PreParser> { ...@@ -1578,17 +1576,13 @@ class PreParser : public ParserBase<PreParser> {
PreParserExpression ExpressionFromIdentifier( PreParserExpression ExpressionFromIdentifier(
const PreParserIdentifier& name, int start_position, const PreParserIdentifier& name, int start_position,
InferName infer = InferName::kYes) { InferName infer = InferName::kYes) {
if (name.string_ != nullptr) { expression_scope()->NewVariable(name.string_, start_position);
expression_scope()->NewVariable(name.string_, start_position);
}
return PreParserExpression::FromIdentifier(name); return PreParserExpression::FromIdentifier(name);
} }
V8_INLINE void DeclareIdentifier(const PreParserIdentifier& name, V8_INLINE void DeclareIdentifier(const PreParserIdentifier& name,
int start_position) { int start_position) {
if (name.string_ != nullptr) { expression_scope()->Declare(name.string_, start_position);
expression_scope()->Declare(name.string_, start_position);
}
} }
V8_INLINE Variable* DeclareCatchVariableName( V8_INLINE Variable* DeclareCatchVariableName(
......
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