diff --git a/mozilla/js/src/jsfun.c b/mozilla/js/src/jsfun.c index eb39c94f6c7..8e1899c6599 100644 --- a/mozilla/js/src/jsfun.c +++ b/mozilla/js/src/jsfun.c @@ -1447,7 +1447,7 @@ fun_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) } #endif -static const char js_call_str[] = "call"; +static const char call_str[] = "call"; #if JS_HAS_CALL_FUNCTION static JSBool @@ -1467,7 +1467,7 @@ fun_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) if (!JSVAL_IS_FUNCTION(cx, fval)) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, - js_Function_str, js_call_str, + js_Function_str, call_str, JS_GetStringBytes(JS_ValueToString(cx, fval))); return JS_FALSE; } @@ -1606,7 +1606,7 @@ static JSFunctionSpec function_methods[] = { {"apply", fun_apply, 2,0,0}, #endif #if JS_HAS_CALL_FUNCTION - {js_call_str, fun_call, 1,0,0}, + {call_str, fun_call, 1,0,0}, #endif {0,0,0,0,0} }; diff --git a/mozilla/js/src/jsregexp.c b/mozilla/js/src/jsregexp.c index f93d82b0cdd..636a966bded 100644 --- a/mozilla/js/src/jsregexp.c +++ b/mozilla/js/src/jsregexp.c @@ -405,9 +405,9 @@ ProcessOp(CompilerState *state, REOpData *opData, RENode **operandStack, intN op case REOP_LPARENNON: case REOP_LPAREN: /* These should have been processed by a close paren. */ - js_ReportCompileErrorNumber(state->context, state->tokenStream, - JSREPORT_TS | JSREPORT_ERROR, - JSMSG_MISSING_PAREN, opData->errPos); + js_ReportCompileErrorNumberUC(state->context, state->tokenStream, + JSREPORT_TS | JSREPORT_ERROR, + JSMSG_MISSING_PAREN, opData->errPos); return JS_FALSE; default:; } @@ -644,9 +644,9 @@ restartOperator: case '*': case '?': case '{': - js_ReportCompileErrorNumber(state->context, state->tokenStream, - JSREPORT_TS | JSREPORT_ERROR, - JSMSG_BAD_QUANTIFIER, state->cp); + js_ReportCompileErrorNumberUC(state->context, state->tokenStream, + JSREPORT_TS | JSREPORT_ERROR, + JSMSG_BAD_QUANTIFIER, state->cp); result = JS_FALSE; goto out; default: @@ -1182,16 +1182,9 @@ doSimple: state->result->u.ucclass.startIndex = termStart - state->cpbegin; while (JS_TRUE) { if (state->cp == state->cpend) { - char *bytes = js_DeflateString(state->context, termStart, - state->cpend - termStart); - if (!bytes) - return JS_FALSE; - - js_ReportCompileErrorNumber(state->context, state->tokenStream, - JSREPORT_TS | JSREPORT_ERROR, - JSMSG_UNTERM_CLASS, bytes); - - JS_free(state->context, bytes); + js_ReportCompileErrorNumberUC(state->context, state->tokenStream, + JSREPORT_TS | JSREPORT_ERROR, + JSMSG_UNTERM_CLASS, termStart); return JS_FALSE; } @@ -1242,9 +1235,9 @@ doSimple: case '*': case '+': case '?': - js_ReportCompileErrorNumber(state->context, state->tokenStream, - JSREPORT_TS | JSREPORT_ERROR, - JSMSG_BAD_QUANTIFIER, state->cp - 1); + js_ReportCompileErrorNumberUC(state->context, state->tokenStream, + JSREPORT_TS | JSREPORT_ERROR, + JSMSG_BAD_QUANTIFIER, state->cp - 1); return JS_FALSE; default: state->result = NewRENode(state, REOP_FLAT); @@ -1344,10 +1337,10 @@ ParseQuantifier(CompilerState *state) state->cp = errp; return JS_TRUE; quantError: - js_ReportCompileErrorNumber(state->context, - state->tokenStream, - JSREPORT_TS | JSREPORT_ERROR, - err, errp); + js_ReportCompileErrorNumberUC(state->context, + state->tokenStream, + JSREPORT_TS | JSREPORT_ERROR, + err, errp); return JS_FALSE; } } diff --git a/mozilla/js/src/jsscan.c b/mozilla/js/src/jsscan.c index 45ffede0f82..d3dab75054a 100644 --- a/mozilla/js/src/jsscan.c +++ b/mozilla/js/src/jsscan.c @@ -1,4 +1,5 @@ /* -*- 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 ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 @@ -564,12 +565,11 @@ MatchChar(JSTokenStream *ts, int32 expect) return JS_FALSE; } -JSBool -js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, - uintN errorNumber, ...) +static JSBool +ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, + uintN errorNumber, JSErrorReport *report, + JSBool charArgs, va_list ap) { - va_list ap; - JSErrorReport report; JSString *linestr = NULL; JSTokenStream *ts = NULL; JSCodeGenerator *cg = NULL; @@ -583,21 +583,16 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, char *message; JSBool warning; - if ((flags & JSREPORT_STRICT) && !JS_HAS_STRICT_OPTION(cx)) - return JS_TRUE; - - memset(&report, 0, sizeof (struct JSErrorReport)); - report.flags = flags; - report.errorNumber = errorNumber; + memset(report, 0, sizeof (struct JSErrorReport)); + report->flags = flags; + report->errorNumber = errorNumber; message = NULL; - va_start(ap, errorNumber); if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, - errorNumber, &message, &report, &warning, - JS_TRUE, ap)) { + errorNumber, &message, report, &warning, + charArgs, ap)) { return JS_FALSE; } - va_end(ap); js_AddRoot(cx, &linestr, "error line buffer"); @@ -626,21 +621,21 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, */ do { if (ts) { - report.filename = ts->filename; + report->filename = ts->filename; #if JS_HAS_XML_SUPPORT if (pn) { - report.lineno = pn->pn_pos.begin.lineno; - if (report.lineno != ts->lineno) + report->lineno = pn->pn_pos.begin.lineno; + if (report->lineno != ts->lineno) break; } #endif - report.lineno = ts->lineno; + report->lineno = ts->lineno; linestr = js_NewStringCopyN(cx, ts->linebuf.base, PTRDIFF(ts->linebuf.limit, ts->linebuf.base, jschar), 0); - report.linebuf = linestr + report->linebuf = linestr ? JS_GetStringBytes(linestr) : NULL; 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) ? tp->begin.index - ts->linepos : 0; - report.tokenptr = linestr ? report.linebuf + index : NULL; - report.uclinebuf = linestr ? JS_GetStringChars(linestr) : NULL; - report.uctokenptr = linestr ? report.uclinebuf + index : NULL; + report->tokenptr = linestr ? report->linebuf + index : NULL; + report->uclinebuf = linestr ? JS_GetStringChars(linestr) : NULL; + report->uctokenptr = linestr ? report->uclinebuf + index : NULL; break; } if (cg) { - report.filename = cg->filename; - report.lineno = CG_CURRENT_LINE(cg); + report->filename = cg->filename; + report->lineno = CG_CURRENT_LINE(cg); break; } @@ -669,8 +664,8 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, */ for (fp = cx->fp; fp; fp = fp->down) { if (fp->script && fp->pc) { - report.filename = fp->script->filename; - report.lineno = js_PCToLineNumber(cx, fp->script, fp->pc); + report->filename = fp->script->filename; + report->lineno = js_PCToLineNumber(cx, fp->script, fp->pc); break; } } @@ -700,7 +695,7 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, * which is likely spurious. */ if (!ts || !(ts->flags & TSF_ERROR)) { - if (js_ErrorToException(cx, message, &report)) + if (js_ErrorToException(cx, message, report)) onError = NULL; } @@ -716,25 +711,19 @@ js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, if (cx->runtime->debugErrorHook && onError) { JSDebugErrorHook hook = cx->runtime->debugErrorHook; /* test local in case debugErrorHook changed on another thread */ - if (hook && !hook(cx, message, &report, + if (hook && !hook(cx, message, report, cx->runtime->debugErrorHookData)) { onError = NULL; } } if (onError) - (*onError)(cx, message, &report); + (*onError)(cx, message, report); } if (message) JS_free(cx, message); - if (report.messageArgs) { - int i = 0; - 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); + if (report->ucmessage) + JS_free(cx, (void *)report->ucmessage); 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. */ 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; } diff --git a/mozilla/js/src/jsscan.h b/mozilla/js/src/jsscan.h index 8057eca65e4..cda5daefe8b 100644 --- a/mozilla/js/src/jsscan.h +++ b/mozilla/js/src/jsscan.h @@ -297,6 +297,10 @@ extern JSBool js_ReportCompileErrorNumber(JSContext *cx, void *handle, uintN flags, 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. */ #define JSREPORT_HANDLE 0x300 #define JSREPORT_TS 0x000