Bug 819509 - Remove old strict mode code and simplify. r=njn

--HG--
extra : rebase_source : bc45b3d5c6229042512a8079ec9941e86df8a4c5
This commit is contained in:
Benjamin Peterson 2012-12-12 01:35:17 -05:00
parent dc2fde2fc6
commit 9b616ed08e
5 changed files with 20 additions and 98 deletions

View File

@ -41,7 +41,6 @@ ParseContext::ParseContext(Parser *prs, SharedContext *sc, unsigned staticLevel,
args_(prs->context),
vars_(prs->context),
yieldNode(NULL),
queuedStrictModeError(NULL),
parserPC(&prs->pc),
lexdeps(prs->context),
parent(prs->pc),
@ -65,13 +64,6 @@ ParseContext::init()
return decls_.init() && lexdeps.ensureMap(sc->context);
}
inline void
ParseContext::setQueuedStrictModeError(CompileError *e)
{
JS_ASSERT(!queuedStrictModeError);
queuedStrictModeError = e;
}
inline
ParseContext::~ParseContext()
{

View File

@ -85,18 +85,6 @@ StrictModeGetter::get() const
return parser->pc->sc->strictMode;
}
CompileError *
StrictModeGetter::queuedStrictModeError() const
{
return parser->pc->queuedStrictModeError;
}
void
StrictModeGetter::setQueuedStrictModeError(CompileError *e)
{
parser->pc->setQueuedStrictModeError(e);
}
bool
frontend::GenerateBlockId(ParseContext *pc, uint32_t &blockid)
{
@ -3512,10 +3500,8 @@ Parser::withStatement()
// reportStrictModeError. However, 'with' is the sole instance of a
// construct that is forbidden in strict mode code, but doesn't even merit a
// warning under JSOPTION_STRICT. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=514576#c1. The actual
// supression of the with code warning is in
// TokenStream::reportCompileErrorNumberVA.
if (!reportStrictModeError(NULL, JSMSG_STRICT_CODE_WITH))
// https://bugzilla.mozilla.org/show_bug.cgi?id=514576#c1.
if (pc->sc->strictMode && !reportStrictModeError(NULL, JSMSG_STRICT_CODE_WITH))
return NULL;
ParseNode *pn = BinaryNode::create(PNK_WITH, this);

View File

@ -155,11 +155,6 @@ struct ParseContext /* tree context for semantic checks */
be an error if we turn out to be inside a
generator expression */
// A strict mode error found in this scope or one of its children. It is
// used only when strictModeState is UNKNOWN. If the scope turns out to be
// strict and this is non-null, it is thrown.
CompileError *queuedStrictModeError;
private:
ParseContext **parserPC; /* this points to the Parser's active pc
and holds either |this| or one of
@ -208,8 +203,6 @@ struct ParseContext /* tree context for semantic checks */
inline bool init();
inline void setQueuedStrictModeError(CompileError *e);
unsigned blockid();
// True if we are at the topmost level of a entire script or function body.

View File

@ -498,34 +498,27 @@ bool
TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned errorNumber,
va_list args)
{
bool strict = JSREPORT_IS_STRICT(flags);
bool warning = JSREPORT_IS_WARNING(flags);
// Avoid reporting JSMSG_STRICT_CODE_WITH as a warning. See the comment in
// Parser::withStatement.
if (strict && warning && (!cx->hasStrictOption() || errorNumber == JSMSG_STRICT_CODE_WITH))
return true;
if (warning && cx->hasWErrorOption()) {
flags &= ~JSREPORT_WARNING;
warning = false;
}
CompileError normalError(cx);
CompileError *err = &normalError;
CompileError err(cx);
const TokenPos *const tp = pn ? &pn->pn_pos : &currentToken().pos;
err->report.flags = flags;
err->report.errorNumber = errorNumber;
err->report.filename = filename;
err->report.originPrincipals = originPrincipals;
err->report.lineno = tp->begin.lineno;
err.report.flags = flags;
err.report.errorNumber = errorNumber;
err.report.filename = filename;
err.report.originPrincipals = originPrincipals;
err.report.lineno = tp->begin.lineno;
err->hasCharArgs = !(flags & JSREPORT_UC);
err.hasCharArgs = !(flags & JSREPORT_UC);
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, errorNumber, &err->message, &err->report,
err->hasCharArgs, args)) {
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, errorNumber, &err.message, &err.report,
err.hasCharArgs, args)) {
return false;
}
@ -539,7 +532,7 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned
* means that any error involving a multi-line token (eg. an unterminated
* multi-line string literal) won't have a context printed.
*/
if (err->report.lineno == lineno) {
if (err.report.lineno == lineno) {
const jschar *tokptr = linebase + tp->begin.index;
// We show only a portion (a "window") of the line around the erroneous
@ -568,23 +561,20 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned
// Unicode and char versions of the window into the offending source
// line, without final \n.
err->report.uclinebuf = windowBuf.extractWellSized();
if (!err->report.uclinebuf)
err.report.uclinebuf = windowBuf.extractWellSized();
if (!err.report.uclinebuf)
return false;
err->report.linebuf = DeflateString(cx, err->report.uclinebuf, windowLength);
if (!err->report.linebuf)
err.report.linebuf = DeflateString(cx, err.report.uclinebuf, windowLength);
if (!err.report.linebuf)
return false;
// The lineno check above means we should only see single-line tokens here.
JS_ASSERT(tp->begin.lineno == tp->end.lineno);
err->report.tokenptr = err->report.linebuf + windowIndex;
err->report.uctokenptr = err->report.uclinebuf + windowIndex;
err.report.tokenptr = err.report.linebuf + windowIndex;
err.report.uctokenptr = err.report.uclinebuf + windowIndex;
}
if (err == &normalError)
err->throwError();
else
return true;
err.throwError();
return warning;
}

View File

@ -181,41 +181,6 @@ TokenKindIsAssignment(TokenKind tt)
return TOK_ASSIGNMENT_START <= tt && tt <= TOK_ASSIGNMENT_LAST;
}
inline bool
TokenContinuesStringExpression(TokenKind tt)
{
switch (tt) {
// comma expression
case TOK_COMMA:
// conditional expression
case TOK_HOOK:
// binary expression
case TOK_OR:
case TOK_AND:
case TOK_BITOR:
case TOK_BITXOR:
case TOK_BITAND:
case TOK_PLUS:
case TOK_MINUS:
case TOK_STAR:
case TOK_DIV:
case TOK_MOD:
case TOK_IN:
case TOK_INSTANCEOF:
// member expression
case TOK_DOT:
case TOK_LB:
case TOK_LP:
case TOK_DBLDOT:
return true;
default:
return TokenKindIsEquality(tt) ||
TokenKindIsRelational(tt) ||
TokenKindIsShift(tt) ||
TokenKindIsAssignment(tt);
}
}
inline bool
TokenKindIsDecl(TokenKind tt)
{
@ -477,9 +442,7 @@ StrictModeFromContext(JSContext *cx)
//
// This class is a tiny back-channel from TokenStream to the strict mode flag
// that avoids exposing the rest of SharedContext to TokenStream. get()
// returns the current strict mode state. The other two methods get and set
// the queuedStrictModeError member of ParseContext. StrictModeGetter's
// non-inline methods are implemented in Parser.cpp.
// returns the current strictness.
//
class StrictModeGetter {
Parser *parser;
@ -487,8 +450,6 @@ class StrictModeGetter {
StrictModeGetter(Parser *p) : parser(p) { }
bool get() const;
CompileError *queuedStrictModeError() const;
void setQueuedStrictModeError(CompileError *e);
};
class TokenStream