Reinstate a few assertions in TokenPos constructors. Bug 695922, r=luke.

This commit is contained in:
Jason Orendorff 2012-01-27 14:14:01 -06:00
parent 3bc51065cd
commit 68e5914814
3 changed files with 19 additions and 13 deletions

View File

@ -1294,8 +1294,7 @@ Parser::functionArguments(TreeContext &funtc, FunctionBox *funbox, ParseNode **l
rhs->pn_cookie.set(funtc.staticLevel, slot);
rhs->pn_dflags |= PND_BOUND;
ParseNode *item =
ParseNode::newBinaryOrAppend(PNK_ASSIGN, JSOP_NOP, lhs, rhs, &funtc);
ParseNode *item = new_<BinaryNode>(PNK_ASSIGN, JSOP_NOP, lhs->pn_pos, lhs, rhs);
if (!item)
return false;
if (!list) {
@ -6919,6 +6918,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
for (;;) {
JSAtom *atom;
TokenKind ltok = tokenStream.getToken(TSF_KEYWORD_IS_NAME);
TokenPtr begin = tokenStream.currentToken().pos.begin;
switch (ltok) {
case TOK_NUMBER:
pn3 = NullaryNode::create(PNK_NUMBER, tc);
@ -6985,7 +6985,10 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
/* NB: Getter function in { get x(){} } is unnamed. */
pn2 = functionDef(NULL, op == JSOP_GETTER ? Getter : Setter, Expression);
pn2 = ParseNode::newBinaryOrAppend(PNK_COLON, op, pn3, pn2, tc);
if (!pn2)
return NULL;
TokenPos pos = {begin, pn2->pn_pos.end};
pn2 = new_<BinaryNode>(PNK_COLON, op, pos, pn3, pn2);
goto skip;
}
case TOK_STRING: {
@ -7015,16 +7018,16 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
tt = tokenStream.getToken();
if (tt == TOK_COLON) {
pnval = assignExpr();
if (!pnval)
return NULL;
/*
* Treat initializers which mutate __proto__ as non-constant,
* so that we can later assume singleton objects delegate to
* the default Object.prototype.
*/
if ((pnval && !pnval->isConstant()) ||
atom == context->runtime->atomState.protoAtom) {
if (!pnval->isConstant() || atom == context->runtime->atomState.protoAtom)
pn->pn_xflags |= PNX_NONCONST;
}
}
#if JS_HAS_DESTRUCTURING_SHORTHAND
else if (ltok == TOK_NAME && (tt == TOK_COMMA || tt == TOK_RC)) {
@ -7047,7 +7050,10 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
return NULL;
}
pn2 = ParseNode::newBinaryOrAppend(PNK_COLON, op, pn3, pnval, tc);
{
TokenPos pos = {begin, pnval->pn_pos.end};
pn2 = new_<BinaryNode>(PNK_COLON, op, pos, pn3, pnval);
}
skip:
if (!pn2)
return NULL;

View File

@ -262,18 +262,16 @@ struct TokenPos {
TokenPtr end; /* index 1 past last char, last line */
static TokenPos make(const TokenPtr &begin, const TokenPtr &end) {
// Assertions temporarily disabled by jorendorff. See bug 695922.
//JS_ASSERT(begin <= end);
JS_ASSERT(begin <= end);
TokenPos pos = {begin, end};
return pos;
}
/* Return a TokenPos that covers left, right, and anything in between. */
static TokenPos box(const TokenPos &left, const TokenPos &right) {
// Assertions temporarily disabled by jorendorff. See bug 695922.
//JS_ASSERT(left.begin <= left.end);
//JS_ASSERT(left.end <= right.begin);
//JS_ASSERT(right.begin <= right.end);
JS_ASSERT(left.begin <= left.end);
JS_ASSERT(left.end <= right.begin);
JS_ASSERT(right.begin <= right.end);
TokenPos pos = {left.begin, right.end};
return pos;
}

View File

@ -0,0 +1,2 @@
load(libdir + "asserts.js");
assertThrowsInstanceOf(function () { eval("({p:"); }, SyntaxError); // don't crash