aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/parsing/parser.cc
diff options
context:
space:
mode:
authorUjjwal Sharma <usharma1998@gmail.com>2019-03-15 18:35:06 +0530
committerRefael Ackermann <refack@gmail.com>2019-03-28 16:36:18 -0400
commitf579e1194046c50f2e6bb54348d48c8e7d1a53cf (patch)
tree9125787c758358365f74f9fd9673c14f57e67870 /deps/v8/src/parsing/parser.cc
parent2c73868b0471fbd4038f500d076df056cbf697fe (diff)
downloadandroid-node-v8-f579e1194046c50f2e6bb54348d48c8e7d1a53cf.tar.gz
android-node-v8-f579e1194046c50f2e6bb54348d48c8e7d1a53cf.tar.bz2
android-node-v8-f579e1194046c50f2e6bb54348d48c8e7d1a53cf.zip
deps: update V8 to 7.4.288.13
PR-URL: https://github.com/nodejs/node/pull/26685 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'deps/v8/src/parsing/parser.cc')
-rw-r--r--deps/v8/src/parsing/parser.cc287
1 files changed, 117 insertions, 170 deletions
diff --git a/deps/v8/src/parsing/parser.cc b/deps/v8/src/parsing/parser.cc
index d6d55af2b6..5399a93cbf 100644
--- a/deps/v8/src/parsing/parser.cc
+++ b/deps/v8/src/parsing/parser.cc
@@ -12,6 +12,7 @@
#include "src/ast/ast.h"
#include "src/ast/source-range-ast-visitor.h"
#include "src/bailout-reason.h"
+#include "src/base/ieee754.h"
#include "src/base/overflowing-math.h"
#include "src/base/platform/platform.h"
#include "src/char-predicates-inl.h"
@@ -26,6 +27,7 @@
#include "src/runtime/runtime.h"
#include "src/string-stream.h"
#include "src/tracing/trace-event.h"
+#include "src/zone/zone-list-inl.h"
namespace v8 {
namespace internal {
@@ -179,7 +181,8 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
return true;
}
case Token::SHL: {
- int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1F);
+ int value =
+ base::ShlWithWraparound(DoubleToInt32(x_val), DoubleToInt32(y_val));
*x = factory()->NewNumberLiteral(value, pos);
return true;
}
@@ -195,13 +198,9 @@ bool Parser::ShortcutNumericLiteralBinaryExpression(Expression** x,
*x = factory()->NewNumberLiteral(value, pos);
return true;
}
- case Token::EXP: {
- double value = Pow(x_val, y_val);
- int int_value = static_cast<int>(value);
- *x = factory()->NewNumberLiteral(
- int_value == value && value != -0.0 ? int_value : value, pos);
+ case Token::EXP:
+ *x = factory()->NewNumberLiteral(base::ieee754::pow(x_val, y_val), pos);
return true;
- }
default:
break;
}
@@ -287,8 +286,7 @@ Expression* Parser::NewSuperPropertyReference(int pos) {
AstSymbol::kHomeObjectSymbol, kNoSourcePosition);
Expression* home_object = factory()->NewProperty(
this_function_proxy, home_object_symbol_literal, pos);
- return factory()->NewSuperPropertyReference(
- ThisExpression(pos)->AsVariableProxy(), home_object, pos);
+ return factory()->NewSuperPropertyReference(home_object, pos);
}
Expression* Parser::NewSuperCallReference(int pos) {
@@ -296,9 +294,8 @@ Expression* Parser::NewSuperCallReference(int pos) {
NewUnresolved(ast_value_factory()->new_target_string(), pos);
VariableProxy* this_function_proxy =
NewUnresolved(ast_value_factory()->this_function_string(), pos);
- return factory()->NewSuperCallReference(
- ThisExpression(pos)->AsVariableProxy(), new_target_proxy,
- this_function_proxy, pos);
+ return factory()->NewSuperCallReference(new_target_proxy, this_function_proxy,
+ pos);
}
Expression* Parser::NewTargetExpression(int pos) {
@@ -453,6 +450,10 @@ void Parser::DeserializeScopeChain(
original_scope_ = Scope::DeserializeScopeChain(
isolate, zone(), *outer_scope_info, info->script_scope(),
ast_value_factory(), mode);
+ if (info->is_eval() || IsArrowFunction(info->function_kind())) {
+ original_scope_->GetReceiverScope()->DeserializeReceiver(
+ ast_value_factory());
+ }
}
}
@@ -536,8 +537,8 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
ResetFunctionLiteralId();
- DCHECK(info->function_literal_id() == FunctionLiteral::kIdTypeTopLevel ||
- info->function_literal_id() == FunctionLiteral::kIdTypeInvalid);
+ DCHECK(info->function_literal_id() == kFunctionLiteralIdTopLevel ||
+ info->function_literal_id() == kFunctionLiteralIdInvalid);
FunctionLiteral* result = nullptr;
{
@@ -786,6 +787,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
// TODO(adamk): We should construct this scope from the ScopeInfo.
DeclarationScope* scope = NewFunctionScope(kind);
+ scope->set_has_checked_syntax(true);
// This bit only needs to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor.
@@ -1015,8 +1017,8 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) {
return nullptr;
}
- DeclareVariable(local_name, VariableMode::kConst, kNeedsInitialization,
- position());
+ DeclareUnboundVariable(local_name, VariableMode::kConst,
+ kNeedsInitialization, position());
NamedImport* import =
new (zone()) NamedImport(import_name, local_name, location);
@@ -1065,8 +1067,8 @@ void Parser::ParseImportDeclaration() {
if (tok != Token::MUL && tok != Token::LBRACE) {
import_default_binding = ParseNonRestrictedIdentifier();
import_default_binding_loc = scanner()->location();
- DeclareVariable(import_default_binding, VariableMode::kConst,
- kNeedsInitialization, pos);
+ DeclareUnboundVariable(import_default_binding, VariableMode::kConst,
+ kNeedsInitialization, pos);
}
// Parse NameSpaceImport or NamedImports if present.
@@ -1080,8 +1082,8 @@ void Parser::ParseImportDeclaration() {
ExpectContextualKeyword(ast_value_factory()->as_string());
module_namespace_binding = ParseNonRestrictedIdentifier();
module_namespace_binding_loc = scanner()->location();
- DeclareVariable(module_namespace_binding, VariableMode::kConst,
- kCreatedInitialized, pos);
+ DeclareUnboundVariable(module_namespace_binding, VariableMode::kConst,
+ kCreatedInitialized, pos);
break;
}
@@ -1171,13 +1173,13 @@ Statement* Parser::ParseExportDefault() {
SetFunctionName(value, ast_value_factory()->default_string());
const AstRawString* local_name =
- ast_value_factory()->star_default_star_string();
+ ast_value_factory()->dot_default_string();
local_names.Add(local_name, zone());
// It's fine to declare this as VariableMode::kConst because the user has
// no way of writing to it.
VariableProxy* proxy =
- DeclareVariable(local_name, VariableMode::kConst, pos);
+ DeclareBoundVariable(local_name, VariableMode::kConst, pos);
proxy->var()->set_initializer_position(position());
Assignment* assignment = factory()->NewAssignment(
@@ -1236,7 +1238,8 @@ void Parser::ParseExportStar() {
Scanner::Location export_name_loc = scanner()->location();
const AstRawString* local_name = NextInternalNamespaceExportName();
Scanner::Location local_name_loc = Scanner::Location::invalid();
- DeclareVariable(local_name, VariableMode::kConst, kCreatedInitialized, pos);
+ DeclareUnboundVariable(local_name, VariableMode::kConst, kCreatedInitialized,
+ pos);
ExpectContextualKeyword(ast_value_factory()->from_string());
Scanner::Location specifier_loc = scanner()->peek_location();
@@ -1350,28 +1353,42 @@ Statement* Parser::ParseExportDeclaration() {
return result;
}
-VariableProxy* Parser::DeclareVariable(const AstRawString* name,
- VariableMode mode, int pos) {
- return DeclareVariable(name, mode, Variable::DefaultInitializationFlag(mode),
- pos);
+void Parser::DeclareUnboundVariable(const AstRawString* name, VariableMode mode,
+ InitializationFlag init, int pos) {
+ bool was_added;
+ Variable* var = DeclareVariable(name, NORMAL_VARIABLE, mode, init, scope(),
+ &was_added, pos, end_position());
+ // The variable will be added to the declarations list, but since we are not
+ // binding it to anything, we can simply ignore it here.
+ USE(var);
}
-VariableProxy* Parser::DeclareVariable(const AstRawString* name,
- VariableMode mode,
- InitializationFlag init, int pos) {
+VariableProxy* Parser::DeclareBoundVariable(const AstRawString* name,
+ VariableMode mode, int pos) {
DCHECK_NOT_NULL(name);
VariableProxy* proxy =
factory()->NewVariableProxy(name, NORMAL_VARIABLE, position());
bool was_added;
- DeclareVariable(proxy, NORMAL_VARIABLE, mode, init, scope(), &was_added, pos,
- end_position());
+ Variable* var = DeclareVariable(name, NORMAL_VARIABLE, mode,
+ Variable::DefaultInitializationFlag(mode),
+ scope(), &was_added, pos, end_position());
+ proxy->BindTo(var);
return proxy;
}
-void Parser::DeclareVariable(VariableProxy* proxy, VariableKind kind,
- VariableMode mode, InitializationFlag init,
- Scope* scope, bool* was_added, int begin,
- int end) {
+void Parser::DeclareAndBindVariable(VariableProxy* proxy, VariableKind kind,
+ VariableMode mode, InitializationFlag init,
+ Scope* scope, bool* was_added, int begin,
+ int end) {
+ Variable* var = DeclareVariable(proxy->raw_name(), kind, mode, init, scope,
+ was_added, begin, end);
+ proxy->BindTo(var);
+}
+
+Variable* Parser::DeclareVariable(const AstRawString* name, VariableKind kind,
+ VariableMode mode, InitializationFlag init,
+ Scope* scope, bool* was_added, int begin,
+ int end) {
Declaration* declaration;
if (mode == VariableMode::kVar && !scope->is_declaration_scope()) {
DCHECK(scope->is_block_scope() || scope->is_with_scope());
@@ -1379,25 +1396,26 @@ void Parser::DeclareVariable(VariableProxy* proxy, VariableKind kind,
} else {
declaration = factory()->NewVariableDeclaration(begin);
}
- return Declare(declaration, proxy, kind, mode, init, scope, was_added, end);
+ Declare(declaration, name, kind, mode, init, scope, was_added, begin, end);
+ return declaration->var();
}
-void Parser::Declare(Declaration* declaration, VariableProxy* proxy,
+void Parser::Declare(Declaration* declaration, const AstRawString* name,
VariableKind variable_kind, VariableMode mode,
InitializationFlag init, Scope* scope, bool* was_added,
- int var_end_pos) {
+ int var_begin_pos, int var_end_pos) {
bool local_ok = true;
bool sloppy_mode_block_scope_function_redefinition = false;
scope->DeclareVariable(
- declaration, proxy, mode, variable_kind, init, was_added,
+ declaration, name, var_begin_pos, mode, variable_kind, init, was_added,
&sloppy_mode_block_scope_function_redefinition, &local_ok);
if (!local_ok) {
// If we only have the start position of a proxy, we can't highlight the
// whole variable name. Pretend its length is 1 so that we highlight at
// least the first character.
- Scanner::Location loc(proxy->position(), var_end_pos != kNoSourcePosition
- ? var_end_pos
- : proxy->position() + 1);
+ Scanner::Location loc(var_begin_pos, var_end_pos != kNoSourcePosition
+ ? var_end_pos
+ : var_begin_pos + 1);
if (variable_kind == PARAMETER_VARIABLE) {
ReportMessageAt(loc, MessageTemplate::kParamDupe);
} else {
@@ -1413,6 +1431,7 @@ Statement* Parser::BuildInitializationBlock(
DeclarationParsingResult* parsing_result) {
ScopedPtrList<Statement> statements(pointer_buffer());
for (const auto& declaration : parsing_result->declarations) {
+ if (!declaration.initializer) continue;
InitializeVariables(&statements, parsing_result->descriptor.kind,
&declaration);
}
@@ -1421,22 +1440,25 @@ Statement* Parser::BuildInitializationBlock(
Statement* Parser::DeclareFunction(const AstRawString* variable_name,
FunctionLiteral* function, VariableMode mode,
- int beg_pos, int end_pos,
- bool is_sloppy_block_function,
+ VariableKind kind, int beg_pos, int end_pos,
ZonePtrList<const AstRawString>* names) {
- VariableProxy* proxy =
- factory()->NewVariableProxy(variable_name, NORMAL_VARIABLE, beg_pos);
- Declaration* declaration = factory()->NewFunctionDeclaration(
- function, is_sloppy_block_function, beg_pos);
+ Declaration* declaration =
+ factory()->NewFunctionDeclaration(function, beg_pos);
bool was_added;
- Declare(declaration, proxy, NORMAL_VARIABLE, mode, kCreatedInitialized,
- scope(), &was_added);
+ Declare(declaration, variable_name, kind, mode, kCreatedInitialized, scope(),
+ &was_added, beg_pos);
+ if (info()->coverage_enabled()) {
+ // Force the function to be allocated when collecting source coverage, so
+ // that even dead functions get source coverage data.
+ declaration->var()->set_is_used();
+ }
if (names) names->Add(variable_name, zone());
- if (is_sloppy_block_function) {
+ if (kind == SLOPPY_BLOCK_FUNCTION_VARIABLE) {
+ Token::Value init = loop_nesting_depth() > 0 ? Token::ASSIGN : Token::INIT;
SloppyBlockFunctionStatement* statement =
- factory()->NewSloppyBlockFunctionStatement(end_pos);
- GetDeclarationScope()->DeclareSloppyBlockFunction(variable_name, scope(),
- statement);
+ factory()->NewSloppyBlockFunctionStatement(end_pos, declaration->var(),
+ init);
+ GetDeclarationScope()->DeclareSloppyBlockFunction(statement);
return statement;
}
return factory()->EmptyStatement();
@@ -1447,7 +1469,7 @@ Statement* Parser::DeclareClass(const AstRawString* variable_name,
ZonePtrList<const AstRawString>* names,
int class_token_pos, int end_pos) {
VariableProxy* proxy =
- DeclareVariable(variable_name, VariableMode::kLet, class_token_pos);
+ DeclareBoundVariable(variable_name, VariableMode::kLet, class_token_pos);
proxy->var()->set_initializer_position(end_pos);
if (names) names->Add(variable_name, zone());
@@ -1467,7 +1489,7 @@ Statement* Parser::DeclareNative(const AstRawString* name, int pos) {
// TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas
// other functions are set up when entering the surrounding scope.
- VariableProxy* proxy = DeclareVariable(name, VariableMode::kVar, pos);
+ VariableProxy* proxy = DeclareBoundVariable(name, VariableMode::kVar, pos);
NativeFunctionLiteral* lit =
factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
return factory()->NewExpressionStatement(
@@ -1549,8 +1571,11 @@ Expression* Parser::RewriteReturn(Expression* return_value, int pos) {
factory()->NewUndefinedLiteral(kNoSourcePosition), pos);
// is_undefined ? this : temp
+ // We don't need to call UseThis() since it's guaranteed to be called
+ // for derived constructors after parsing the constructor in
+ // ParseFunctionBody.
return_value =
- factory()->NewConditional(is_undefined, ThisExpression(pos),
+ factory()->NewConditional(is_undefined, factory()->ThisExpression(),
factory()->NewVariableProxy(temp), pos);
}
return return_value;
@@ -1594,15 +1619,27 @@ Statement* Parser::RewriteSwitchStatement(SwitchStatement* switch_statement,
return switch_block;
}
+void Parser::InitializeVariables(
+ ScopedPtrList<Statement>* statements, VariableKind kind,
+ const DeclarationParsingResult::Declaration* declaration) {
+ if (has_error()) return;
+
+ DCHECK_NOT_NULL(declaration->initializer);
+
+ int pos = declaration->value_beg_pos;
+ if (pos == kNoSourcePosition) {
+ pos = declaration->initializer->position();
+ }
+ Assignment* assignment = factory()->NewAssignment(
+ Token::INIT, declaration->pattern, declaration->initializer, pos);
+ statements->Add(factory()->NewExpressionStatement(assignment, pos));
+}
+
Block* Parser::RewriteCatchPattern(CatchInfo* catch_info) {
DCHECK_NOT_NULL(catch_info->pattern);
- // Initializer position for variables declared by the pattern.
- const int initializer_position = position();
-
DeclarationParsingResult::Declaration decl(
- catch_info->pattern, initializer_position,
- factory()->NewVariableProxy(catch_info->variable));
+ catch_info->pattern, factory()->NewVariableProxy(catch_info->variable));
ScopedPtrList<Statement> init_statements(pointer_buffer());
InitializeVariables(&init_statements, NORMAL_VARIABLE, &decl);
@@ -1789,7 +1826,7 @@ Block* Parser::RewriteForVarInLegacy(const ForInfo& for_info) {
const DeclarationParsingResult::Declaration& decl =
for_info.parsing_result.declarations[0];
if (!IsLexicalVariableMode(for_info.parsing_result.descriptor.mode) &&
- decl.pattern->IsVariableProxy() && decl.initializer != nullptr) {
+ decl.initializer != nullptr && decl.pattern->IsVariableProxy()) {
++use_counts_[v8::Isolate::kForInInitializer];
const AstRawString* name = decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = NewUnresolved(name);
@@ -1797,7 +1834,7 @@ Block* Parser::RewriteForVarInLegacy(const ForInfo& for_info) {
init_block->statements()->Add(
factory()->NewExpressionStatement(
factory()->NewAssignment(Token::ASSIGN, single_var,
- decl.initializer, kNoSourcePosition),
+ decl.initializer, decl.value_beg_pos),
kNoSourcePosition),
zone());
return init_block;
@@ -1827,7 +1864,8 @@ void Parser::DesugarBindingInForEachStatement(ForInfo* for_info,
for_info->parsing_result.declarations[0];
Variable* temp = NewTemporary(ast_value_factory()->dot_for_string());
ScopedPtrList<Statement> each_initialization_statements(pointer_buffer());
- decl.initializer = factory()->NewVariableProxy(temp);
+ DCHECK_IMPLIES(!has_error(), decl.pattern != nullptr);
+ decl.initializer = factory()->NewVariableProxy(temp, for_info->position);
InitializeVariables(&each_initialization_statements, NORMAL_VARIABLE, &decl);
*body_block = factory()->NewBlock(3, false);
@@ -1849,7 +1887,7 @@ Block* Parser::CreateForEachStatementTDZ(Block* init_block,
// TODO(adamk): This needs to be some sort of special
// INTERNAL variable that's invisible to the debugger
// but visible to everything else.
- VariableProxy* tdz_proxy = DeclareVariable(
+ VariableProxy* tdz_proxy = DeclareBoundVariable(
for_info.bound_names[i], VariableMode::kLet, kNoSourcePosition);
tdz_proxy->var()->set_initializer_position(position());
}
@@ -1898,7 +1936,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
// }
DCHECK_GT(for_info.bound_names.length(), 0);
- ZonePtrList<Variable> temps(for_info.bound_names.length(), zone());
+ ScopedPtrList<Variable> temps(pointer_buffer());
Block* outer_block =
factory()->NewBlock(for_info.bound_names.length() + 4, false);
@@ -1919,7 +1957,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Statement* assignment_statement =
factory()->NewExpressionStatement(assignment, kNoSourcePosition);
outer_block->statements()->Add(assignment_statement, zone());
- temps.Add(temp, zone());
+ temps.Add(temp);
}
Variable* first = nullptr;
@@ -1957,14 +1995,14 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Block* ignore_completion_block =
factory()->NewBlock(for_info.bound_names.length() + 3, true);
- ZonePtrList<Variable> inner_vars(for_info.bound_names.length(), zone());
+ ScopedPtrList<Variable> inner_vars(pointer_buffer());
// For each let variable x:
// make statement: let/const x = temp_x.
for (int i = 0; i < for_info.bound_names.length(); i++) {
- VariableProxy* proxy = DeclareVariable(
+ VariableProxy* proxy = DeclareBoundVariable(
for_info.bound_names[i], for_info.parsing_result.descriptor.mode,
kNoSourcePosition);
- inner_vars.Add(proxy->var(), zone());
+ inner_vars.Add(proxy->var());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
Assignment* assignment = factory()->NewAssignment(
Token::INIT, proxy, temp_proxy, kNoSourcePosition);
@@ -2175,8 +2213,7 @@ void Parser::AddArrowFunctionFormalParameters(
expr = assignment->target();
}
- AddFormalParameter(parameters, expr, initializer,
- end_pos, is_rest);
+ AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
}
void Parser::DeclareArrowFunctionFormalParameters(
@@ -2398,7 +2435,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(scope->start_position(), scope->end_position());
}
- CheckConflictingVarDeclarations(scope);
FunctionLiteral::ParameterFlag duplicate_parameters =
has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
@@ -2510,65 +2546,6 @@ bool Parser::SkipFunction(const AstRawString* function_name, FunctionKind kind,
return true;
}
-Statement* Parser::BuildAssertIsCoercible(Variable* var,
- ObjectLiteral* pattern) {
- // if (var === null || var === undefined)
- // throw /* type error kNonCoercible) */;
- auto source_position = pattern->position();
- const AstRawString* property = ast_value_factory()->empty_string();
- MessageTemplate msg = MessageTemplate::kNonCoercible;
- for (ObjectLiteralProperty* literal_property : *pattern->properties()) {
- Expression* key = literal_property->key();
- if (key->IsPropertyName()) {
- property = key->AsLiteral()->AsRawPropertyName();
- msg = MessageTemplate::kNonCoercibleWithProperty;
- source_position = key->position();
- break;
- }
- }
-
- Expression* condition = factory()->NewBinaryOperation(
- Token::OR,
- factory()->NewCompareOperation(
- Token::EQ_STRICT, factory()->NewVariableProxy(var),
- factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition),
- factory()->NewCompareOperation(
- Token::EQ_STRICT, factory()->NewVariableProxy(var),
- factory()->NewNullLiteral(kNoSourcePosition), kNoSourcePosition),
- kNoSourcePosition);
- Expression* throw_type_error =
- NewThrowTypeError(msg, property, source_position);
- IfStatement* if_statement = factory()->NewIfStatement(
- condition,
- factory()->NewExpressionStatement(throw_type_error, kNoSourcePosition),
- factory()->EmptyStatement(), kNoSourcePosition);
- return if_statement;
-}
-
-class InitializerRewriter final
- : public AstTraversalVisitor<InitializerRewriter> {
- public:
- InitializerRewriter(uintptr_t stack_limit, Expression* root, Parser* parser)
- : AstTraversalVisitor(stack_limit, root), parser_(parser) {}
-
- private:
- // This is required so that the overriden Visit* methods can be
- // called by the base class (template).
- friend class AstTraversalVisitor<InitializerRewriter>;
-
- // Code in function literals does not need to be eagerly rewritten, it will be
- // rewritten when scheduled.
- void VisitFunctionLiteral(FunctionLiteral* expr) {}
-
- Parser* parser_;
-};
-
-void Parser::RewriteParameterInitializer(Expression* expr) {
- if (has_error()) return;
- InitializerRewriter rewriter(stack_limit_, expr, this);
- rewriter.Run();
-}
-
Block* Parser::BuildParameterInitializationBlock(
const ParserFormalParameters& parameters) {
DCHECK(!parameters.is_simple);
@@ -2582,19 +2559,6 @@ Block* Parser::BuildParameterInitializationBlock(
if (parameter->initializer() != nullptr) {
// IS_UNDEFINED($param) ? initializer : $param
- if (parameter->initializer()->IsClassLiteral()) {
- // Initializers could have their own scopes. So set the scope
- // here if necessary.
- BlockState block_state(
- &scope_, parameter->initializer()->AsClassLiteral()->scope());
-
- // Ensure initializer is rewritten
- RewriteParameterInitializer(parameter->initializer());
- } else {
- // Ensure initializer is rewritten
- RewriteParameterInitializer(parameter->initializer());
- }
-
auto condition = factory()->NewCompareOperation(
Token::EQ_STRICT,
factory()->NewVariableProxy(parameters.scope->parameter(index)),
@@ -2617,12 +2581,13 @@ Block* Parser::BuildParameterInitializationBlock(
non_simple_param_init_statements.emplace(pointer_buffer());
param_init_statements = &non_simple_param_init_statements.value();
// Rewrite the outer initializer to point to param_scope
+ ReparentExpressionScope(stack_limit(), parameter->pattern, param_scope);
ReparentExpressionScope(stack_limit(), initial_value, param_scope);
}
BlockState block_state(&scope_, param_scope);
- DeclarationParsingResult::Declaration decl(
- parameter->pattern, parameter->initializer_end_position, initial_value);
+ DeclarationParsingResult::Declaration decl(parameter->pattern,
+ initial_value);
InitializeVariables(param_init_statements, PARAMETER_VARIABLE, &decl);
@@ -2787,7 +2752,7 @@ void Parser::DeclareClassVariable(const AstRawString* name,
if (name != nullptr) {
VariableProxy* proxy =
- DeclareVariable(name, VariableMode::kConst, class_token_pos);
+ DeclareBoundVariable(name, VariableMode::kConst, class_token_pos);
class_info->variable = proxy->var();
}
}
@@ -2797,7 +2762,7 @@ void Parser::DeclareClassVariable(const AstRawString* name,
// index in the AST, instead of storing the variable.
Variable* Parser::CreateSyntheticContextVariable(const AstRawString* name) {
VariableProxy* proxy =
- DeclareVariable(name, VariableMode::kConst, kNoSourcePosition);
+ DeclareBoundVariable(name, VariableMode::kConst, kNoSourcePosition);
proxy->var()->ForceContextAllocation();
return proxy->var();
}
@@ -2923,21 +2888,6 @@ Expression* Parser::RewriteClassLiteral(Scope* block_scope,
return class_literal;
}
-void Parser::CheckConflictingVarDeclarations(Scope* scope) {
- if (has_error()) return;
- Declaration* decl = scope->CheckConflictingVarDeclarations();
- if (decl != nullptr) {
- // In ES6, conflicting variable bindings are early errors.
- const AstRawString* name = decl->var()->raw_name();
- int position = decl->position();
- Scanner::Location location =
- position == kNoSourcePosition
- ? Scanner::Location::invalid()
- : Scanner::Location(position, position + 1);
- ReportMessageAt(location, MessageTemplate::kVarRedeclaration, name);
- }
-}
-
bool Parser::IsPropertyWithPrivateFieldKey(Expression* expression) {
if (!expression->IsProperty()) return false;
Property* property = expression->AsProperty();
@@ -3101,13 +3051,11 @@ void Parser::AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
}
}
-
void Parser::AddTemplateExpression(TemplateLiteralState* state,
Expression* expression) {
(*state)->AddExpression(expression, zone());
}
-
Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
Expression* tag) {
TemplateLiteral* lit = *state;
@@ -3177,7 +3125,7 @@ Expression* Parser::SpreadCall(Expression* function,
if (function->IsProperty()) {
// Method calls
if (function->AsProperty()->IsSuperAccess()) {
- Expression* home = ThisExpression(kNoSourcePosition);
+ Expression* home = ThisExpression();
args.Add(function);
args.Add(home);
} else {
@@ -3214,7 +3162,6 @@ Expression* Parser::SpreadCallNew(Expression* function,
return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
}
-
void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) {
v8::Isolate::UseCounterFeature feature;
if (is_sloppy(mode))