Bug 1297706 - Syntax parse lexical declarations. r=jandem

This commit is contained in:
Shu-yu Guo 2016-09-01 13:55:56 +02:00
Родитель 0c1d7143d1
Коммит 85437bebb4
2 изменённых файлов: 18 добавлений и 25 удалений

Просмотреть файл

@ -4322,12 +4322,10 @@ Parser<ParseHandler>::declarationList(YieldHandling yieldHandling,
return decl;
}
template <>
ParseNode*
Parser<FullParseHandler>::lexicalDeclaration(YieldHandling yieldHandling, bool isConst)
template <typename ParseHandler>
typename ParseHandler::Node
Parser<ParseHandler>::lexicalDeclaration(YieldHandling yieldHandling, bool isConst)
{
handler.disableSyntaxParser();
/*
* Parse body-level lets without a new block object. ES6 specs
* that an execution environment's initial lexical environment
@ -4339,21 +4337,13 @@ Parser<FullParseHandler>::lexicalDeclaration(YieldHandling yieldHandling, bool i
*
* See 8.1.1.1.6 and the note in 13.2.1.
*/
ParseNode* decl = declarationList(yieldHandling, isConst ? PNK_CONST : PNK_LET);
Node decl = declarationList(yieldHandling, isConst ? PNK_CONST : PNK_LET);
if (!decl || !MatchOrInsertSemicolonAfterExpression(tokenStream))
return null();
return decl;
}
template <>
SyntaxParseHandler::Node
Parser<SyntaxParseHandler>::lexicalDeclaration(YieldHandling, bool)
{
JS_ALWAYS_FALSE(abortIfSyntaxParser());
return SyntaxParseHandler::NodeFailure;
}
template <>
bool
Parser<FullParseHandler>::namedImportsOrNamespaceImport(TokenKind tt, Node importSpecSet)
@ -6899,8 +6889,6 @@ Parser<ParseHandler>::statementListItem(YieldHandling yieldHandling,
// LetOrConst BindingList[?In, ?Yield]
case TOK_LET:
case TOK_CONST:
if (!abortIfSyntaxParser())
return null();
// [In] is the default behavior, because for-loops specially parse
// their heads to handle |in| in this situation.
return lexicalDeclaration(yieldHandling, /* isConst = */ tt == TOK_CONST);

Просмотреть файл

@ -46,7 +46,8 @@ class SyntaxParseHandler
NodeThrow,
NodeEmptyStatement,
NodeDeclaration,
NodeVarDeclaration,
NodeLexicalDeclaration,
NodeFunctionDefinition,
@ -376,22 +377,25 @@ class SyntaxParseHandler
}
Node newDeclarationList(ParseNodeKind kind, JSOp op = JSOP_NOP) {
return NodeDeclaration;
if (kind == PNK_VAR)
return NodeVarDeclaration;
MOZ_ASSERT(kind == PNK_LET || kind == PNK_CONST);
return NodeLexicalDeclaration;
}
Node newDeclarationList(ParseNodeKind kind, Node kid, JSOp op = JSOP_NOP) {
return NodeDeclaration;
return newDeclarationList(kind, op);
}
bool isDeclarationList(Node node) {
return node == NodeDeclaration;
return node == NodeVarDeclaration || node == NodeLexicalDeclaration;
}
Node singleBindingFromDeclaration(Node decl) {
MOZ_ASSERT(isDeclarationList(decl));
// This is, unfortunately, very dodgy. Obviously NodeDeclaration
// can store no info on the arbitrary number of bindings it could
// contain.
// This is, unfortunately, very dodgy. Obviously NodeVarDeclaration
// and NodeLexicalDeclaration can store no info on the arbitrary
// number of bindings it could contain.
//
// But this method is called only for cloning for-in/of declarations
// as initialization targets. That context simplifies matters. If the
@ -419,7 +423,8 @@ class SyntaxParseHandler
list == NodeUnparenthesizedArray ||
list == NodeUnparenthesizedObject ||
list == NodeUnparenthesizedCommaExpr ||
list == NodeDeclaration ||
list == NodeVarDeclaration ||
list == NodeLexicalDeclaration ||
list == NodeFunctionCall);
}
@ -442,7 +447,7 @@ class SyntaxParseHandler
}
bool isStatementPermittedAfterReturnStatement(Node pn) {
return pn == NodeFunctionDefinition || pn == NodeDeclaration ||
return pn == NodeFunctionDefinition || pn == NodeVarDeclaration ||
pn == NodeBreak ||
pn == NodeThrow ||
pn == NodeEmptyStatement;