mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-21 14:47:31 +09:00
Inline Parser::checkFunctionDefinition into its sole caller.
This commit is contained in:
parent
092b87b756
commit
9191d0d06b
2 changed files with 49 additions and 65 deletions
|
|
@ -1307,7 +1307,7 @@ Parser<ParseHandler>::noteDeclaredName(HandlePropertyName name, DeclarationKind
|
||||||
// Functions in block have complex allowances in sloppy mode for being
|
// Functions in block have complex allowances in sloppy mode for being
|
||||||
// labelled that other lexical declarations do not have. Those checks
|
// labelled that other lexical declarations do not have. Those checks
|
||||||
// are more complex than calling checkLexicalDeclarationDirectlyWithin-
|
// are more complex than calling checkLexicalDeclarationDirectlyWithin-
|
||||||
// Block and are done in checkFunctionDefinition.
|
// Block and are done inline in callers.
|
||||||
|
|
||||||
ParseContext::Scope* scope = pc->innermostScope();
|
ParseContext::Scope* scope = pc->innermostScope();
|
||||||
if (AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name)) {
|
if (AddDeclaredNamePtr p = scope->lookupDeclaredNameForAdd(name)) {
|
||||||
|
|
@ -3008,61 +3008,6 @@ Parser<ParseHandler>::functionArguments(YieldHandling yieldHandling, FunctionSyn
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ParseHandler>
|
|
||||||
bool
|
|
||||||
Parser<ParseHandler>::checkFunctionDefinition(HandlePropertyName funName, Node pn,
|
|
||||||
GeneratorKind generatorKind, bool* tryAnnexB)
|
|
||||||
{
|
|
||||||
TokenPos pos = handler.getPosition(pn);
|
|
||||||
|
|
||||||
// In sloppy mode, Annex B.3.2 allows labelled function
|
|
||||||
// declarations. Otherwise it is a parse error.
|
|
||||||
ParseContext::Statement* declaredInStmt = pc->innermostStatement();
|
|
||||||
if (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) {
|
|
||||||
MOZ_ASSERT(!pc->sc()->strict(),
|
|
||||||
"labeled functions shouldn't be parsed in strict mode");
|
|
||||||
|
|
||||||
// Find the innermost non-label statement. Report an error if it's
|
|
||||||
// unbraced: functions can't appear in it. Otherwise the statement
|
|
||||||
// (or its absence) determines the scope the function's bound in.
|
|
||||||
while (declaredInStmt && declaredInStmt->kind() == StatementKind::Label)
|
|
||||||
declaredInStmt = declaredInStmt->enclosing();
|
|
||||||
|
|
||||||
if (declaredInStmt && !StatementKindIsBraced(declaredInStmt->kind())) {
|
|
||||||
reportWithOffset(ParseError, false, pos.begin, JSMSG_SLOPPY_FUNCTION_LABEL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (declaredInStmt) {
|
|
||||||
MOZ_ASSERT(declaredInStmt->kind() != StatementKind::Label);
|
|
||||||
MOZ_ASSERT(StatementKindIsBraced(declaredInStmt->kind()));
|
|
||||||
|
|
||||||
if (!pc->sc()->strict() && generatorKind == NotGenerator) {
|
|
||||||
// In sloppy mode, try Annex B.3.3 semantics. If making an
|
|
||||||
// additional 'var' binding of the same name does not throw an
|
|
||||||
// early error, do so. This 'var' binding would be assigned
|
|
||||||
// the function object when its declaration is reached, not at
|
|
||||||
// the start of the block.
|
|
||||||
|
|
||||||
if (!tryDeclareVarForAnnexBLexicalFunction(funName, tryAnnexB))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!noteDeclaredName(funName, DeclarationKind::LexicalFunction, pos))
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!noteDeclaredName(funName, DeclarationKind::BodyLevelFunction, pos))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Body-level functions in modules are always closed over.
|
|
||||||
if (pc->atModuleLevel())
|
|
||||||
pc->varScope().lookupDeclaredName(funName)->value()->setClosedOver();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
bool
|
bool
|
||||||
Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t preludeStart,
|
Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t preludeStart,
|
||||||
|
|
@ -3618,12 +3563,30 @@ Parser<ParseHandler>::functionStmt(uint32_t preludeStart, YieldHandling yieldHan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RootedPropertyName name(context);
|
// In sloppy mode, Annex B.3.2 allows labelled function declarations.
|
||||||
GeneratorKind generatorKind = asyncKind == AsyncFunction ? StarGenerator : NotGenerator;
|
// Otherwise it's a parse error.
|
||||||
|
ParseContext::Statement* declaredInStmt = pc->innermostStatement();
|
||||||
|
if (declaredInStmt && declaredInStmt->kind() == StatementKind::Label) {
|
||||||
|
MOZ_ASSERT(!pc->sc()->strict(),
|
||||||
|
"labeled functions shouldn't be parsed in strict mode");
|
||||||
|
|
||||||
|
// Find the innermost non-label statement. Report an error if it's
|
||||||
|
// unbraced: functions can't appear in it. Otherwise the statement
|
||||||
|
// (or its absence) determines the scope the function's bound in.
|
||||||
|
while (declaredInStmt && declaredInStmt->kind() == StatementKind::Label)
|
||||||
|
declaredInStmt = declaredInStmt->enclosing();
|
||||||
|
|
||||||
|
if (declaredInStmt && !StatementKindIsBraced(declaredInStmt->kind())) {
|
||||||
|
error(JSMSG_SLOPPY_FUNCTION_LABEL);
|
||||||
|
return null();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TokenKind tt;
|
TokenKind tt;
|
||||||
if (!tokenStream.getToken(&tt))
|
if (!tokenStream.getToken(&tt))
|
||||||
return null();
|
return null();
|
||||||
|
|
||||||
|
GeneratorKind generatorKind = asyncKind == AsyncFunction ? StarGenerator : NotGenerator;
|
||||||
if (tt == TOK_MUL) {
|
if (tt == TOK_MUL) {
|
||||||
if (asyncKind != SyncFunction) {
|
if (asyncKind != SyncFunction) {
|
||||||
error(JSMSG_ASYNC_GENERATOR);
|
error(JSMSG_ASYNC_GENERATOR);
|
||||||
|
|
@ -3634,6 +3597,7 @@ Parser<ParseHandler>::functionStmt(uint32_t preludeStart, YieldHandling yieldHan
|
||||||
return null();
|
return null();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RootedPropertyName name(context);
|
||||||
if (tt == TOK_NAME || tt == TOK_YIELD) {
|
if (tt == TOK_NAME || tt == TOK_YIELD) {
|
||||||
name = bindingIdentifier(yieldHandling);
|
name = bindingIdentifier(yieldHandling);
|
||||||
if (!name)
|
if (!name)
|
||||||
|
|
@ -3647,13 +3611,35 @@ Parser<ParseHandler>::functionStmt(uint32_t preludeStart, YieldHandling yieldHan
|
||||||
return null();
|
return null();
|
||||||
}
|
}
|
||||||
|
|
||||||
Node pn = handler.newFunctionStatement();
|
|
||||||
if (!pn)
|
|
||||||
return null();
|
|
||||||
|
|
||||||
// Note the declared name and check for early errors.
|
// Note the declared name and check for early errors.
|
||||||
bool tryAnnexB = false;
|
bool tryAnnexB = false;
|
||||||
if (!checkFunctionDefinition(name, pn, generatorKind, &tryAnnexB))
|
if (declaredInStmt) {
|
||||||
|
MOZ_ASSERT(declaredInStmt->kind() != StatementKind::Label);
|
||||||
|
MOZ_ASSERT(StatementKindIsBraced(declaredInStmt->kind()));
|
||||||
|
|
||||||
|
if (!pc->sc()->strict() && generatorKind == NotGenerator) {
|
||||||
|
// In sloppy mode, try Annex B.3.3 semantics. If making an
|
||||||
|
// additional 'var' binding of the same name does not throw an
|
||||||
|
// early error, do so. This 'var' binding would be assigned
|
||||||
|
// the function object when its declaration is reached, not at
|
||||||
|
// the start of the block.
|
||||||
|
if (!tryDeclareVarForAnnexBLexicalFunction(name, &tryAnnexB))
|
||||||
|
return null();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!noteDeclaredName(name, DeclarationKind::LexicalFunction, pos()))
|
||||||
|
return null();
|
||||||
|
} else {
|
||||||
|
if (!noteDeclaredName(name, DeclarationKind::BodyLevelFunction, pos()))
|
||||||
|
return null();
|
||||||
|
|
||||||
|
// Body-level functions in modules are always closed over.
|
||||||
|
if (pc->atModuleLevel())
|
||||||
|
pc->varScope().lookupDeclaredName(name)->value()->setClosedOver();
|
||||||
|
}
|
||||||
|
|
||||||
|
Node pn = handler.newFunctionStatement();
|
||||||
|
if (!pn)
|
||||||
return null();
|
return null();
|
||||||
|
|
||||||
YieldHandling newYieldHandling = GetYieldHandling(generatorKind, asyncKind);
|
YieldHandling newYieldHandling = GetYieldHandling(generatorKind, asyncKind);
|
||||||
|
|
|
||||||
|
|
@ -1349,8 +1349,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
Node newDotGeneratorName();
|
Node newDotGeneratorName();
|
||||||
bool declareDotGeneratorName();
|
bool declareDotGeneratorName();
|
||||||
|
|
||||||
bool checkFunctionDefinition(HandlePropertyName funName, Node pn,
|
|
||||||
GeneratorKind generatorKind, bool* tryAnnexB);
|
|
||||||
bool skipLazyInnerFunction(Node pn, uint32_t preludeStart, FunctionSyntaxKind kind,
|
bool skipLazyInnerFunction(Node pn, uint32_t preludeStart, FunctionSyntaxKind kind,
|
||||||
bool tryAnnexB);
|
bool tryAnnexB);
|
||||||
bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t preludeStart,
|
bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t preludeStart,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue