diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index b3a19513f9b9..3ef90bffaf22 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -7240,7 +7240,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) pn3 = NullaryNode::create(tc); if (!pn3) return NULL; - pn3->pn_dval = tokenStream.currentToken().t_dval; + pn3->pn_dval = tokenStream.currentToken().number(); if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom)) return NULL; break; @@ -7266,7 +7266,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) pn3 = NullaryNode::create(tc); if (!pn3) return NULL; - pn3->pn_dval = tokenStream.currentToken().t_dval; + pn3->pn_dval = tokenStream.currentToken().number(); if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom)) return NULL; } else { @@ -7412,7 +7412,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) pn = UnaryNode::create(tc); if (!pn) return NULL; - pn->pn_num = (jsint) tokenStream.currentToken().t_dval; + pn->pn_num = tokenStream.currentToken().sharpNumber(); tt = tokenStream.getToken(TSF_OPERAND); pn->pn_kid = primaryExpr(tt, JS_FALSE); if (!pn->pn_kid) @@ -7436,7 +7436,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) return NULL; if (!tc->ensureSharpSlots()) return NULL; - pn->pn_num = (jsint) tokenStream.currentToken().t_dval; + pn->pn_num = tokenStream.currentToken().sharpNumber(); break; #endif /* JS_HAS_SHARP_VARS */ @@ -7667,7 +7667,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) if (!pn) return NULL; pn->setOp(JSOP_DOUBLE); - pn->pn_dval = tokenStream.currentToken().t_dval; + pn->pn_dval = tokenStream.currentToken().number(); break; case TOK_PRIMARY: diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index bc00f20414f4..652a71ab1320 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -1713,7 +1713,7 @@ TokenStream::getTokenInternal() if (!js_strtod(cx, numStart, userbuf.addressOfNextRawChar(), &dummy, &dval)) goto error; } - tp->t_dval = dval; + tp->setNumber(dval); tt = TOK_NUMBER; goto out; } @@ -1799,7 +1799,7 @@ TokenStream::getTokenInternal() const jschar *dummy; if (!GetPrefixInteger(cx, numStart, userbuf.addressOfNextRawChar(), radix, &dummy, &dval)) goto error; - tp->t_dval = dval; + tp->setNumber(dval); tt = TOK_NUMBER; goto out; } @@ -2071,9 +2071,8 @@ TokenStream::getTokenInternal() goto error; } } - tp->t_dval = (jsdouble) n; - if (cx->hasStrictOption() && - (c == '=' || c == '#')) { + tp->setSharpNumber(uint16(n)); + if (cx->hasStrictOption() && (c == '=' || c == '#')) { char buf[20]; JS_snprintf(buf, sizeof buf, "#%u%c", n, c); if (!ReportCompileErrorNumber(cx, this, NULL, JSREPORT_WARNING | JSREPORT_STRICT, diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 27d52d090a33..47d5758f70d0 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -265,14 +265,15 @@ struct Token { JSAtom *atom; /* potentially-numeric atom */ } n; } s; - class { /* pair for XML PI */ - friend struct Token; + + private: + friend struct Token; + struct { /* pair for XML PI */ JSAtom *data; /* auxiliary atom table entry */ PropertyName *target; /* main atom table entry */ } xmlpi; - jsdouble dval; /* floating point number */ - private: - friend struct Token; + uint16 sharpNumber; /* sharp variable number: #1# or #1= */ + jsdouble number; /* floating point number */ RegExpFlag reflags; /* regexp flags, use tokenbuf to access regexp chars */ } u; @@ -306,6 +307,14 @@ struct Token { u.reflags = flags; } + void setSharpNumber(uint16 sharpNum) { + u.sharpNumber = sharpNum; + } + + void setNumber(jsdouble n) { + u.number = n; + } + /* Type-safe accessors */ PropertyName *name() const { @@ -338,10 +347,19 @@ struct Token { JS_ASSERT((u.reflags & AllFlags) == u.reflags); return u.reflags; } + + uint16 sharpNumber() const { + JS_ASSERT(type == TOK_DEFSHARP || type == TOK_USESHARP); + return u.sharpNumber; + } + + jsdouble number() const { + JS_ASSERT(type == TOK_NUMBER); + return u.number; + } }; #define t_op u.s.op -#define t_dval u.dval enum TokenStreamFlags {