зеркало из https://github.com/mozilla/pjs.git
bug 298286: JS_ReportCompileErrorNumber doesn't deal with jschar arguments. This fixes error reporting in jsregexp.c. r+a=brendan
This commit is contained in:
Родитель
0fd1ab3be4
Коммит
702acea788
|
@ -1447,7 +1447,7 @@ fun_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char js_call_str[] = "call";
|
static const char call_str[] = "call";
|
||||||
|
|
||||||
#if JS_HAS_CALL_FUNCTION
|
#if JS_HAS_CALL_FUNCTION
|
||||||
static JSBool
|
static JSBool
|
||||||
|
@ -1467,7 +1467,7 @@ fun_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
if (!JSVAL_IS_FUNCTION(cx, fval)) {
|
if (!JSVAL_IS_FUNCTION(cx, fval)) {
|
||||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||||
JSMSG_INCOMPATIBLE_PROTO,
|
JSMSG_INCOMPATIBLE_PROTO,
|
||||||
js_Function_str, js_call_str,
|
js_Function_str, call_str,
|
||||||
JS_GetStringBytes(JS_ValueToString(cx, fval)));
|
JS_GetStringBytes(JS_ValueToString(cx, fval)));
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1606,7 +1606,7 @@ static JSFunctionSpec function_methods[] = {
|
||||||
{"apply", fun_apply, 2,0,0},
|
{"apply", fun_apply, 2,0,0},
|
||||||
#endif
|
#endif
|
||||||
#if JS_HAS_CALL_FUNCTION
|
#if JS_HAS_CALL_FUNCTION
|
||||||
{js_call_str, fun_call, 1,0,0},
|
{call_str, fun_call, 1,0,0},
|
||||||
#endif
|
#endif
|
||||||
{0,0,0,0,0}
|
{0,0,0,0,0}
|
||||||
};
|
};
|
||||||
|
|
|
@ -405,9 +405,9 @@ ProcessOp(CompilerState *state, REOpData *opData, RENode **operandStack, intN op
|
||||||
case REOP_LPARENNON:
|
case REOP_LPARENNON:
|
||||||
case REOP_LPAREN:
|
case REOP_LPAREN:
|
||||||
/* These should have been processed by a close paren. */
|
/* These should have been processed by a close paren. */
|
||||||
js_ReportCompileErrorNumber(state->context, state->tokenStream,
|
js_ReportCompileErrorNumberUC(state->context, state->tokenStream,
|
||||||
JSREPORT_TS | JSREPORT_ERROR,
|
JSREPORT_TS | JSREPORT_ERROR,
|
||||||
JSMSG_MISSING_PAREN, opData->errPos);
|
JSMSG_MISSING_PAREN, opData->errPos);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
default:;
|
default:;
|
||||||
}
|
}
|
||||||
|
@ -644,9 +644,9 @@ restartOperator:
|
||||||
case '*':
|
case '*':
|
||||||
case '?':
|
case '?':
|
||||||
case '{':
|
case '{':
|
||||||
js_ReportCompileErrorNumber(state->context, state->tokenStream,
|
js_ReportCompileErrorNumberUC(state->context, state->tokenStream,
|
||||||
JSREPORT_TS | JSREPORT_ERROR,
|
JSREPORT_TS | JSREPORT_ERROR,
|
||||||
JSMSG_BAD_QUANTIFIER, state->cp);
|
JSMSG_BAD_QUANTIFIER, state->cp);
|
||||||
result = JS_FALSE;
|
result = JS_FALSE;
|
||||||
goto out;
|
goto out;
|
||||||
default:
|
default:
|
||||||
|
@ -1182,16 +1182,9 @@ doSimple:
|
||||||
state->result->u.ucclass.startIndex = termStart - state->cpbegin;
|
state->result->u.ucclass.startIndex = termStart - state->cpbegin;
|
||||||
while (JS_TRUE) {
|
while (JS_TRUE) {
|
||||||
if (state->cp == state->cpend) {
|
if (state->cp == state->cpend) {
|
||||||
char *bytes = js_DeflateString(state->context, termStart,
|
js_ReportCompileErrorNumberUC(state->context, state->tokenStream,
|
||||||
state->cpend - termStart);
|
JSREPORT_TS | JSREPORT_ERROR,
|
||||||
if (!bytes)
|
JSMSG_UNTERM_CLASS, termStart);
|
||||||
return JS_FALSE;
|
|
||||||
|
|
||||||
js_ReportCompileErrorNumber(state->context, state->tokenStream,
|
|
||||||
JSREPORT_TS | JSREPORT_ERROR,
|
|
||||||
JSMSG_UNTERM_CLASS, bytes);
|
|
||||||
|
|
||||||
JS_free(state->context, bytes);
|
|
||||||
|
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1242,9 +1235,9 @@ doSimple:
|
||||||
case '*':
|
case '*':
|
||||||
case '+':
|
case '+':
|
||||||
case '?':
|
case '?':
|
||||||
js_ReportCompileErrorNumber(state->context, state->tokenStream,
|
js_ReportCompileErrorNumberUC(state->context, state->tokenStream,
|
||||||
JSREPORT_TS | JSREPORT_ERROR,
|
JSREPORT_TS | JSREPORT_ERROR,
|
||||||
JSMSG_BAD_QUANTIFIER, state->cp - 1);
|
JSMSG_BAD_QUANTIFIER, state->cp - 1);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
default:
|
default:
|
||||||
state->result = NewRENode(state, REOP_FLAT);
|
state->result = NewRENode(state, REOP_FLAT);
|
||||||
|
@ -1344,10 +1337,10 @@ ParseQuantifier(CompilerState *state)
|
||||||
state->cp = errp;
|
state->cp = errp;
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
quantError:
|
quantError:
|
||||||
js_ReportCompileErrorNumber(state->context,
|
js_ReportCompileErrorNumberUC(state->context,
|
||||||
state->tokenStream,
|
state->tokenStream,
|
||||||
JSREPORT_TS | JSREPORT_ERROR,
|
JSREPORT_TS | JSREPORT_ERROR,
|
||||||
err, errp);
|
err, errp);
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
118
js/src/jsscan.c
118
js/src/jsscan.c
|
@ -1,4 +1,5 @@
|
||||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
* vim: set sw=4 ts=8 et tw=80:
|
||||||
*
|
*
|
||||||
* ***** BEGIN LICENSE BLOCK *****
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
@ -564,12 +565,11 @@ MatchChar(JSTokenStream *ts, int32 expect)
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool
|
static JSBool
|
||||||
js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
uintN errorNumber, ...)
|
uintN errorNumber, JSErrorReport *report,
|
||||||
|
JSBool charArgs, va_list ap)
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
JSErrorReport report;
|
|
||||||
JSString *linestr = NULL;
|
JSString *linestr = NULL;
|
||||||
JSTokenStream *ts = NULL;
|
JSTokenStream *ts = NULL;
|
||||||
JSCodeGenerator *cg = NULL;
|
JSCodeGenerator *cg = NULL;
|
||||||
|
@ -583,21 +583,16 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
char *message;
|
char *message;
|
||||||
JSBool warning;
|
JSBool warning;
|
||||||
|
|
||||||
if ((flags & JSREPORT_STRICT) && !JS_HAS_STRICT_OPTION(cx))
|
memset(report, 0, sizeof (struct JSErrorReport));
|
||||||
return JS_TRUE;
|
report->flags = flags;
|
||||||
|
report->errorNumber = errorNumber;
|
||||||
memset(&report, 0, sizeof (struct JSErrorReport));
|
|
||||||
report.flags = flags;
|
|
||||||
report.errorNumber = errorNumber;
|
|
||||||
message = NULL;
|
message = NULL;
|
||||||
|
|
||||||
va_start(ap, errorNumber);
|
|
||||||
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL,
|
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL,
|
||||||
errorNumber, &message, &report, &warning,
|
errorNumber, &message, report, &warning,
|
||||||
JS_TRUE, ap)) {
|
charArgs, ap)) {
|
||||||
return JS_FALSE;
|
return JS_FALSE;
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
js_AddRoot(cx, &linestr, "error line buffer");
|
js_AddRoot(cx, &linestr, "error line buffer");
|
||||||
|
|
||||||
|
@ -626,21 +621,21 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
if (ts) {
|
if (ts) {
|
||||||
report.filename = ts->filename;
|
report->filename = ts->filename;
|
||||||
#if JS_HAS_XML_SUPPORT
|
#if JS_HAS_XML_SUPPORT
|
||||||
if (pn) {
|
if (pn) {
|
||||||
report.lineno = pn->pn_pos.begin.lineno;
|
report->lineno = pn->pn_pos.begin.lineno;
|
||||||
if (report.lineno != ts->lineno)
|
if (report->lineno != ts->lineno)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
report.lineno = ts->lineno;
|
report->lineno = ts->lineno;
|
||||||
linestr = js_NewStringCopyN(cx, ts->linebuf.base,
|
linestr = js_NewStringCopyN(cx, ts->linebuf.base,
|
||||||
PTRDIFF(ts->linebuf.limit,
|
PTRDIFF(ts->linebuf.limit,
|
||||||
ts->linebuf.base,
|
ts->linebuf.base,
|
||||||
jschar),
|
jschar),
|
||||||
0);
|
0);
|
||||||
report.linebuf = linestr
|
report->linebuf = linestr
|
||||||
? JS_GetStringBytes(linestr)
|
? JS_GetStringBytes(linestr)
|
||||||
: NULL;
|
: NULL;
|
||||||
tp = &ts->tokens[(ts->cursor+ts->lookahead) & NTOKENS_MASK].pos;
|
tp = &ts->tokens[(ts->cursor+ts->lookahead) & NTOKENS_MASK].pos;
|
||||||
|
@ -651,15 +646,15 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
index = (tp->begin.lineno == tp->end.lineno)
|
index = (tp->begin.lineno == tp->end.lineno)
|
||||||
? tp->begin.index - ts->linepos
|
? tp->begin.index - ts->linepos
|
||||||
: 0;
|
: 0;
|
||||||
report.tokenptr = linestr ? report.linebuf + index : NULL;
|
report->tokenptr = linestr ? report->linebuf + index : NULL;
|
||||||
report.uclinebuf = linestr ? JS_GetStringChars(linestr) : NULL;
|
report->uclinebuf = linestr ? JS_GetStringChars(linestr) : NULL;
|
||||||
report.uctokenptr = linestr ? report.uclinebuf + index : NULL;
|
report->uctokenptr = linestr ? report->uclinebuf + index : NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cg) {
|
if (cg) {
|
||||||
report.filename = cg->filename;
|
report->filename = cg->filename;
|
||||||
report.lineno = CG_CURRENT_LINE(cg);
|
report->lineno = CG_CURRENT_LINE(cg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,8 +664,8 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
*/
|
*/
|
||||||
for (fp = cx->fp; fp; fp = fp->down) {
|
for (fp = cx->fp; fp; fp = fp->down) {
|
||||||
if (fp->script && fp->pc) {
|
if (fp->script && fp->pc) {
|
||||||
report.filename = fp->script->filename;
|
report->filename = fp->script->filename;
|
||||||
report.lineno = js_PCToLineNumber(cx, fp->script, fp->pc);
|
report->lineno = js_PCToLineNumber(cx, fp->script, fp->pc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -700,7 +695,7 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
* which is likely spurious.
|
* which is likely spurious.
|
||||||
*/
|
*/
|
||||||
if (!ts || !(ts->flags & TSF_ERROR)) {
|
if (!ts || !(ts->flags & TSF_ERROR)) {
|
||||||
if (js_ErrorToException(cx, message, &report))
|
if (js_ErrorToException(cx, message, report))
|
||||||
onError = NULL;
|
onError = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,25 +711,19 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
if (cx->runtime->debugErrorHook && onError) {
|
if (cx->runtime->debugErrorHook && onError) {
|
||||||
JSDebugErrorHook hook = cx->runtime->debugErrorHook;
|
JSDebugErrorHook hook = cx->runtime->debugErrorHook;
|
||||||
/* test local in case debugErrorHook changed on another thread */
|
/* test local in case debugErrorHook changed on another thread */
|
||||||
if (hook && !hook(cx, message, &report,
|
if (hook && !hook(cx, message, report,
|
||||||
cx->runtime->debugErrorHookData)) {
|
cx->runtime->debugErrorHookData)) {
|
||||||
onError = NULL;
|
onError = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (onError)
|
if (onError)
|
||||||
(*onError)(cx, message, &report);
|
(*onError)(cx, message, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message)
|
if (message)
|
||||||
JS_free(cx, message);
|
JS_free(cx, message);
|
||||||
if (report.messageArgs) {
|
if (report->ucmessage)
|
||||||
int i = 0;
|
JS_free(cx, (void *)report->ucmessage);
|
||||||
while (report.messageArgs[i])
|
|
||||||
JS_free(cx, (void *)report.messageArgs[i++]);
|
|
||||||
JS_free(cx, (void *)report.messageArgs);
|
|
||||||
}
|
|
||||||
if (report.ucmessage)
|
|
||||||
JS_free(cx, (void *)report.ucmessage);
|
|
||||||
|
|
||||||
js_RemoveRoot(cx->runtime, &linestr);
|
js_RemoveRoot(cx->runtime, &linestr);
|
||||||
|
|
||||||
|
@ -742,6 +731,59 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
/* Set the error flag to suppress spurious reports. */
|
/* Set the error flag to suppress spurious reports. */
|
||||||
ts->flags |= TSF_ERROR;
|
ts->flags |= TSF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool
|
||||||
|
js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
|
uintN errorNumber, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
JSErrorReport report;
|
||||||
|
JSBool warning;
|
||||||
|
|
||||||
|
if ((flags & JSREPORT_STRICT) && !JS_HAS_STRICT_OPTION(cx))
|
||||||
|
return JS_TRUE;
|
||||||
|
|
||||||
|
va_start(ap, errorNumber);
|
||||||
|
warning = ReportCompileErrorNumber(cx, handle, flags, errorNumber,
|
||||||
|
&report, JS_TRUE, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have to do this here because js_ReportCompileErrorNumberUC doesn't
|
||||||
|
* need to do this.
|
||||||
|
*/
|
||||||
|
if (report.messageArgs) {
|
||||||
|
int i = 0;
|
||||||
|
while (report.messageArgs[i])
|
||||||
|
JS_free(cx, (void *)report.messageArgs[i++]);
|
||||||
|
JS_free(cx, (void *)report.messageArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
JSBool
|
||||||
|
js_ReportCompileErrorNumberUC(JSContext *cx, void *handle, uintN flags,
|
||||||
|
uintN errorNumber, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
JSErrorReport report;
|
||||||
|
JSBool warning;
|
||||||
|
|
||||||
|
if ((flags & JSREPORT_STRICT) && !JS_HAS_STRICT_OPTION(cx))
|
||||||
|
return JS_TRUE;
|
||||||
|
|
||||||
|
va_start(ap, errorNumber);
|
||||||
|
warning = ReportCompileErrorNumber(cx, handle, flags, errorNumber,
|
||||||
|
&report, JS_FALSE, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
if (report.messageArgs)
|
||||||
|
JS_free(cx, (void *)report.messageArgs);
|
||||||
|
|
||||||
return warning;
|
return warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,6 +297,10 @@ extern JSBool
|
||||||
js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags,
|
||||||
uintN errorNumber, ...);
|
uintN errorNumber, ...);
|
||||||
|
|
||||||
|
extern JSBool
|
||||||
|
js_ReportCompileErrorNumberUC(JSContext *cx, void *handle, uintN flags,
|
||||||
|
uintN errorNumber, ...);
|
||||||
|
|
||||||
/* Steal some JSREPORT_* bits (see jsapi.h) to tell handle's type. */
|
/* Steal some JSREPORT_* bits (see jsapi.h) to tell handle's type. */
|
||||||
#define JSREPORT_HANDLE 0x300
|
#define JSREPORT_HANDLE 0x300
|
||||||
#define JSREPORT_TS 0x000
|
#define JSREPORT_TS 0x000
|
||||||
|
|
Загрузка…
Ссылка в новой задаче