Commit 7a457c71 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser] Skipping inner funcs: params part 5

Handle eval in default parameters.

BUG=v8:5516
R=vogelheim@chromium.org

Change-Id: Ib6543a4aef9a3cc9636e65d0337bc269c8a079dc
Reviewed-on: https://chromium-review.googlesource.com/444747
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43328}
parent 38affafd
......@@ -3518,6 +3518,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
// BindingElement[?Yield, ?GeneratorParameter]
bool is_rest = parameters->has_rest;
int initializer_start_position = kNoSourcePosition;
ExpressionT pattern = ParsePrimaryExpression(CHECK_OK_CUSTOM(Void));
ValidateBindingPattern(CHECK_OK_CUSTOM(Void));
......@@ -3530,6 +3531,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
ExpressionT initializer = impl()->EmptyExpression();
if (!is_rest && Check(Token::ASSIGN)) {
ExpressionClassifier init_classifier(this);
initializer_start_position = scanner()->peek_location().beg_pos;
initializer = ParseAssignmentExpression(true, CHECK_OK_CUSTOM(Void));
impl()->RewriteNonPattern(CHECK_OK_CUSTOM(Void));
ValidateFormalParameterInitializer(CHECK_OK_CUSTOM(Void));
......@@ -3541,6 +3543,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
}
impl()->AddFormalParameter(parameters, pattern, initializer,
initializer_start_position,
scanner()->location().end_pos, is_rest);
}
......
......@@ -2443,7 +2443,9 @@ void Parser::AddArrowFunctionFormalParameters(
expr = assignment->target();
}
AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
AddFormalParameter(parameters, expr, initializer,
initializer ? initializer->position() : kNoSourcePosition,
end_pos, is_rest);
}
void Parser::DeclareArrowFunctionFormalParameters(
......
......@@ -1051,6 +1051,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
Expression* pattern,
Expression* initializer,
int initializer_start_position,
int initializer_end_position,
bool is_rest) {
parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest);
......
......@@ -791,18 +791,37 @@ class PreParserFactory {
struct PreParserFormalParameters : FormalParametersBase {
struct Parameter : public ZoneObject {
Parameter(PreParserExpression pattern, bool is_destructuring, bool is_rest)
Parameter(PreParserExpression pattern, bool is_destructuring,
bool has_initializer, int initializer_start_position,
int initializer_end_position, bool is_rest)
: pattern(pattern),
initializer_start_position(initializer_start_position),
initializer_end_position(initializer_end_position),
is_destructuring(is_destructuring),
is_rest(is_rest) {}
has_initializer(has_initializer),
is_rest(is_rest) {
DCHECK_IMPLIES(is_rest, !has_initializer);
DCHECK_IMPLIES(has_initializer,
initializer_start_position != kNoSourcePosition);
DCHECK_IMPLIES(has_initializer,
initializer_end_position != kNoSourcePosition);
}
Parameter** next() { return &next_parameter; }
Parameter* const* next() const { return &next_parameter; }
bool is_simple() const {
return !is_destructuring && !has_initializer && !is_rest;
}
bool is_nondestructuring_rest() const {
return is_rest && !is_destructuring;
}
PreParserExpression pattern;
int initializer_start_position;
int initializer_end_position;
Parameter* next_parameter = nullptr;
bool is_destructuring : 1;
bool has_initializer : 1;
bool is_rest : 1;
};
explicit PreParserFormalParameters(DeclarationScope* scope)
......@@ -1387,6 +1406,13 @@ class PreParser : public ParserBase<PreParser> {
if (track_unresolved_variables_) {
for (auto parameter : parameters.params) {
if (parameter->is_nondestructuring_rest()) break;
if (!parameter->is_simple() && scope()->calls_sloppy_eval()) {
Scope* param_scope = NewVarblockScope();
param_scope->set_start_position(
parameter->initializer_start_position);
param_scope->set_end_position(parameter->initializer_end_position);
param_scope->RecordEvalCall();
}
if (parameter->pattern.variables_ != nullptr) {
for (auto variable : *parameter->pattern.variables_) {
scope()->DeclareVariableName(variable->raw_name(), LET);
......@@ -1610,12 +1636,14 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters,
PreParserExpression pattern,
PreParserExpression initializer,
int initializer_start_position,
int initializer_end_position,
bool is_rest) {
if (track_unresolved_variables_) {
DCHECK(FLAG_lazy_inner_functions);
parameters->params.Add(new (zone()) PreParserFormalParameters::Parameter(
pattern, !IsIdentifier(pattern), is_rest));
pattern, !IsIdentifier(pattern), !IsEmptyExpression(initializer),
initializer_start_position, initializer_end_position, is_rest));
}
parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest);
}
......
......@@ -440,6 +440,12 @@ TEST(PreParserScopeAnalysis) {
// Hoisted sloppy block function shadowing a parameter.
{"var1, var2", "for (;;) { function var1() { } }"},
// Eval in default parameter.
{"var1, var2 = eval(''), var3", "let var4 = 0;", true},
{"var1, var2 = eval(''), var3 = eval('')", "let var4 = 0;", true},
// FIXME(marja): arguments parameter
};
for (unsigned outer_ix = 0; outer_ix < arraysize(outers); ++outer_ix) {
......
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