Bug 754739 - Clean up front-end error reporting. r=jwalden.

This commit is contained in:
Nicholas Nethercote 2012-06-24 22:50:21 -07:00
parent 796438f7d9
commit 4c43234dda
12 changed files with 326 additions and 314 deletions

View File

@ -212,7 +212,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
* https://bugzilla.mozilla.org/show_bug.cgi?id=336551
*/
if (pn && onlyXML && !callerFrame) {
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_XML_WHOLE_PROGRAM);
parser.reportError(NULL, JSMSG_XML_WHOLE_PROGRAM);
return NULL;
}
#endif
@ -222,7 +222,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
PropertyName *arguments = cx->runtime->atomState.argumentsAtom;
for (AtomDefnRange r = tc.lexdeps->all(); !r.empty(); r.popFront()) {
if (r.front().key() == arguments) {
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_ARGUMENTS_AND_REST);
parser.reportError(NULL, JSMSG_ARGUMENTS_AND_REST);
return NULL;
}
}
@ -327,7 +327,7 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
return false;
if (!parser.tokenStream.matchToken(TOK_EOF)) {
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
parser.reportError(NULL, JSMSG_SYNTAX_ERROR);
return false;
}

View File

@ -975,8 +975,7 @@ AdjustBlockSlot(JSContext *cx, BytecodeEmitter *bce, int slot)
if (bce->sc->inFunction()) {
slot += bce->sc->bindings.numVars();
if ((unsigned) slot >= SLOTNO_LIMIT) {
ReportCompileErrorNumber(cx, bce->tokenStream(), NULL, JSREPORT_ERROR,
JSMSG_TOO_MANY_LOCALS);
bce->reportError(NULL, JSMSG_TOO_MANY_LOCALS);
slot = -1;
}
}
@ -1179,7 +1178,7 @@ BindNameToSlot(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
if (bce->sc->needStrictChecks()) {
JSAutoByteString name;
if (!js_AtomToPrintableString(cx, atom, &name) ||
!ReportStrictModeError(cx, bce->tokenStream(), pn, JSMSG_READ_ONLY, name.ptr()))
!bce->reportStrictModeError(pn, JSMSG_READ_ONLY, name.ptr()))
{
return false;
}
@ -1564,6 +1563,37 @@ BytecodeEmitter::needsImplicitThis()
return false;
}
bool
BytecodeEmitter::reportError(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream()->reportCompileErrorNumberVA(pn, JSREPORT_ERROR, errorNumber, args);
va_end(args);
return result;
}
bool
BytecodeEmitter::reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream()->reportCompileErrorNumberVA(pn, JSREPORT_STRICT | JSREPORT_WARNING,
errorNumber, args);
va_end(args);
return result;
}
bool
BytecodeEmitter::reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream()->reportStrictModeErrorNumberVA(pn, errorNumber, args);
va_end(args);
return result;
}
static JSBool
EmitNameOp(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool callContext)
{
@ -2854,8 +2884,7 @@ EmitDestructuringOpsHelper(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn,
unsigned pickDistance = (unsigned)((bce->stackDepth + 1) - depthBefore);
if (pickDistance > 0) {
if (pickDistance > UINT8_MAX) {
ReportCompileErrorNumber(cx, bce->tokenStream(), pn3, JSREPORT_ERROR,
JSMSG_TOO_MANY_LOCALS);
bce->reportError(pn3, JSMSG_TOO_MANY_LOCALS);
return JS_FALSE;
}
if (Emit2(cx, bce, JSOP_PICK, (jsbytecode)pickDistance) < 0)
@ -2996,8 +3025,7 @@ EmitGroupAssignment(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp,
depth = limit = (unsigned) bce->stackDepth;
for (pn = rhs->pn_head; pn; pn = pn->pn_next) {
if (limit == JS_BIT(16)) {
ReportCompileErrorNumber(cx, bce->tokenStream(), rhs, JSREPORT_ERROR,
JSMSG_ARRAY_INIT_TOO_BIG);
bce->reportError(rhs, JSMSG_ARRAY_INIT_TOO_BIG);
return JS_FALSE;
}
@ -3491,8 +3519,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par
case PNK_NAME:
if (lhs->isConst()) {
if (!rhs) {
ReportCompileErrorNumber(cx, bce->tokenStream(), lhs, JSREPORT_ERROR,
JSMSG_BAD_FOR_LEFTSIDE);
bce->reportError(lhs, JSMSG_BAD_FOR_LEFTSIDE);
return false;
}
break;
@ -5104,11 +5131,8 @@ EmitStatement(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
} else if (!pn->isDirectivePrologueMember()) {
/* Don't complain about directive prologue members; just don't emit their code. */
bce->current->currentLine = pn2->pn_pos.begin.lineno;
if (!ReportCompileErrorNumber(cx, bce->tokenStream(), pn2,
JSREPORT_WARNING | JSREPORT_STRICT, JSMSG_USELESS_EXPR))
{
if (!bce->reportStrictWarning(pn2, JSMSG_USELESS_EXPR))
return false;
}
}
return true;
@ -5545,8 +5569,7 @@ EmitObject(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
{
#if JS_HAS_DESTRUCTURING_SHORTHAND
if (pn->pn_xflags & PNX_DESTRUCT) {
ReportCompileErrorNumber(cx, bce->tokenStream(), pn, JSREPORT_ERROR,
JSMSG_BAD_OBJECT_INIT);
bce->reportError(pn, JSMSG_BAD_OBJECT_INIT);
return false;
}
#endif

View File

@ -188,6 +188,10 @@ struct BytecodeEmitter
unsigned currentLine() const { return current->currentLine; }
inline ptrdiff_t countFinalSourceNotes();
bool reportError(ParseNode *pn, unsigned errorNumber, ...);
bool reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...);
bool reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...);
};
namespace frontend {

View File

@ -70,7 +70,7 @@ using namespace js::frontend;
#define MUST_MATCH_TOKEN_WITH_FLAGS(tt, errno, __flags) \
JS_BEGIN_MACRO \
if (tokenStream.getToken((__flags)) != tt) { \
reportErrorNumber(NULL, JSREPORT_ERROR, errno); \
reportError(NULL, errno); \
return NULL; \
} \
JS_END_MACRO
@ -255,7 +255,7 @@ Parser::parse(JSObject *chain)
ParseNode *pn = statements();
if (pn) {
if (!tokenStream.matchToken(TOK_EOF)) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
pn = NULL;
} else if (foldConstants) {
if (!FoldConstants(context, pn, this))
@ -391,8 +391,8 @@ HasFinalReturn(ParseNode *pn)
}
static JSBool
ReportBadReturn(JSContext *cx, Parser *parser, ParseNode *pn, unsigned flags, unsigned errnum,
unsigned anonerrnum)
ReportBadReturn(JSContext *cx, Parser *parser, ParseNode *pn, Parser::Reporter reporter,
unsigned errnum, unsigned anonerrnum)
{
JSAutoByteString name;
if (parser->tc->sc->fun()->atom) {
@ -401,7 +401,7 @@ ReportBadReturn(JSContext *cx, Parser *parser, ParseNode *pn, unsigned flags, un
} else {
errnum = anonerrnum;
}
return ReportCompileErrorNumber(cx, TS(parser), pn, flags, errnum, name.ptr());
return (parser->*reporter)(pn, errnum, name.ptr());
}
static JSBool
@ -409,7 +409,7 @@ CheckFinalReturn(JSContext *cx, Parser *parser, ParseNode *pn)
{
JS_ASSERT(parser->tc->sc->inFunction());
return HasFinalReturn(pn) == ENDS_IN_RETURN ||
ReportBadReturn(cx, parser, pn, JSREPORT_WARNING | JSREPORT_STRICT,
ReportBadReturn(cx, parser, pn, &Parser::reportStrictWarning,
JSMSG_NO_RETURN_VALUE, JSMSG_ANON_NO_RETURN_VALUE);
}
@ -426,7 +426,7 @@ CheckStrictAssignment(JSContext *cx, Parser *parser, ParseNode *lhs)
if (atom == atomState->evalAtom || atom == atomState->argumentsAtom) {
JSAutoByteString name;
if (!js_AtomToPrintableString(cx, atom, &name) ||
!ReportStrictModeError(cx, TS(parser), lhs, JSMSG_DEPRECATED_ASSIGN, name.ptr()))
!parser->reportStrictModeError(lhs, JSMSG_DEPRECATED_ASSIGN, name.ptr()))
{
return false;
}
@ -455,7 +455,7 @@ CheckStrictBinding(JSContext *cx, Parser *parser, PropertyName *name, ParseNode
JSAutoByteString bytes;
if (!js_AtomToPrintableString(cx, name, &bytes))
return false;
return ReportStrictModeError(cx, TS(parser), pn, JSMSG_BAD_BINDING, bytes.ptr());
return parser->reportStrictModeError(pn, JSMSG_BAD_BINDING, bytes.ptr());
}
return true;
@ -467,7 +467,7 @@ ReportBadParameter(JSContext *cx, Parser *parser, JSAtom *name, unsigned errorNu
Definition *dn = parser->tc->decls.lookupFirst(name);
JSAutoByteString bytes;
return js_AtomToPrintableString(cx, name, &bytes) &&
ReportStrictModeError(cx, TS(parser), dn, errorNumber, bytes.ptr());
parser->reportStrictModeError(dn, errorNumber, bytes.ptr());
}
/*
@ -572,7 +572,7 @@ Parser::functionBody(FunctionBodyType type)
pn = NULL;
} else {
if (tc->sc->funIsGenerator()) {
ReportBadReturn(context, this, pn, JSREPORT_ERROR,
ReportBadReturn(context, this, pn, &Parser::reportError,
JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
pn = NULL;
@ -669,7 +669,7 @@ Parser::functionBody(FunctionBodyType type)
case VARIABLE:
case CONSTANT:
if (hasRest) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_ARGUMENTS_AND_REST);
reportError(NULL, JSMSG_ARGUMENTS_AND_REST);
return NULL;
}
@ -960,8 +960,7 @@ BindDestructuringArg(JSContext *cx, BindData *data, JSAtom *atom, Parser *parser
* been parsed.
*/
if (tc->decls.lookupFirst(atom)) {
ReportCompileErrorNumber(cx, TS(parser), NULL, JSREPORT_ERROR,
JSMSG_DESTRUCT_DUP_ARG);
parser->reportError(NULL, JSMSG_DESTRUCT_DUP_ARG);
return JS_FALSE;
}
@ -1033,7 +1032,7 @@ MatchOrInsertSemicolon(JSContext *cx, TokenStream *ts)
if (tt != TOK_EOF && tt != TOK_EOL && tt != TOK_SEMI && tt != TOK_RC) {
/* Advance the scanner for proper error location reporting. */
ts->getToken(TSF_OPERAND);
ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR, JSMSG_SEMI_BEFORE_STMNT);
ts->reportError(JSMSG_SEMI_BEFORE_STMNT);
return JS_FALSE;
}
(void) ts->matchToken(TOK_SEMI);
@ -1227,7 +1226,7 @@ bool
Parser::functionArguments(ParseNode **listp, bool &hasRest)
{
if (tokenStream.getToken() != TOK_LP) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_PAREN_BEFORE_FORMAL);
reportError(NULL, JSMSG_PAREN_BEFORE_FORMAL);
return false;
}
@ -1250,7 +1249,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
do {
if (hasRest) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_PARAMETER_AFTER_REST);
reportError(NULL, JSMSG_PARAMETER_AFTER_REST);
return false;
}
switch (TokenKind tt = tokenStream.getToken()) {
@ -1262,7 +1261,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
if (duplicatedArg)
goto report_dup_and_destructuring;
if (hasDefaults) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT);
reportError(NULL, JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT);
return false;
}
@ -1326,7 +1325,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
tt = tokenStream.getToken();
if (tt != TOK_NAME) {
if (tt != TOK_ERROR)
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NO_REST_NAME);
reportError(NULL, JSMSG_NO_REST_NAME);
return false;
}
/* Fall through */
@ -1369,7 +1368,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
if (tokenStream.matchToken(TOK_ASSIGN)) {
if (hasRest) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_REST_WITH_DEFAULT);
reportError(NULL, JSMSG_REST_WITH_DEFAULT);
return false;
}
hasDefaults = true;
@ -1381,7 +1380,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
arg->pn_expr = def_expr;
tc->sc->funbox()->ndefaults++;
} else if (!hasRest && hasDefaults) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT);
reportError(NULL, JSMSG_NONDEFAULT_FORMAL_AFTER_DEFAULT);
return false;
}
@ -1389,7 +1388,7 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
}
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_MISSING_FORMAL);
reportError(NULL, JSMSG_MISSING_FORMAL);
/* FALL THROUGH */
case TOK_ERROR:
return false;
@ -1397,14 +1396,14 @@ Parser::functionArguments(ParseNode **listp, bool &hasRest)
#if JS_HAS_DESTRUCTURING
report_dup_and_destructuring:
Definition *dn = tc->decls.lookupFirst(duplicatedArg);
reportErrorNumber(dn, JSREPORT_ERROR, JSMSG_DESTRUCT_DUP_ARG);
reportError(dn, JSMSG_DESTRUCT_DUP_ARG);
return false;
#endif
}
} while (tokenStream.matchToken(TOK_COMMA));
if (tokenStream.getToken() != TOK_RP) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_PAREN_AFTER_FORMAL);
reportError(NULL, JSMSG_PAREN_AFTER_FORMAL);
return false;
}
}
@ -1439,14 +1438,13 @@ Parser::functionDef(HandlePropertyName funName, FunctionType type, FunctionSynta
if (context->hasStrictOption() || dn_kind == Definition::CONST) {
JSAutoByteString name;
Reporter reporter = (dn_kind != Definition::CONST)
? &Parser::reportStrictWarning
: &Parser::reportError;
if (!js_AtomToPrintableString(context, funName, &name) ||
!reportErrorNumber(NULL,
(dn_kind != Definition::CONST)
? JSREPORT_WARNING | JSREPORT_STRICT
: JSREPORT_ERROR,
JSMSG_REDECLARED_VAR,
Definition::kindString(dn_kind),
name.ptr())) {
!(this->*reporter)(NULL, JSMSG_REDECLARED_VAR, Definition::kindString(dn_kind),
name.ptr()))
{
return NULL;
}
}
@ -1584,13 +1582,11 @@ Parser::functionDef(HandlePropertyName funName, FunctionType type, FunctionSynta
#endif
if (type == Getter && fun->nargs > 0) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_ACCESSOR_WRONG_ARGS,
"getter", "no", "s");
reportError(NULL, JSMSG_ACCESSOR_WRONG_ARGS, "getter", "no", "s");
return NULL;
}
if (type == Setter && fun->nargs != 1) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_ACCESSOR_WRONG_ARGS,
"setter", "one", "");
reportError(NULL, JSMSG_ACCESSOR_WRONG_ARGS, "setter", "one", "");
return NULL;
}
@ -1736,13 +1732,13 @@ Parser::functionStmt()
name = tokenStream.currentToken().name();
} else {
/* Unnamed function expressions are forbidden in statement context. */
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_UNNAMED_FUNCTION_STMT);
reportError(NULL, JSMSG_UNNAMED_FUNCTION_STMT);
return NULL;
}
/* We forbid function statements in strict mode code. */
if (!tc->sc->atBodyLevel() && tc->sc->inStrictMode()) {
reportErrorNumber(NULL, JSREPORT_STRICT_MODE_ERROR, JSMSG_STRICT_FUNCTION_STATEMENT);
reportStrictModeError(NULL, JSMSG_STRICT_FUNCTION_STATEMENT);
return NULL;
}
@ -1819,7 +1815,7 @@ Parser::recognizeDirectivePrologue(ParseNode *pn, bool *isDirectivePrologueMembe
* }
*/
if (tokenStream.hasOctalCharacterEscape()) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_DEPRECATED_OCTAL);
reportError(NULL, JSMSG_DEPRECATED_OCTAL);
return false;
}
@ -1923,7 +1919,7 @@ Parser::condition()
JS_ASSERT_IF(pn->isKind(PNK_ASSIGN), pn->isOp(JSOP_NOP));
if (pn->isKind(PNK_ASSIGN) &&
!pn->isInParens() &&
!reportErrorNumber(NULL, JSREPORT_WARNING | JSREPORT_STRICT, JSMSG_EQUAL_AS_ASSIGN))
!reportStrictWarning(NULL, JSMSG_EQUAL_AS_ASSIGN))
{
return NULL;
}
@ -1949,12 +1945,8 @@ static bool
ReportRedeclaration(JSContext *cx, Parser *parser, ParseNode *pn, bool isConst, JSAtom *atom)
{
JSAutoByteString name;
if (js_AtomToPrintableString(cx, atom, &name)) {
ReportCompileErrorNumber(cx, TS(parser), pn,
JSREPORT_ERROR, JSMSG_REDECLARED_VAR,
isConst ? "const" : "variable",
name.ptr());
}
if (js_AtomToPrintableString(cx, atom, &name))
parser->reportError(pn, JSMSG_REDECLARED_VAR, isConst ? "const" : "variable", name.ptr());
return false;
}
@ -1978,8 +1970,7 @@ BindLet(JSContext *cx, BindData *data, JSAtom *atom, Parser *parser)
Rooted<StaticBlockObject *> blockObj(cx, data->let.blockObj);
unsigned blockCount = blockObj->slotCount();
if (blockCount == JS_BIT(16)) {
ReportCompileErrorNumber(cx, TS(parser), pn,
JSREPORT_ERROR, data->let.overflow);
parser->reportError(pn, data->let.overflow);
return false;
}
@ -2143,16 +2134,11 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, Parser *parser)
return JS_FALSE;
if (op == JSOP_DEFCONST) {
ReportCompileErrorNumber(cx, TS(parser), pn,
JSREPORT_ERROR, JSMSG_REDECLARED_PARAM,
name.ptr());
parser->reportError(pn, JSMSG_REDECLARED_PARAM, name.ptr());
return JS_FALSE;
}
if (!ReportCompileErrorNumber(cx, TS(parser), pn,
JSREPORT_WARNING | JSREPORT_STRICT,
JSMSG_VAR_HIDES_ARG, name.ptr())) {
if (!parser->reportStrictWarning(pn, JSMSG_VAR_HIDES_ARG, name.ptr()))
return JS_FALSE;
}
} else {
bool error = (op == JSOP_DEFCONST ||
dn_kind == Definition::CONST ||
@ -2161,16 +2147,15 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, Parser *parser)
if (cx->hasStrictOption()
? op != JSOP_DEFVAR || dn_kind != Definition::VAR
: error) {
: error)
{
JSAutoByteString name;
Parser::Reporter reporter =
error ? &Parser::reportError : &Parser::reportStrictWarning;
if (!js_AtomToPrintableString(cx, atom, &name) ||
!ReportCompileErrorNumber(cx, TS(parser), pn,
!error
? JSREPORT_WARNING | JSREPORT_STRICT
: JSREPORT_ERROR,
JSMSG_REDECLARED_VAR,
Definition::kindString(dn_kind),
name.ptr())) {
!(parser->*reporter)(pn, JSMSG_REDECLARED_VAR,
Definition::kindString(dn_kind), name.ptr()))
{
return JS_FALSE;
}
}
@ -2265,12 +2250,12 @@ MakeSetCall(JSContext *cx, ParseNode *pn, Parser *parser, unsigned msg)
JS_ASSERT(pn->isArity(PN_LIST));
JS_ASSERT(pn->isOp(JSOP_CALL) || pn->isOp(JSOP_EVAL) ||
pn->isOp(JSOP_FUNCALL) || pn->isOp(JSOP_FUNAPPLY));
if (!ReportStrictModeError(cx, TS(parser), pn, msg))
if (!parser->reportStrictModeError(pn, msg))
return false;
ParseNode *pn2 = pn->pn_head;
if (pn2->isKind(PNK_FUNCTION) && (pn2->pn_funbox->inGenexpLambda)) {
ReportCompileErrorNumber(cx, TS(parser), pn, JSREPORT_ERROR, msg);
parser->reportError(pn, msg);
return false;
}
pn->pn_xflags |= PNX_SETCALL;
@ -2430,8 +2415,7 @@ BindDestructuringLHS(JSContext *cx, ParseNode *pn, Parser *parser)
#endif
default:
ReportCompileErrorNumber(cx, TS(parser), pn,
JSREPORT_ERROR, JSMSG_BAD_LEFTSIDE_OF_ASS);
parser->reportError(pn, JSMSG_BAD_LEFTSIDE_OF_ASS);
return JS_FALSE;
}
@ -2488,8 +2472,7 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, Parser *parse
bool ok;
if (left->isKind(PNK_ARRAYCOMP)) {
ReportCompileErrorNumber(cx, TS(parser), left, JSREPORT_ERROR,
JSMSG_ARRAY_COMP_LEFTSIDE);
parser->reportError(left, JSMSG_ARRAY_COMP_LEFTSIDE);
return false;
}
@ -2506,8 +2489,7 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, Parser *parse
} else {
if (data) {
if (!pn->isKind(PNK_NAME)) {
ReportCompileErrorNumber(cx, TS(parser), pn, JSREPORT_ERROR,
JSMSG_NO_VARIABLE_NAME);
parser->reportError(pn, JSMSG_NO_VARIABLE_NAME);
return false;
}
ok = BindDestructuringVar(cx, data, pn, parser);
@ -2529,8 +2511,7 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, Parser *parse
ok = CheckDestructuring(cx, data, pn, parser, false);
} else if (data) {
if (!pn->isKind(PNK_NAME)) {
ReportCompileErrorNumber(cx, TS(parser), pn, JSREPORT_ERROR,
JSMSG_NO_VARIABLE_NAME);
parser->reportError(pn, JSMSG_NO_VARIABLE_NAME);
return false;
}
ok = BindDestructuringVar(cx, data, pn, parser);
@ -2646,8 +2627,8 @@ Parser::returnOrYield(bool useAssignExpr)
{
TokenKind tt = tokenStream.currentToken().type;
if (!tc->sc->inFunction()) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_RETURN_OR_YIELD,
(tt == TOK_RETURN) ? js_return_str : js_yield_str);
reportError(NULL, JSMSG_BAD_RETURN_OR_YIELD,
(tt == TOK_RETURN) ? js_return_str : js_yield_str);
return NULL;
}
@ -2701,16 +2682,15 @@ Parser::returnOrYield(bool useAssignExpr)
if (tc->hasReturnExpr && tc->sc->funIsGenerator()) {
/* As in Python (see PEP-255), disallow return v; in generators. */
ReportBadReturn(context, this, pn, JSREPORT_ERROR,
JSMSG_BAD_GENERATOR_RETURN,
ReportBadReturn(context, this, pn, &Parser::reportError, JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
return NULL;
}
if (context->hasStrictOption() && tc->hasReturnExpr && tc->hasReturnVoid &&
!ReportBadReturn(context, this, pn, JSREPORT_WARNING | JSREPORT_STRICT,
JSMSG_NO_RETURN_VALUE,
JSMSG_ANON_NO_RETURN_VALUE)) {
!ReportBadReturn(context, this, pn, &Parser::reportStrictWarning,
JSMSG_NO_RETURN_VALUE, JSMSG_ANON_NO_RETURN_VALUE))
{
return NULL;
}
@ -2826,7 +2806,7 @@ Parser::letBlock(LetContext letContext)
*
* See bug 569464.
*/
if (!ReportStrictModeError(context, &tokenStream, pnlet, JSMSG_STRICT_CODE_LET_EXPR_STMT))
if (!reportStrictModeError(pnlet, JSMSG_STRICT_CODE_LET_EXPR_STMT))
return NULL;
/*
@ -2963,7 +2943,7 @@ Parser::switchStatement()
switch (tt) {
case TOK_DEFAULT:
if (seenDefault) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_DEFAULTS);
reportError(NULL, JSMSG_TOO_MANY_DEFAULTS);
return NULL;
}
seenDefault = true;
@ -2987,13 +2967,13 @@ Parser::switchStatement()
return NULL;
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_SWITCH);
reportError(NULL, JSMSG_BAD_SWITCH);
return NULL;
}
pn2->append(pn3);
if (pn2->pn_count == JS_BIT(16)) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_CASES);
reportError(NULL, JSMSG_TOO_MANY_CASES);
return NULL;
}
@ -3095,7 +3075,7 @@ Parser::forStatement()
TokenKind tt = tokenStream.peekToken(TSF_OPERAND);
if (tt == TOK_SEMI) {
if (pn->pn_iflags & JSITER_FOREACH) {
reportErrorNumber(pn, JSREPORT_ERROR, JSMSG_BAD_FOR_EACH_LOOP);
reportError(pn, JSMSG_BAD_FOR_EACH_LOOP);
return NULL;
}
@ -3175,7 +3155,7 @@ Parser::forStatement()
/* Set pn_iflags and rule out invalid combinations. */
if (forOf && pn->pn_iflags != 0) {
JS_ASSERT(pn->pn_iflags == JSITER_FOREACH);
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_FOR_EACH_LOOP);
reportError(NULL, JSMSG_BAD_FOR_EACH_LOOP);
return NULL;
}
pn->pn_iflags |= (forOf ? JSITER_FOR_OF : JSITER_ENUMERATE);
@ -3210,7 +3190,7 @@ Parser::forStatement()
#endif
!pn1->isKind(PNK_LB)))
{
reportErrorNumber(pn1, JSREPORT_ERROR, JSMSG_BAD_FOR_LEFTSIDE);
reportError(pn1, JSMSG_BAD_FOR_LEFTSIDE);
return NULL;
}
@ -3242,7 +3222,7 @@ Parser::forStatement()
*/
#if JS_HAS_BLOCK_SCOPE
if (blockObj) {
reportErrorNumber(pn2, JSREPORT_ERROR, JSMSG_INVALID_FOR_IN_INIT);
reportError(pn2, JSMSG_INVALID_FOR_IN_INIT);
return NULL;
}
#endif /* JS_HAS_BLOCK_SCOPE */
@ -3369,7 +3349,7 @@ Parser::forStatement()
}
if (pn->pn_iflags & JSITER_FOREACH) {
reportErrorNumber(pn, JSREPORT_ERROR, JSMSG_BAD_FOR_EACH_LOOP);
reportError(pn, JSMSG_BAD_FOR_EACH_LOOP);
return NULL;
}
pn->setOp(JSOP_NOP);
@ -3483,7 +3463,7 @@ Parser::tryStatement()
/* Check for another catch after unconditional catch. */
if (lastCatch && !lastCatch->pn_kid2) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_CATCH_AFTER_GENERAL);
reportError(NULL, JSMSG_CATCH_AFTER_GENERAL);
return NULL;
}
@ -3542,7 +3522,7 @@ Parser::tryStatement()
}
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_CATCH_IDENTIFIER);
reportError(NULL, JSMSG_CATCH_IDENTIFIER);
return NULL;
}
@ -3588,7 +3568,7 @@ Parser::tryStatement()
tokenStream.ungetToken();
}
if (!catchList && !pn->pn_kid3) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_CATCH_OR_FINALLY);
reportError(NULL, JSMSG_CATCH_OR_FINALLY);
return NULL;
}
return pn;
@ -3602,13 +3582,13 @@ Parser::withStatement()
/*
* In most cases, we want the constructs forbidden in strict mode
* code to be a subset of those that JSOPTION_STRICT warns about, and
* we should use ReportStrictModeError. However, 'with' is the sole
* we should use 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.
*/
if (tc->sc->inStrictMode()) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_STRICT_CODE_WITH);
reportError(NULL, JSMSG_STRICT_CODE_WITH);
return NULL;
}
@ -3687,7 +3667,7 @@ Parser::letStatement()
StmtInfo *stmt = tc->sc->topStmt;
if (stmt &&
(!STMT_MAYBE_SCOPE(stmt) || (stmt->flags & SIF_FOR_BLOCK))) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_LET_DECL_NOT_IN_BLOCK);
reportError(NULL, JSMSG_LET_DECL_NOT_IN_BLOCK);
return NULL;
}
@ -3781,13 +3761,13 @@ Parser::expressionStatement()
if (tokenStream.peekToken() == TOK_COLON) {
if (!pn2->isKind(PNK_NAME)) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_LABEL);
reportError(NULL, JSMSG_BAD_LABEL);
return NULL;
}
JSAtom *label = pn2->pn_atom;
for (StmtInfo *stmt = tc->sc->topStmt; stmt; stmt = stmt->down) {
if (stmt->type == STMT_LABEL && stmt->label == label) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_DUPLICATE_LABEL);
reportError(NULL, JSMSG_DUPLICATE_LABEL);
return NULL;
}
}
@ -3866,7 +3846,7 @@ Parser::statement()
if (pn2->isKind(PNK_SEMI) &&
!pn2->pn_kid &&
!reportErrorNumber(NULL, JSREPORT_WARNING | JSREPORT_STRICT, JSMSG_EMPTY_CONSEQUENT))
!reportStrictWarning(NULL, JSMSG_EMPTY_CONSEQUENT))
{
return NULL;
}
@ -3959,7 +3939,7 @@ Parser::statement()
if (tt == TOK_ERROR)
return NULL;
if (tt == TOK_EOF || tt == TOK_EOL || tt == TOK_SEMI || tt == TOK_RC) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;
}
@ -3974,11 +3954,11 @@ Parser::statement()
/* TOK_CATCH and TOK_FINALLY are both handled in the TOK_TRY case */
case TOK_CATCH:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_CATCH_WITHOUT_TRY);
reportError(NULL, JSMSG_CATCH_WITHOUT_TRY);
return NULL;
case TOK_FINALLY:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_FINALLY_WITHOUT_TRY);
reportError(NULL, JSMSG_FINALLY_WITHOUT_TRY);
return NULL;
case TOK_BREAK:
@ -3995,7 +3975,7 @@ Parser::statement()
if (label) {
for (; ; stmt = stmt->down) {
if (!stmt) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_LABEL_NOT_FOUND);
reportError(NULL, JSMSG_LABEL_NOT_FOUND);
return NULL;
}
if (stmt->type == STMT_LABEL && stmt->label == label)
@ -4004,7 +3984,7 @@ Parser::statement()
} else {
for (; ; stmt = stmt->down) {
if (!stmt) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOUGH_BREAK);
reportError(NULL, JSMSG_TOUGH_BREAK);
return NULL;
}
if (STMT_IS_LOOP(stmt) || stmt->type == STMT_SWITCH)
@ -4028,13 +4008,13 @@ Parser::statement()
if (label) {
for (StmtInfo *stmt2 = NULL; ; stmt = stmt->down) {
if (!stmt) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_LABEL_NOT_FOUND);
reportError(NULL, JSMSG_LABEL_NOT_FOUND);
return NULL;
}
if (stmt->type == STMT_LABEL) {
if (stmt->label == label) {
if (!stmt2 || !STMT_IS_LOOP(stmt2)) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_CONTINUE);
reportError(NULL, JSMSG_BAD_CONTINUE);
return NULL;
}
break;
@ -4046,7 +4026,7 @@ Parser::statement()
} else {
for (; ; stmt = stmt->down) {
if (!stmt) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_CONTINUE);
reportError(NULL, JSMSG_BAD_CONTINUE);
return NULL;
}
if (STMT_IS_LOOP(stmt))
@ -4140,7 +4120,7 @@ Parser::statement()
tokenStream.currentToken().name() != context->runtime->atomState.namespaceAtom ||
!tokenStream.matchToken(TOK_ASSIGN))
{
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_DEFAULT_XML_NAMESPACE);
reportError(NULL, JSMSG_BAD_DEFAULT_XML_NAMESPACE);
return NULL;
}
@ -4242,7 +4222,7 @@ Parser::variables(ParseNodeKind kind, StaticBlockObject *blockObj, VarContext va
if (tt != TOK_NAME) {
if (tt != TOK_ERROR)
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NO_VARIABLE_NAME);
reportError(NULL, JSMSG_NO_VARIABLE_NAME);
return NULL;
}
@ -4304,7 +4284,7 @@ Parser::expr()
#if JS_HAS_GENERATORS
pn2 = pn->last();
if (pn2->isKind(PNK_YIELD) && !pn2->isInParens()) {
reportErrorNumber(pn2, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str);
reportError(pn2, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str);
return NULL;
}
#endif
@ -4573,7 +4553,7 @@ Parser::setAssignmentLhsOps(ParseNode *pn, JSOp op)
case PNK_RB:
case PNK_RC:
if (op != JSOP_NOP) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_DESTRUCT_ASS);
reportError(NULL, JSMSG_BAD_DESTRUCT_ASS);
return false;
}
if (!CheckDestructuring(context, NULL, pn, this))
@ -4591,7 +4571,7 @@ Parser::setAssignmentLhsOps(ParseNode *pn, JSOp op)
break;
#endif
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_LEFTSIDE_OF_ASS);
reportError(NULL, JSMSG_BAD_LEFTSIDE_OF_ASS);
return false;
}
return true;
@ -4671,8 +4651,7 @@ SetLvalKid(JSContext *cx, Parser *parser, ParseNode *pn, ParseNode *kid,
#endif
!kid->isKind(PNK_LB))
{
ReportCompileErrorNumber(cx, &parser->tokenStream, NULL, JSREPORT_ERROR, JSMSG_BAD_OPERAND,
name);
parser->reportError(NULL, JSMSG_BAD_OPERAND, name);
return false;
}
if (!CheckStrictAssignment(cx, parser, kid))
@ -4803,10 +4782,8 @@ Parser::unaryExpr()
}
break;
case PNK_NAME:
if (!ReportStrictModeError(context, &tokenStream, pn,
JSMSG_DEPRECATED_DELETE_OPERAND)) {
if (!reportStrictModeError(pn, JSMSG_DEPRECATED_DELETE_OPERAND))
return NULL;
}
pn2->setOp(JSOP_DELNAME);
break;
default:;
@ -4941,7 +4918,7 @@ GenexpGuard::checkValidBody(ParseNode *pn, unsigned err = JSMSG_BAD_GENEXP_BODY)
ParseNode *errorNode = tc->yieldNode;
if (!errorNode)
errorNode = pn;
parser->reportErrorNumber(errorNode, JSREPORT_ERROR, err, js_yield_str);
parser->reportError(errorNode, err, js_yield_str);
return false;
}
@ -4962,15 +4939,13 @@ GenexpGuard::maybeNoteGenerator(ParseNode *pn)
if (tc->yieldCount > 0) {
tc->sc->setFunIsGenerator();
if (!tc->sc->inFunction()) {
parser->reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_RETURN_OR_YIELD,
js_yield_str);
parser->reportError(NULL, JSMSG_BAD_RETURN_OR_YIELD, js_yield_str);
return false;
}
if (tc->hasReturnExpr) {
/* At the time we saw the yield, we might not have set funIsGenerator yet. */
ReportBadReturn(tc->sc->context, parser, pn, JSREPORT_ERROR,
JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
ReportBadReturn(tc->sc->context, parser, pn, &Parser::reportError,
JSMSG_BAD_GENERATOR_RETURN, JSMSG_BAD_ANON_GENERATOR_RETURN);
return false;
}
}
@ -5291,7 +5266,7 @@ Parser::comprehensionTail(ParseNode *kid, unsigned blockid, bool isGenexp,
break;
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NO_VARIABLE_NAME);
reportError(NULL, JSMSG_NO_VARIABLE_NAME);
case TOK_ERROR:
return NULL;
@ -5299,13 +5274,13 @@ Parser::comprehensionTail(ParseNode *kid, unsigned blockid, bool isGenexp,
bool forOf;
if (!matchInOrOf(&forOf)) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_IN_AFTER_FOR_NAME);
reportError(NULL, JSMSG_IN_AFTER_FOR_NAME);
return NULL;
}
if (forOf) {
if (pn2->pn_iflags != JSITER_ENUMERATE) {
JS_ASSERT(pn2->pn_iflags == (JSITER_FOREACH | JSITER_ENUMERATE));
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_FOR_EACH_LOOP);
reportError(NULL, JSMSG_BAD_FOR_EACH_LOOP);
return NULL;
}
pn2->pn_iflags = JSITER_FOR_OF;
@ -5336,7 +5311,7 @@ Parser::comprehensionTail(ParseNode *kid, unsigned blockid, bool isGenexp,
if (versionNumber() == JSVERSION_1_7) {
/* Destructuring requires [key, value] enumeration in JS1.7. */
if (!pn3->isKind(PNK_RB) || pn3->pn_count != 2) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_FOR_LEFTSIDE);
reportError(NULL, JSMSG_BAD_FOR_LEFTSIDE);
return NULL;
}
@ -5489,7 +5464,7 @@ Parser::generatorExpr(ParseNode *kid)
if (AtomDefnPtr p = gentc.lexdeps->lookup(arguments)) {
Definition *dn = p.value();
ParseNode *errorNode = dn->dn_uses ? dn->dn_uses : body;
reportErrorNumber(errorNode, JSREPORT_ERROR, JSMSG_BAD_GENEXP_BODY, js_arguments_str);
reportError(errorNode, JSMSG_BAD_GENEXP_BODY, js_arguments_str);
return NULL;
}
@ -5554,7 +5529,7 @@ Parser::argumentList(ParseNode *listNode)
if (argNode->isKind(PNK_YIELD) &&
!argNode->isInParens() &&
tokenStream.peekToken() == TOK_COMMA) {
reportErrorNumber(argNode, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str);
reportError(argNode, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str);
return JS_FALSE;
}
#endif
@ -5567,8 +5542,7 @@ Parser::argumentList(ParseNode *listNode)
return JS_FALSE;
if (listNode->pn_count > 1 ||
tokenStream.peekToken() == TOK_COMMA) {
reportErrorNumber(argNode, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX,
js_generator_str);
reportError(argNode, JSMSG_BAD_GENERATOR_SYNTAX, js_generator_str);
return JS_FALSE;
}
} else
@ -5582,7 +5556,7 @@ Parser::argumentList(ParseNode *listNode)
} while (tokenStream.matchToken(TOK_COMMA));
if (tokenStream.getToken() != TOK_RP) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_PAREN_AFTER_ARGS);
reportError(NULL, JSMSG_PAREN_AFTER_ARGS);
return JS_FALSE;
}
return JS_TRUE;
@ -5693,20 +5667,20 @@ Parser::memberExpr(JSBool allowCallSyntax)
if (!nextMember)
return NULL;
} else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT);
reportError(NULL, JSMSG_NAME_AFTER_DOT);
return NULL;
}
}
#endif
else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT);
reportError(NULL, JSMSG_NAME_AFTER_DOT);
return NULL;
}
}
#if JS_HAS_XML_SUPPORT
else if (tt == TOK_DBLDOT) {
if (!allowsXML()) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT);
reportError(NULL, JSMSG_NAME_AFTER_DOT);
return NULL;
}
@ -5722,7 +5696,7 @@ Parser::memberExpr(JSBool allowCallSyntax)
pn3->setArity(PN_NULLARY);
pn3->setOp(JSOP_QNAMEPART);
} else if (!pn3->isXMLPropertyIdentifier()) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT);
reportError(NULL, JSMSG_NAME_AFTER_DOT);
return NULL;
}
nextMember->setOp(JSOP_DESCENDANTS);
@ -5959,7 +5933,7 @@ Parser::qualifiedSuffix(ParseNode *pn)
}
if (tt != TOK_LB) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;
}
ParseNode *pn3 = endBracketedExpr();
@ -6010,7 +5984,7 @@ Parser::attributeIdentifier()
} else if (tt == TOK_LB) {
pn2 = endBracketedExpr();
} else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;
}
if (!pn2)
@ -6180,7 +6154,7 @@ Parser::xmlTagContent(ParseNodeKind tagkind, JSAtom **namep)
pn2 = xmlExpr(JS_TRUE);
pn->pn_xflags |= PNX_CANTFOLD;
} else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_ATTR_VALUE);
reportError(NULL, JSMSG_BAD_XML_ATTR_VALUE);
return NULL;
}
if (!pn2)
@ -6196,7 +6170,7 @@ Parser::xmlTagContent(ParseNodeKind tagkind, JSAtom **namep)
JS_BEGIN_MACRO \
if ((tt) <= TOK_EOF) { \
if ((tt) == TOK_EOF) { \
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_END_OF_XML_SOURCE); \
reportError(NULL, JSMSG_END_OF_XML_SOURCE); \
} \
return result; \
} \
@ -6318,7 +6292,7 @@ Parser::xmlElementOrList(JSBool allowList)
} else {
/* We had better have a tag-close (>) at this point. */
if (tt != TOK_XMLTAGC) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_TAG_SYNTAX);
reportError(NULL, JSMSG_BAD_XML_TAG_SYNTAX);
return NULL;
}
pn2->pn_pos.end = tokenStream.currentToken().pos.end;
@ -6349,7 +6323,7 @@ Parser::xmlElementOrList(JSBool allowList)
tt = tokenStream.getToken();
XML_CHECK_FOR_ERROR_AND_EOF(tt, NULL);
if (tt != TOK_XMLNAME && tt != TOK_LC) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_TAG_SYNTAX);
reportError(NULL, JSMSG_BAD_XML_TAG_SYNTAX);
return NULL;
}
@ -6359,13 +6333,12 @@ Parser::xmlElementOrList(JSBool allowList)
return NULL;
if (pn2->isKind(PNK_XMLETAGO)) {
/* Oops, end tag has attributes! */
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_TAG_SYNTAX);
reportError(NULL, JSMSG_BAD_XML_TAG_SYNTAX);
return NULL;
}
if (endAtom && startAtom && endAtom != startAtom) {
/* End vs. start tag name mismatch: point to the tag name. */
reportErrorNumber(pn2, JSREPORT_UC | JSREPORT_ERROR, JSMSG_XML_TAG_NAME_MISMATCH,
startAtom->chars());
reportUcError(pn2, JSMSG_XML_TAG_NAME_MISMATCH, startAtom->chars());
return NULL;
}
@ -6398,7 +6371,7 @@ Parser::xmlElementOrList(JSBool allowList)
MUST_MATCH_TOKEN(TOK_XMLTAGC, JSMSG_BAD_XML_LIST_SYNTAX);
} else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_NAME_SYNTAX);
reportError(NULL, JSMSG_BAD_XML_NAME_SYNTAX);
return NULL;
}
tokenStream.setXMLTagMode(false);
@ -6445,7 +6418,7 @@ Parser::parseXMLText(JSObject *chain, bool allowList)
ParseNode *pn;
if (tt != TOK_XMLSTAGO) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP);
reportError(NULL, JSMSG_BAD_XML_MARKUP);
pn = NULL;
} else {
pn = xmlElementOrListRoot(allowList);
@ -6468,7 +6441,7 @@ Parser::checkForFunctionNode(PropertyName *name, ParseNode *node)
*/
if (const KeywordInfo *ki = FindKeyword(name->charsZ(), name->length())) {
if (ki->tokentype != TOK_FUNCTION) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_KEYWORD_NOT_NS);
reportError(NULL, JSMSG_KEYWORD_NOT_NS);
return false;
}
@ -6551,7 +6524,7 @@ Parser::starOrAtPropertyIdentifier(TokenKind tt)
JS_ASSERT(tt == TOK_AT || tt == TOK_STAR);
if (allowsXML())
return (tt == TOK_AT) ? attributeIdentifier() : qualifiedIdentifier();
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;
}
#endif
@ -6618,7 +6591,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
unsigned index = 0;
for (; ; index++) {
if (index == StackSpace::ARGS_LENGTH_MAX) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_ARRAY_INIT_TOO_BIG);
reportError(NULL, JSMSG_ARRAY_INIT_TOO_BIG);
return NULL;
}
@ -6859,7 +6832,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
case TOK_RC:
goto end_obj_init;
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_PROP_ID);
reportError(NULL, JSMSG_BAD_PROP_ID);
return NULL;
}
@ -6898,7 +6871,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
}
#endif
else {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_COLON_AFTER_ID);
reportError(NULL, JSMSG_COLON_AFTER_ID);
return NULL;
}
@ -6940,16 +6913,12 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (!js_AtomToPrintableString(context, atom, &name))
return NULL;
unsigned flags = (oldAssignType == VALUE &&
assignType == VALUE &&
!tc->sc->inStrictMode())
? JSREPORT_WARNING
: JSREPORT_ERROR;
if (!ReportCompileErrorNumber(context, &tokenStream, NULL, flags,
JSMSG_DUPLICATE_PROPERTY, name.ptr()))
{
Reporter reporter =
(oldAssignType == VALUE && assignType == VALUE && !tc->sc->inStrictMode())
? &Parser::reportWarning
: &Parser::reportError;
if (!(this->*reporter)(NULL, JSMSG_DUPLICATE_PROPERTY, name.ptr()))
return NULL;
}
}
p.value() = assignType | oldAssignType;
} else {
@ -6961,7 +6930,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (tt == TOK_RC)
goto end_obj_init;
if (tt != TOK_COMMA) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_CURLY_AFTER_LIST);
reportError(NULL, JSMSG_CURLY_AFTER_LIST);
return NULL;
}
}
@ -7095,7 +7064,7 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
return NULL;
default:
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
reportError(NULL, JSMSG_SYNTAX_ERROR);
return NULL;
}
return pn;
@ -7126,8 +7095,7 @@ Parser::parenExpr(JSBool *genexp)
return NULL;
JS_ASSERT(!pn->isKind(PNK_YIELD));
if (pn->isKind(PNK_COMMA) && !pn->isInParens()) {
reportErrorNumber(pn->last(), JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX,
js_generator_str);
reportError(pn->last(), JSMSG_BAD_GENERATOR_SYNTAX, js_generator_str);
return NULL;
}
pn = generatorExpr(pn);
@ -7136,8 +7104,7 @@ Parser::parenExpr(JSBool *genexp)
pn->pn_pos.begin = begin;
if (genexp) {
if (tokenStream.getToken() != TOK_RP) {
reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX,
js_generator_str);
reportError(NULL, JSMSG_BAD_GENERATOR_SYNTAX, js_generator_str);
return NULL;
}
pn->pn_pos.end = tokenStream.currentToken().pos.end;

View File

@ -100,7 +100,12 @@ struct Parser : private AutoGCRooter
/*
* Report a parse (compile) error.
*/
inline bool reportErrorNumber(ParseNode *pn, unsigned flags, unsigned errorNumber, ...);
inline bool reportError(ParseNode *pn, unsigned errorNumber, ...);
inline bool reportUcError(ParseNode *pn, unsigned errorNumber, ...);
inline bool reportWarning(ParseNode *pn, unsigned errorNumber, ...);
inline bool reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...);
inline bool reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...);
typedef bool (js::Parser::*Reporter)(ParseNode *pn, unsigned errorNumber, ...);
private:
ParseNode *allocParseNode(size_t size) {
@ -249,11 +254,53 @@ struct Parser : private AutoGCRooter
};
inline bool
Parser::reportErrorNumber(ParseNode *pn, unsigned flags, unsigned errorNumber, ...)
Parser::reportError(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream.reportCompileErrorNumberVA(pn, flags, errorNumber, args);
bool result = tokenStream.reportCompileErrorNumberVA(pn, JSREPORT_ERROR, errorNumber, args);
va_end(args);
return result;
}
inline bool
Parser::reportUcError(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream.reportCompileErrorNumberVA(pn, JSREPORT_UC | JSREPORT_ERROR,
errorNumber, args);
va_end(args);
return result;
}
inline bool
Parser::reportWarning(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream.reportCompileErrorNumberVA(pn, JSREPORT_WARNING, errorNumber, args);
va_end(args);
return result;
}
inline bool
Parser::reportStrictWarning(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream.reportCompileErrorNumberVA(pn, JSREPORT_STRICT | JSREPORT_WARNING,
errorNumber, args);
va_end(args);
return result;
}
inline bool
Parser::reportStrictModeError(ParseNode *pn, unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = tokenStream.reportStrictModeErrorNumberVA(pn, errorNumber, args);
va_end(args);
return result;
}

View File

@ -393,7 +393,23 @@ TokenStream::TokenBuf::findEOLMax(const jschar *p, size_t max)
}
bool
TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned errorNumber, va_list ap)
TokenStream::reportStrictModeErrorNumberVA(ParseNode *pn, unsigned errorNumber, va_list args)
{
/* In strict mode code, this is an error, not merely a warning. */
unsigned flags;
if (isStrictMode())
flags = JSREPORT_ERROR;
else if (cx->hasStrictOption())
flags = JSREPORT_WARNING;
else
return true;
return reportCompileErrorNumberVA(pn, flags, errorNumber, args);
}
bool
TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned errorNumber,
va_list args)
{
class ReportManager
{
@ -449,7 +465,7 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned
ReportManager mgr(cx, &report, hasCharArgs);
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, errorNumber, &mgr.message, &report,
hasCharArgs, ap)) {
hasCharArgs, args)) {
return false;
}
@ -538,44 +554,43 @@ TokenStream::reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned
}
bool
js::ReportStrictModeError(JSContext *cx, TokenStream *ts, ParseNode *pn, unsigned errorNumber, ...)
TokenStream::reportStrictModeError(unsigned errorNumber, ...)
{
JS_ASSERT(cx == ts->getContext());
/* In strict mode code, this is an error, not merely a warning. */
unsigned flags;
if (ts->isStrictMode())
flags = JSREPORT_ERROR;
else if (cx->hasStrictOption())
flags = JSREPORT_WARNING;
else
return true;
va_list ap;
va_start(ap, errorNumber);
bool result = ts->reportCompileErrorNumberVA(pn, flags, errorNumber, ap);
va_end(ap);
va_list args;
va_start(args, errorNumber);
bool result = reportStrictModeErrorNumberVA(NULL, errorNumber, args);
va_end(args);
return result;
}
bool
js::ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, ParseNode *pn, unsigned flags,
unsigned errorNumber, ...)
TokenStream::reportError(unsigned errorNumber, ...)
{
/*
* We don't handle JSREPORT_STRICT_MODE_ERROR here. Use
* ReportStrictModeError instead, or do the checks in the caller and pass
* plain old JSREPORT_ERROR.
*/
JS_ASSERT(!(flags & JSREPORT_STRICT_MODE_ERROR));
JS_ASSERT(cx == ts->getContext());
va_list args;
va_start(args, errorNumber);
bool result = reportCompileErrorNumberVA(NULL, JSREPORT_ERROR, errorNumber, args);
va_end(args);
return result;
}
va_list ap;
va_start(ap, errorNumber);
bool result = ts->reportCompileErrorNumberVA(pn, flags, errorNumber, ap);
va_end(ap);
bool
TokenStream::reportWarning(unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = reportCompileErrorNumberVA(NULL, JSREPORT_WARNING, errorNumber, args);
va_end(args);
return result;
}
bool
TokenStream::reportStrictWarning(unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
bool result = reportCompileErrorNumberVA(NULL, JSREPORT_STRICT | JSREPORT_WARNING,
errorNumber, args);
va_end(args);
return result;
}
@ -599,7 +614,7 @@ TokenStream::getXMLEntity()
return false;
while ((c = getChar()) != ';') {
if (c == EOF || c == '\n') {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_END_OF_XML_ENTITY);
reportError(JSMSG_END_OF_XML_ENTITY);
return false;
}
if (!tb.append(c))
@ -691,7 +706,7 @@ TokenStream::getXMLEntity()
JS_ASSERT((tb.end() - bp) >= 1);
bytes = DeflateString(cx, bp + 1, (tb.end() - bp) - 1);
if (bytes) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, msg, bytes);
reportError(msg, bytes);
cx->free_(bytes);
}
return false;
@ -779,8 +794,7 @@ TokenStream::getXMLTextOrTag(TokenKind *ttp, Token **tpp)
(nextc = peekChar(),
((flags & TSF_XMLONLYMODE) || nextc != '{') &&
!IsXMLNamePart(nextc))) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_BAD_XML_QNAME);
reportError(JSMSG_BAD_XML_QNAME);
goto error;
}
sawColon = JS_TRUE;
@ -815,8 +829,7 @@ TokenStream::getXMLTextOrTag(TokenKind *ttp, Token **tpp)
qc = c;
while ((c = getChar()) != qc) {
if (c == EOF) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_UNTERMINATED_STRING);
reportError(JSMSG_UNTERMINATED_STRING);
goto error;
}
@ -863,7 +876,7 @@ TokenStream::getXMLTextOrTag(TokenKind *ttp, Token **tpp)
bad_xml_char:
default:
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_BAD_XML_CHARACTER);
reportError(JSMSG_BAD_XML_CHARACTER);
goto error;
}
JS_NOT_REACHED("getXMLTextOrTag 1");
@ -1041,7 +1054,7 @@ TokenStream::getXMLMarkup(TokenKind *ttp, Token **tpp)
return true;
bad_xml_markup:
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP);
reportError(JSMSG_BAD_XML_MARKUP);
error:
*ttp = TOK_ERROR;
*tpp = tp;
@ -1287,10 +1300,8 @@ TokenStream::checkForKeyword(const jschar *s, size_t length, TokenKind *ttp, JSO
if (!kw)
return true;
if (kw->tokentype == TOK_RESERVED) {
return ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_RESERVED_ID, kw->chars);
}
if (kw->tokentype == TOK_RESERVED)
return reportError(JSMSG_RESERVED_ID, kw->chars);
if (kw->tokentype != TOK_STRICT_RESERVED) {
if (kw->version <= versionNumber()) {
@ -1300,8 +1311,7 @@ TokenStream::checkForKeyword(const jschar *s, size_t length, TokenKind *ttp, JSO
*topp = (JSOp) kw->op;
return true;
}
return ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_RESERVED_ID, kw->chars);
return reportError(JSMSG_RESERVED_ID, kw->chars);
}
/*
@ -1315,9 +1325,8 @@ TokenStream::checkForKeyword(const jschar *s, size_t length, TokenKind *ttp, JSO
/* Strict reserved word. */
if (isStrictMode())
return ReportStrictModeError(cx, this, NULL, JSMSG_RESERVED_ID, kw->chars);
return ReportCompileErrorNumber(cx, this, NULL, JSREPORT_STRICT | JSREPORT_WARNING,
JSMSG_RESERVED_ID, kw->chars);
return reportStrictModeError(JSMSG_RESERVED_ID, kw->chars);
return reportStrictWarning(JSMSG_RESERVED_ID, kw->chars);
}
enum FirstCharKind {
@ -1600,10 +1609,8 @@ TokenStream::getTokenInternal()
c = peekChar();
/* Strict mode code allows only \0, then a non-digit. */
if (val != 0 || JS7_ISDEC(c)) {
if (!ReportStrictModeError(cx, this, NULL,
JSMSG_DEPRECATED_OCTAL)) {
if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL))
goto error;
}
setOctalCharacterEscape();
}
if ('0' <= c && c < '8') {
@ -1632,8 +1639,7 @@ TokenStream::getTokenInternal()
+ JS7_UNHEX(cp[3]);
skipChars(4);
} else {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_MALFORMED_ESCAPE, "Unicode");
reportError(JSMSG_MALFORMED_ESCAPE, "Unicode");
goto error;
}
} else if (c == 'x') {
@ -1643,8 +1649,7 @@ TokenStream::getTokenInternal()
c = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]);
skipChars(2);
} else {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_MALFORMED_ESCAPE, "hexadecimal");
reportError(JSMSG_MALFORMED_ESCAPE, "hexadecimal");
goto error;
}
} else if (c == '\n') {
@ -1658,8 +1663,7 @@ TokenStream::getTokenInternal()
}
} else if (TokenBuf::isRawEOLChar(c) || c == EOF) {
ungetCharIgnoreEOL(c);
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_UNTERMINATED_STRING);
reportError(JSMSG_UNTERMINATED_STRING);
goto error;
}
}
@ -1700,8 +1704,7 @@ TokenStream::getTokenInternal()
c = getCharIgnoreEOL();
if (!JS7_ISDEC(c)) {
ungetCharIgnoreEOL(c);
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_MISSING_EXPONENT);
reportError(JSMSG_MISSING_EXPONENT);
goto error;
}
do {
@ -1711,7 +1714,7 @@ TokenStream::getTokenInternal()
ungetCharIgnoreEOL(c);
if (c != EOF && IsIdentifierStart(c)) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_IDSTART_AFTER_NUMBER);
reportError(JSMSG_IDSTART_AFTER_NUMBER);
goto error;
}
@ -1770,7 +1773,7 @@ TokenStream::getTokenInternal()
c = getCharIgnoreEOL();
if (!JS7_ISHEX(c)) {
ungetCharIgnoreEOL(c);
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_MISSING_HEXDIGITS);
reportError(JSMSG_MISSING_HEXDIGITS);
goto error;
}
numStart = userbuf.addressOfNextRawChar() - 1; /* one past the '0x' */
@ -1781,7 +1784,7 @@ TokenStream::getTokenInternal()
numStart = userbuf.addressOfNextRawChar() - 1; /* one past the '0' */
while (JS7_ISDEC(c)) {
/* Octal integer literals are not permitted in strict mode code. */
if (!ReportStrictModeError(cx, this, NULL, JSMSG_DEPRECATED_OCTAL))
if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL))
goto error;
/*
@ -1791,8 +1794,7 @@ TokenStream::getTokenInternal()
* about it.
*/
if (c >= '8') {
if (!ReportCompileErrorNumber(cx, this, NULL, JSREPORT_WARNING,
JSMSG_BAD_OCTAL, c == '8' ? "08" : "09")) {
if (!reportWarning(JSMSG_BAD_OCTAL, c == '8' ? "08" : "09")) {
goto error;
}
goto decimal; /* use the decimal scanner for the rest of the number */
@ -1807,7 +1809,7 @@ TokenStream::getTokenInternal()
ungetCharIgnoreEOL(c);
if (c != EOF && IsIdentifierStart(c)) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_IDSTART_AFTER_NUMBER);
reportError(JSMSG_IDSTART_AFTER_NUMBER);
goto error;
}
@ -1981,8 +1983,7 @@ TokenStream::getTokenInternal()
/* Ignore all characters until comment close. */
}
if (c == EOF) {
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_UNTERMINATED_COMMENT);
reportError(JSMSG_UNTERMINATED_COMMENT);
goto error;
}
if (linenoBefore != lineno)
@ -2014,8 +2015,7 @@ TokenStream::getTokenInternal()
}
if (c == '\n' || c == EOF) {
ungetChar(c);
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR,
JSMSG_UNTERMINATED_REGEXP);
reportError(JSMSG_UNTERMINATED_REGEXP);
goto error;
}
if (!tokenbuf.append(c))
@ -2045,8 +2045,7 @@ TokenStream::getTokenInternal()
char buf[2] = { '\0', '\0' };
tp->pos.begin.index += length + 1;
buf[0] = char(c);
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_BAD_REGEXP_FLAG,
buf);
reportError(JSMSG_BAD_REGEXP_FLAG, buf);
(void) getChar();
goto error;
}
@ -2087,7 +2086,7 @@ TokenStream::getTokenInternal()
badchar:
default:
ReportCompileErrorNumber(cx, this, NULL, JSREPORT_ERROR, JSMSG_ILLEGAL_CHARACTER);
reportError(JSMSG_ILLEGAL_CHARACTER);
goto error;
}

View File

@ -500,10 +500,18 @@ class TokenStream
bool isEOF() const { return !!(flags & TSF_EOF); }
bool hasOctalCharacterEscape() const { return flags & TSF_OCTAL_CHAR; }
// Return false if we should stop compiling, either because (a) we issued
// an error message, or (b) something went wrong, such as an OOM.
// TokenStream-specific error reporters.
bool reportError(unsigned errorNumber, ...);
bool reportWarning(unsigned errorNumber, ...);
bool reportStrictWarning(unsigned errorNumber, ...);
bool reportStrictModeError(unsigned errorNumber, ...);
// General-purpose error reporters. You should avoid calling these
// directly, and instead use the more succinct alternatives (e.g.
// reportError()) in TokenStream, Parser, and BytecodeEmitter.
bool reportCompileErrorNumberVA(ParseNode *pn, unsigned flags, unsigned errorNumber,
va_list ap);
va_list args);
bool reportStrictModeErrorNumberVA(ParseNode *pn, unsigned errorNumber, va_list args);
private:
static JSAtom *atomize(JSContext *cx, CharBuffer &cb);
@ -830,22 +838,6 @@ IsIdentifier(JSLinearString *str);
*/
#define JSREPORT_UC 0x100
/*
* Report a compile-time error by its number. Return true for a warning, false
* for an error. When pn is not null, use it to report error's location.
* Otherwise use ts, which must not be null.
*/
bool
ReportCompileErrorNumber(JSContext *cx, TokenStream *ts, ParseNode *pn, unsigned flags,
unsigned errorNumber, ...);
/*
* Report a condition that should elicit a warning with JSOPTION_STRICT,
* or an error if the current context is handling strict mode code.
*/
bool
ReportStrictModeError(JSContext *cx, TokenStream *ts, ParseNode *pn, unsigned errorNumber, ...);
} /* namespace js */
extern JS_FRIEND_API(int)

View File

@ -1106,8 +1106,7 @@ Function(JSContext *cx, unsigned argc, Value *vp)
* TOK_ERROR, which was already reported.
*/
if (hasRest) {
ReportCompileErrorNumber(cx, &ts, NULL, JSREPORT_ERROR,
JSMSG_PARAMETER_AFTER_REST);
ts.reportError(JSMSG_PARAMETER_AFTER_REST);
return false;
}
@ -1117,13 +1116,10 @@ Function(JSContext *cx, unsigned argc, Value *vp)
tt = ts.getToken();
if (tt != TOK_NAME) {
if (tt != TOK_ERROR)
ReportCompileErrorNumber(cx, &ts, NULL,
JSREPORT_ERROR,
JSMSG_NO_REST_NAME);
ts.reportError(JSMSG_NO_REST_NAME);
return false;
}
}
else {
} else {
return OnBadFormal(cx, tt);
}
}
@ -1134,12 +1130,8 @@ Function(JSContext *cx, unsigned argc, Value *vp)
JSAutoByteString bytes;
if (!js_AtomToPrintableString(cx, name, &bytes))
return false;
if (!ReportCompileErrorNumber(cx, &ts, NULL,
JSREPORT_WARNING | JSREPORT_STRICT,
JSMSG_DUPLICATE_FORMAL, bytes.ptr()))
{
if (!ts.reportStrictWarning(JSMSG_DUPLICATE_FORMAL, bytes.ptr()))
return false;
}
}
uint16_t dummy;

View File

@ -2577,7 +2577,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst)
{
/* The parser notes any uninitialized properties by setting the PNX_DESTRUCT flag. */
if (pn->pn_xflags & PNX_DESTRUCT) {
parser->reportErrorNumber(pn, JSREPORT_ERROR, JSMSG_BAD_OBJECT_INIT);
parser->reportError(pn, JSMSG_BAD_OBJECT_INIT);
return false;
}
NodeVector elts(cx);

View File

@ -1291,8 +1291,7 @@ JSScript::fullyInitFromEmitter(JSContext *cx, BytecodeEmitter *bce)
}
script->lineno = bce->firstLine;
if (script->nfixed + bce->maxStackDepth >= JS_BIT(16)) {
ReportCompileErrorNumber(cx, bce->tokenStream(), NULL, JSREPORT_ERROR, JSMSG_NEED_DIET,
"script");
bce->reportError(NULL, JSMSG_NEED_DIET, "script");
return false;
}
script->nslots = script->nfixed + bce->maxStackDepth;

View File

@ -1248,10 +1248,8 @@ ParseNodeToQName(Parser *parser, ParseNode *pn,
if (!uri) {
Value v = StringValue(prefix);
JSAutoByteString bytes;
if (js_ValueToPrintable(parser->context, v, &bytes)) {
ReportCompileErrorNumber(parser->context, &parser->tokenStream, pn,
JSREPORT_ERROR, JSMSG_BAD_XML_NAMESPACE, bytes.ptr());
}
if (js_ValueToPrintable(parser->context, v, &bytes))
parser->reportError(pn, JSMSG_BAD_XML_NAMESPACE, bytes.ptr());
return NULL;
}
@ -1333,8 +1331,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn,
int stackDummy;
if (!JS_CHECK_STACK_SIZE(cx->runtime->nativeStackLimit, &stackDummy)) {
ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR,
JSMSG_OVER_RECURSED);
parser->reportError(pn, JSMSG_OVER_RECURSED);
return NULL;
}
@ -1473,11 +1470,8 @@ ParseNodeToXML(Parser *parser, ParseNode *pn,
if (pn3->pn_atom == pn2->pn_atom) {
Value v = StringValue(pn2->pn_atom);
JSAutoByteString bytes;
if (js_ValueToPrintable(cx, v, &bytes)) {
ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR,
bytes.ptr());
}
if (js_ValueToPrintable(cx, v, &bytes))
parser->reportError(pn2, JSMSG_DUPLICATE_XML_ATTR, bytes.ptr());
goto fail;
}
}
@ -1571,11 +1565,8 @@ ParseNodeToXML(Parser *parser, ParseNode *pn,
EqualStrings(attrjqn->getQNameLocalName(), qn->getQNameLocalName())) {
Value v = StringValue(pn2->pn_atom);
JSAutoByteString bytes;
if (js_ValueToPrintable(cx, v, &bytes)) {
ReportCompileErrorNumber(cx, &parser->tokenStream, pn2,
JSREPORT_ERROR, JSMSG_DUPLICATE_XML_ATTR,
bytes.ptr());
}
if (js_ValueToPrintable(cx, v, &bytes))
parser->reportError(pn2, JSMSG_DUPLICATE_XML_ATTR, bytes.ptr());
goto fail;
}
}
@ -1615,10 +1606,8 @@ ParseNodeToXML(Parser *parser, ParseNode *pn,
if (IS_XML(str)) {
Value v = StringValue(str);
JSAutoByteString bytes;
if (js_ValueToPrintable(cx, v, &bytes)) {
ReportCompileErrorNumber(cx, &parser->tokenStream, &pi,
JSREPORT_ERROR, JSMSG_RESERVED_ID, bytes.ptr());
}
if (js_ValueToPrintable(cx, v, &bytes))
parser->reportError(&pi, JSMSG_RESERVED_ID, bytes.ptr());
goto fail;
}
@ -1659,7 +1648,7 @@ skip_child:
#undef PN2X_SKIP_CHILD
syntax:
ReportCompileErrorNumber(cx, &parser->tokenStream, pn, JSREPORT_ERROR, JSMSG_BAD_XML_MARKUP);
parser->reportError(pn, JSMSG_BAD_XML_MARKUP);
fail:
js_LeaveLocalRootScope(cx);
return NULL;

View File

@ -147,7 +147,7 @@ RegExpCode::reportYarrError(JSContext *cx, TokenStream *ts, ErrorCode error)
#define COMPILE_EMSG(__code, __msg) \
case JSC::Yarr::__code: \
if (ts) \
ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR, __msg); \
ts->reportError(__msg); \
else \
JS_ReportErrorFlagsAndNumberUC(cx, JSREPORT_ERROR, js_GetErrorMessage, NULL, __msg); \
return