mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1298809 - Fix skipping lazy function expression bodies to account for semicolon. (r=Waldo)
This commit is contained in:
parent
25da11fb5e
commit
02dc0c0895
@ -2841,7 +2841,8 @@ Parser<ParseHandler>::checkFunctionDefinition(HandleAtom funAtom, Node pn, Funct
|
||||
|
||||
template <>
|
||||
bool
|
||||
Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, bool tryAnnexB)
|
||||
Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, FunctionSyntaxKind kind,
|
||||
bool tryAnnexB)
|
||||
{
|
||||
// When a lazily-parsed function is called, we only fully parse (and emit)
|
||||
// that function, not any of its nested children. The initial syntax-only
|
||||
@ -2867,12 +2868,21 @@ Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, bool tryAnnexB)
|
||||
// script source.
|
||||
Rooted<LazyScript*> lazyOuter(context, handler.lazyOuterFunction());
|
||||
uint32_t userbufBase = lazyOuter->begin() - lazyOuter->column();
|
||||
return tokenStream.advance(fun->lazyScript()->end() - userbufBase);
|
||||
if (!tokenStream.advance(fun->lazyScript()->end() - userbufBase))
|
||||
return false;
|
||||
|
||||
if (kind == Statement && fun->isExprBody()) {
|
||||
if (!MatchOrInsertSemicolonAfterExpression(tokenStream))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool
|
||||
Parser<SyntaxParseHandler>::skipLazyInnerFunction(Node pn, bool tryAnnexB)
|
||||
Parser<SyntaxParseHandler>::skipLazyInnerFunction(Node pn, FunctionSyntaxKind kind,
|
||||
bool tryAnnexB)
|
||||
{
|
||||
MOZ_CRASH("Cannot skip lazy inner functions when syntax parsing");
|
||||
}
|
||||
@ -2970,7 +2980,7 @@ Parser<ParseHandler>::functionDefinition(InHandling inHandling, YieldHandling yi
|
||||
// functions, which are also lazy. Instead, their free variables and
|
||||
// source extents are recorded and may be skipped.
|
||||
if (handler.canSkipLazyInnerFunctions()) {
|
||||
if (!skipLazyInnerFunction(pn, tryAnnexB))
|
||||
if (!skipLazyInnerFunction(pn, kind, tryAnnexB))
|
||||
return null();
|
||||
return pn;
|
||||
}
|
||||
|
@ -1259,7 +1259,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||
|
||||
bool checkFunctionDefinition(HandleAtom funAtom, Node pn, FunctionSyntaxKind kind,
|
||||
GeneratorKind generatorKind, bool* tryAnnexB);
|
||||
bool skipLazyInnerFunction(Node pn, bool tryAnnexB);
|
||||
bool skipLazyInnerFunction(Node pn, FunctionSyntaxKind kind, bool tryAnnexB);
|
||||
bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun,
|
||||
InHandling inHandling, FunctionSyntaxKind kind,
|
||||
GeneratorKind generatorKind, bool tryAnnexB,
|
||||
|
6
js/src/jit-test/tests/parser/bug-1298809.js
Normal file
6
js/src/jit-test/tests/parser/bug-1298809.js
Normal file
@ -0,0 +1,6 @@
|
||||
function f() {
|
||||
if (0)
|
||||
function g() x;
|
||||
else;
|
||||
}
|
||||
f();
|
Loading…
Reference in New Issue
Block a user