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

[parser] Skipping inner funcs: Fix default ctors in PreParser.

Parser creates a FunctionState for default ctors, which affects the
next_function_is_likely_called logic. PreParser needs to match that logic, so
that Parser and PreParser agree about which functions are skippable.

BUG=v8:5515, chromium:773576

Change-Id: I96cb6f5aa68e74389a863355f70a34693a2d1329
Reviewed-on: https://chromium-review.googlesource.com/712579
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48511}
parent c00fc26e
......@@ -336,12 +336,6 @@ bool ProducedPreParsedScopeData::ScopeIsSkippableFunctionScope(Scope* scope) {
void ProducedPreParsedScopeData::SaveDataForScope(Scope* scope) {
DCHECK_NE(scope->end_position(), kNoSourcePosition);
// We're not trying to save data for default constructors because the
// PreParser doesn't construct them.
DCHECK_IMPLIES(scope->scope_type() == ScopeType::FUNCTION_SCOPE,
(scope->AsDeclarationScope()->function_kind() &
kDefaultConstructor) == 0);
if (!ScopeNeedsData(scope)) {
return;
}
......
......@@ -1124,7 +1124,22 @@ class PreParser : public ParserBase<PreParser> {
ClassInfo* class_info, int pos, int end_pos, bool* ok) {
bool has_default_constructor = !class_info->has_seen_constructor;
// Account for the default constructor.
if (has_default_constructor) GetNextFunctionLiteralId();
if (has_default_constructor) {
// Creating and disposing of a FunctionState makes tracking of
// next_function_is_likely_called match what Parser does. TODO(marja):
// Make the lazy function + next_function_is_likely_called + default ctor
// logic less surprising. Default ctors shouldn't affect the laziness of
// functions.
bool has_extends = class_info->extends.IsNull();
FunctionKind kind = has_extends ? FunctionKind::kDefaultDerivedConstructor
: FunctionKind::kDefaultBaseConstructor;
DeclarationScope* function_scope = NewFunctionScope(kind);
SetLanguageMode(function_scope, STRICT);
function_scope->set_start_position(pos);
function_scope->set_end_position(pos);
FunctionState function_state(&function_state_, &scope_, function_scope);
GetNextFunctionLiteralId();
}
return PreParserExpression::Default();
}
......
......@@ -352,3 +352,16 @@ TestSkippableFunctionInForOfHeaderAndBody();
}
lazy();
})();
(function TestLazinessDecisionWithDefaultConstructors() {
// Regression test for
// https://bugs.chromium.org/p/chromium/issues/detail?id=773576
// The problem was that Parser and PreParser treated default constructors
// differently, and that threw off the "next / previous function is likely
// called" logic.
function lazy(p = (function() {}, class {}, function() {}, class { method1() { } })) { }
lazy();
})();
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