зеркало из https://github.com/mozilla/pjs.git
Bug 518621 - JS_ReportErrorNumber ignores exception type for user-generated messages. r=mrbkap
This commit is contained in:
Родитель
add24e08b7
Коммит
ad4e58bc28
|
@ -43,10 +43,5 @@
|
|||
*/
|
||||
|
||||
MSG_DEF(CTYPESMSG_PLACEHOLDER_0, 0, 0, JSEXN_NONE, NULL)
|
||||
MSG_DEF(CTYPESMSG_PLACEHOLDER_1, 1, 0, JSEXN_NONE, NULL)
|
||||
MSG_DEF(CTYPESMSG_PLACEHOLDER_2, 2, 0, JSEXN_NONE, NULL)
|
||||
|
||||
// This error has to be number 3 in order to be a TypeError,
|
||||
// due to a bug in the js engine.
|
||||
MSG_DEF(CTYPESMSG_TYPE_ERROR, 3, 2, JSEXN_TYPEERR, "expected type {0}, got {1}")
|
||||
MSG_DEF(CTYPESMSG_TYPE_ERROR, 1, 2, JSEXN_TYPEERR, "expected type {0}, got {1}")
|
||||
|
||||
|
|
|
@ -5827,7 +5827,8 @@ JS_PUBLIC_API(JSBool)
|
|||
JS_ThrowReportedError(JSContext *cx, const char *message,
|
||||
JSErrorReport *reportp)
|
||||
{
|
||||
return JS_IsRunning(cx) && js_ErrorToException(cx, message, reportp);
|
||||
return JS_IsRunning(cx) &&
|
||||
js_ErrorToException(cx, message, reportp, NULL, NULL);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
|
|
|
@ -1281,7 +1281,8 @@ MarkLocalRoots(JSTracer *trc, JSLocalRootStack *lrs)
|
|||
}
|
||||
|
||||
static void
|
||||
ReportError(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
ReportError(JSContext *cx, const char *message, JSErrorReport *reportp,
|
||||
JSErrorCallback callback, void *userRef)
|
||||
{
|
||||
/*
|
||||
* Check the error report, and set a JavaScript-catchable exception
|
||||
|
@ -1290,7 +1291,8 @@ ReportError(JSContext *cx, const char *message, JSErrorReport *reportp)
|
|||
* on the error report, and exception-aware hosts should ignore it.
|
||||
*/
|
||||
JS_ASSERT(reportp);
|
||||
if (reportp->errorNumber == JSMSG_UNCAUGHT_EXCEPTION)
|
||||
if ((!callback || callback == js_GetErrorMessage) &&
|
||||
reportp->errorNumber == JSMSG_UNCAUGHT_EXCEPTION)
|
||||
reportp->flags |= JSREPORT_EXCEPTION;
|
||||
|
||||
/*
|
||||
|
@ -1301,7 +1303,8 @@ ReportError(JSContext *cx, const char *message, JSErrorReport *reportp)
|
|||
* propagates out of scope. This is needed for compatability
|
||||
* with the old scheme.
|
||||
*/
|
||||
if (!JS_IsRunning(cx) || !js_ErrorToException(cx, message, reportp)) {
|
||||
if (!JS_IsRunning(cx) ||
|
||||
!js_ErrorToException(cx, message, reportp, callback, userRef)) {
|
||||
js_ReportErrorAgain(cx, message, reportp);
|
||||
} else if (cx->debugHooks->debugErrorHook && cx->errorReporter) {
|
||||
JSDebugErrorHook hook = cx->debugHooks->debugErrorHook;
|
||||
|
@ -1457,7 +1460,7 @@ js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
|||
|
||||
warning = JSREPORT_IS_WARNING(report.flags);
|
||||
|
||||
ReportError(cx, message, &report);
|
||||
ReportError(cx, message, &report, NULL, NULL);
|
||||
js_free(message);
|
||||
cx->free(ucmessage);
|
||||
return warning;
|
||||
|
@ -1651,7 +1654,7 @@ js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
ReportError(cx, message, &report);
|
||||
ReportError(cx, message, &report, callback, userRef);
|
||||
|
||||
if (message)
|
||||
cx->free(message);
|
||||
|
|
|
@ -1104,7 +1104,8 @@ static struct exnname { char *name; char *exception; } errortoexnname[] = {
|
|||
#endif /* DEBUG */
|
||||
|
||||
JSBool
|
||||
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
|
||||
JSErrorCallback callback, void *userRef)
|
||||
{
|
||||
JSErrNum errorNumber;
|
||||
const JSErrorFormatString *errorString;
|
||||
|
@ -1124,7 +1125,10 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp)
|
|||
|
||||
/* Find the exception index associated with this error. */
|
||||
errorNumber = (JSErrNum) reportp->errorNumber;
|
||||
errorString = js_GetLocalizedErrorMessage(cx, NULL, NULL, errorNumber);
|
||||
if (!callback || callback == js_GetErrorMessage)
|
||||
errorString = js_GetLocalizedErrorMessage(cx, NULL, NULL, errorNumber);
|
||||
else
|
||||
errorString = callback(userRef, NULL, errorNumber);
|
||||
exn = errorString ? (JSExnType) errorString->exnType : JSEXN_NONE;
|
||||
JS_ASSERT(exn < JSEXN_LIMIT);
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ js_InitExceptionClasses(JSContext *cx, JSObject *obj);
|
|||
* found and set, JS_FALSE otherwise.
|
||||
*/
|
||||
extern JSBool
|
||||
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp);
|
||||
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
|
||||
JSErrorCallback callback, void *userRef);
|
||||
|
||||
/*
|
||||
* Called if a JS API call to js_Execute or js_InternalCall fails; calls the
|
||||
|
|
|
@ -607,7 +607,7 @@ ReportCompileErrorNumberVA(JSContext *cx, JSTokenStream *ts, JSParseNode *pn,
|
|||
* which is likely spurious.
|
||||
*/
|
||||
if (!(ts->flags & TSF_ERROR)) {
|
||||
if (js_ErrorToException(cx, message, &report))
|
||||
if (js_ErrorToException(cx, message, &report, NULL, NULL))
|
||||
onError = NULL;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче