зеркало из https://github.com/mozilla/gecko-dev.git
Bug 883226, part 6 - Clean up string literal parsing. r=Waldo.
This commit is contained in:
Родитель
1708ced874
Коммит
29c045d435
|
@ -103,14 +103,11 @@ class FullParseHandler
|
|||
dn->pn_dflags |= PND_PLACEHOLDER;
|
||||
return dn;
|
||||
}
|
||||
ParseNode *newAtom(ParseNodeKind kind, JSAtom *atom, JSOp op = JSOP_NOP) {
|
||||
ParseNode *pn = new_<NullaryNode>(kind, pos());
|
||||
if (!pn)
|
||||
return NULL;
|
||||
pn->setOp(op);
|
||||
pn->pn_atom = atom;
|
||||
return pn;
|
||||
|
||||
ParseNode *newAtom(ParseNodeKind kind, JSAtom *atom, const TokenPos &pos) {
|
||||
return new_<NullaryNode>(kind, JSOP_NOP, pos, atom);
|
||||
}
|
||||
|
||||
ParseNode *newNumber(double value, DecimalPoint decimalPoint, const TokenPos &pos) {
|
||||
ParseNode *pn = new_<NullaryNode>(PNK_NUMBER, pos);
|
||||
if (!pn)
|
||||
|
@ -122,9 +119,15 @@ class FullParseHandler
|
|||
ParseNode *newBooleanLiteral(bool cond, const TokenPos &pos) {
|
||||
return new_<BooleanLiteral>(cond, pos);
|
||||
}
|
||||
|
||||
ParseNode *newStringLiteral(JSAtom *atom, const TokenPos &pos) {
|
||||
return new_<NullaryNode>(PNK_STRING, JSOP_STRING, pos, atom);
|
||||
}
|
||||
|
||||
ParseNode *newThisLiteral(const TokenPos &pos) {
|
||||
return new_<ThisLiteral>(pos);
|
||||
}
|
||||
|
||||
ParseNode *newNullLiteral(const TokenPos &pos) {
|
||||
return new_<NullLiteral>(pos);
|
||||
}
|
||||
|
|
|
@ -6375,21 +6375,18 @@ Parser<ParseHandler>::identifierName()
|
|||
|
||||
template <typename ParseHandler>
|
||||
typename ParseHandler::Node
|
||||
Parser<ParseHandler>::atomNode(ParseNodeKind kind, JSOp op)
|
||||
Parser<ParseHandler>::stringLiteral()
|
||||
{
|
||||
JSAtom *atom = tokenStream.currentToken().atom();
|
||||
Node pn = handler.newAtom(kind, atom, op);
|
||||
if (!pn)
|
||||
return null();
|
||||
|
||||
// Large strings are fast to parse but slow to compress. Stop compression on
|
||||
// them, so we don't wait for a long time for compression to finish at the
|
||||
// end of compilation.
|
||||
const size_t HUGE_STRING = 50000;
|
||||
if (sct && sct->active() && kind == PNK_STRING && atom->length() >= HUGE_STRING)
|
||||
if (sct && sct->active() && atom->length() >= HUGE_STRING)
|
||||
sct->abort();
|
||||
|
||||
return pn;
|
||||
return handler.newStringLiteral(atom, pos());
|
||||
}
|
||||
|
||||
template <typename ParseHandler>
|
||||
|
@ -6589,7 +6586,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
|
|||
} else if (atom == context->names().set) {
|
||||
op = JSOP_INITPROP_SETTER;
|
||||
} else {
|
||||
pn3 = handler.newAtom(PNK_NAME, atom);
|
||||
pn3 = handler.newAtom(PNK_NAME, atom, pos());
|
||||
if (!pn3)
|
||||
return null();
|
||||
break;
|
||||
|
@ -6614,7 +6611,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
|
|||
if (!atom)
|
||||
return null();
|
||||
} else {
|
||||
pn3 = handler.newName(atom->asPropertyName(), pc, PNK_STRING);
|
||||
pn3 = stringLiteral();
|
||||
if (!pn3)
|
||||
return null();
|
||||
}
|
||||
|
@ -6629,7 +6626,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
|
|||
return null();
|
||||
} else {
|
||||
tokenStream.ungetToken();
|
||||
pn3 = handler.newAtom(PNK_NAME, atom);
|
||||
pn3 = handler.newAtom(PNK_NAME, atom, pos());
|
||||
if (!pn3)
|
||||
return null();
|
||||
break;
|
||||
|
@ -6659,7 +6656,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
|
|||
if (!pn3)
|
||||
return null();
|
||||
} else {
|
||||
pn3 = handler.newAtom(PNK_STRING, atom);
|
||||
pn3 = stringLiteral();
|
||||
if (!pn3)
|
||||
return null();
|
||||
}
|
||||
|
@ -6798,7 +6795,7 @@ Parser<ParseHandler>::primaryExpr(TokenKind tt)
|
|||
}
|
||||
|
||||
case TOK_STRING:
|
||||
return atomNode(PNK_STRING, JSOP_STRING);
|
||||
return stringLiteral();
|
||||
|
||||
case TOK_NAME:
|
||||
return identifierName();
|
||||
|
|
|
@ -361,11 +361,7 @@ struct Parser : private AutoGCRooter, public StrictModeGetter
|
|||
private:
|
||||
Parser *thisForCtor() { return this; }
|
||||
|
||||
/*
|
||||
* Create a parse node with the given kind and op using the current token's
|
||||
* atom.
|
||||
*/
|
||||
Node atomNode(ParseNodeKind kind, JSOp op);
|
||||
Node stringLiteral();
|
||||
|
||||
inline bool abortIfSyntaxParser();
|
||||
|
||||
|
|
|
@ -57,15 +57,16 @@ class SyntaxParseHandler
|
|||
DefinitionNode newPlaceholder(JSAtom *atom, ParseContext<SyntaxParseHandler> *pc) {
|
||||
return Definition::PLACEHOLDER;
|
||||
}
|
||||
Node newAtom(ParseNodeKind kind, JSAtom *atom, JSOp op = JSOP_NOP) {
|
||||
if (kind == PNK_STRING) {
|
||||
lastAtom = atom;
|
||||
lastStringPos = tokenStream.currentToken().pos;
|
||||
}
|
||||
return NodeString;
|
||||
}
|
||||
Node newAtom(ParseNodeKind kind, JSAtom *atom, const TokenPos &pos) { return NodeString; }
|
||||
Node newNumber(double value, DecimalPoint decimalPoint, const TokenPos &pos) { return NodeGeneric; }
|
||||
Node newBooleanLiteral(bool cond, const TokenPos &pos) { return NodeGeneric; }
|
||||
|
||||
Node newStringLiteral(JSAtom *atom, const TokenPos &pos) {
|
||||
lastAtom = atom;
|
||||
lastStringPos = pos;
|
||||
return NodeString;
|
||||
}
|
||||
|
||||
Node newThisLiteral(const TokenPos &pos) { return NodeGeneric; }
|
||||
Node newNullLiteral(const TokenPos &pos) { return NodeGeneric; }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче