зеркало из https://github.com/mozilla/gecko-dev.git
Bug 883333, part 10 - Refactor throw statement parsing. r=Waldo.
--HG-- extra : rebase_source : 0ace9a0daabe0df4151dcf2a0ade7890aee6a4c1
This commit is contained in:
Родитель
abac2332b1
Коммит
75aaa9d753
|
@ -4577,6 +4577,32 @@ Parser<ParseHandler>::labeledStatement()
|
|||
return handler.newLabeledStatement(label, pn, begin);
|
||||
}
|
||||
|
||||
template <typename ParseHandler>
|
||||
typename ParseHandler::Node
|
||||
Parser<ParseHandler>::throwStatement()
|
||||
{
|
||||
JS_ASSERT(tokenStream.isCurrentTokenType(TOK_THROW));
|
||||
uint32_t begin = pos().begin;
|
||||
|
||||
/* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */
|
||||
TokenKind tt = tokenStream.peekTokenSameLine(TSF_OPERAND);
|
||||
if (tt == TOK_ERROR)
|
||||
return null();
|
||||
if (tt == TOK_EOF || tt == TOK_EOL || tt == TOK_SEMI || tt == TOK_RC) {
|
||||
report(ParseError, false, null(), JSMSG_SYNTAX_ERROR);
|
||||
return null();
|
||||
}
|
||||
|
||||
Node throwExpr = expr();
|
||||
if (!throwExpr)
|
||||
return null();
|
||||
|
||||
if (!MatchOrInsertSemicolon(context, &tokenStream))
|
||||
return null();
|
||||
|
||||
return handler.newThrowStatement(throwExpr, TokenPos::make(begin, pos().end));
|
||||
}
|
||||
|
||||
template <typename ParseHandler>
|
||||
typename ParseHandler::Node
|
||||
Parser<ParseHandler>::tryStatement()
|
||||
|
@ -4828,27 +4854,7 @@ Parser<ParseHandler>::statement(bool canHaveDirectives)
|
|||
return withStatement();
|
||||
|
||||
case TOK_THROW:
|
||||
{
|
||||
uint32_t begin = pos().begin;
|
||||
|
||||
/* ECMA-262 Edition 3 says 'throw [no LineTerminator here] Expr'. */
|
||||
TokenKind tt = tokenStream.peekTokenSameLine(TSF_OPERAND);
|
||||
if (tt == TOK_ERROR)
|
||||
return null();
|
||||
if (tt == TOK_EOF || tt == TOK_EOL || tt == TOK_SEMI || tt == TOK_RC) {
|
||||
report(ParseError, false, null(), JSMSG_SYNTAX_ERROR);
|
||||
return null();
|
||||
}
|
||||
|
||||
Node pnexp = expr();
|
||||
if (!pnexp)
|
||||
return null();
|
||||
|
||||
pn = handler.newThrowStatement(pnexp, TokenPos::make(begin, pos().end));
|
||||
if (!pn)
|
||||
return null();
|
||||
break;
|
||||
}
|
||||
return throwStatement();
|
||||
|
||||
case TOK_TRY:
|
||||
return tryStatement();
|
||||
|
|
|
@ -427,6 +427,7 @@ struct Parser : private AutoGCRooter, public StrictModeGetter
|
|||
Node returnStatementOrYieldExpression();
|
||||
Node withStatement();
|
||||
Node labeledStatement();
|
||||
Node throwStatement();
|
||||
Node tryStatement();
|
||||
#if JS_HAS_BLOCK_SCOPE
|
||||
Node letStatement();
|
||||
|
|
Загрузка…
Ссылка в новой задаче