зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1037613 - rm js_GetLocalizedErrorMessage, localeGetErrorMessage callback. r=jorendorff
This commit is contained in:
Родитель
d268839202
Коммит
cfcce18b5a
|
@ -54,8 +54,7 @@ JSErrorFormatString ErrorFormatString[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const JSErrorFormatString*
|
const JSErrorFormatString*
|
||||||
GetErrorMessage(void* aUserRef, const char* aLocale,
|
GetErrorMessage(void* aUserRef, const unsigned aErrorNumber)
|
||||||
const unsigned aErrorNumber)
|
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aErrorNumber < ArrayLength(ErrorFormatString));
|
MOZ_ASSERT(aErrorNumber < ArrayLength(ErrorFormatString));
|
||||||
return &ErrorFormatString[aErrorNumber];
|
return &ErrorFormatString[aErrorNumber];
|
||||||
|
@ -139,8 +138,7 @@ ErrorResult::ThrowTypeError(const dom::ErrNum errorNumber, ...)
|
||||||
mResult = NS_ERROR_TYPE_ERR;
|
mResult = NS_ERROR_TYPE_ERR;
|
||||||
Message* message = new Message();
|
Message* message = new Message();
|
||||||
message->mErrorNumber = errorNumber;
|
message->mErrorNumber = errorNumber;
|
||||||
uint16_t argCount =
|
uint16_t argCount = dom::GetErrorMessage(nullptr, errorNumber)->argCount;
|
||||||
dom::GetErrorMessage(nullptr, nullptr, errorNumber)->argCount;
|
|
||||||
MOZ_ASSERT(argCount <= 10);
|
MOZ_ASSERT(argCount <= 10);
|
||||||
argCount = std::min<uint16_t>(argCount, 10);
|
argCount = std::min<uint16_t>(argCount, 10);
|
||||||
while (argCount--) {
|
while (argCount--) {
|
||||||
|
|
|
@ -877,7 +877,7 @@ static const JSErrorFormatString ErrorFormatString[CTYPESERR_LIMIT] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JSErrorFormatString*
|
static const JSErrorFormatString*
|
||||||
GetErrorMessage(void* userRef, const char* locale, const unsigned errorNumber)
|
GetErrorMessage(void* userRef, const unsigned errorNumber)
|
||||||
{
|
{
|
||||||
if (0 < errorNumber && errorNumber < CTYPESERR_LIMIT)
|
if (0 < errorNumber && errorNumber < CTYPESERR_LIMIT)
|
||||||
return &ErrorFormatString[errorNumber];
|
return &ErrorFormatString[errorNumber];
|
||||||
|
|
|
@ -733,8 +733,7 @@ typedef struct JSErrorFormatString {
|
||||||
} JSErrorFormatString;
|
} JSErrorFormatString;
|
||||||
|
|
||||||
typedef const JSErrorFormatString *
|
typedef const JSErrorFormatString *
|
||||||
(* JSErrorCallback)(void *userRef, const char *locale,
|
(* JSErrorCallback)(void *userRef, const unsigned errorNumber);
|
||||||
const unsigned errorNumber);
|
|
||||||
|
|
||||||
typedef bool
|
typedef bool
|
||||||
(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval);
|
(* JSLocaleToUpperCase)(JSContext *cx, JS::HandleString src, JS::MutableHandleValue rval);
|
||||||
|
@ -4536,7 +4535,6 @@ struct JSLocaleCallbacks {
|
||||||
JSLocaleToLowerCase localeToLowerCase;
|
JSLocaleToLowerCase localeToLowerCase;
|
||||||
JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API
|
JSLocaleCompare localeCompare; // not used #if EXPOSE_INTL_API
|
||||||
JSLocaleToUnicode localeToUnicode;
|
JSLocaleToUnicode localeToUnicode;
|
||||||
JSErrorCallback localeGetErrorMessage;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -391,8 +391,7 @@ js_ReportOutOfMemory(ThreadSafeContext *cxArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the message for this error, but we don't expand any arguments. */
|
/* Get the message for this error, but we don't expand any arguments. */
|
||||||
const JSErrorFormatString *efs =
|
const JSErrorFormatString *efs = js_GetErrorMessage(nullptr, JSMSG_OUT_OF_MEMORY);
|
||||||
js_GetLocalizedErrorMessage(cx, nullptr, nullptr, JSMSG_OUT_OF_MEMORY);
|
|
||||||
const char *msg = efs ? efs->format : "Out of memory";
|
const char *msg = efs ? efs->format : "Out of memory";
|
||||||
|
|
||||||
/* Fill out the report, but don't do anything that requires allocation. */
|
/* Fill out the report, but don't do anything that requires allocation. */
|
||||||
|
@ -671,13 +670,14 @@ js_ExpandErrorArguments(ExclusiveContext *cx, JSErrorCallback callback,
|
||||||
|
|
||||||
*messagep = nullptr;
|
*messagep = nullptr;
|
||||||
|
|
||||||
/* Most calls supply js_GetErrorMessage; if this is so, assume nullptr. */
|
if (!callback)
|
||||||
if (!callback || callback == js_GetErrorMessage) {
|
callback = js_GetErrorMessage;
|
||||||
efs = js_GetLocalizedErrorMessage(cx, userRef, nullptr, errorNumber);
|
|
||||||
} else {
|
{
|
||||||
AutoSuppressGC suppressGC(cx);
|
AutoSuppressGC suppressGC(cx);
|
||||||
efs = callback(userRef, nullptr, errorNumber);
|
efs = callback(userRef, errorNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (efs) {
|
if (efs) {
|
||||||
reportp->exnType = efs->exnType;
|
reportp->exnType = efs->exnType;
|
||||||
|
|
||||||
|
@ -1004,9 +1004,9 @@ const JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
JS_FRIEND_API(const JSErrorFormatString *)
|
JS_FRIEND_API(const JSErrorFormatString *)
|
||||||
js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber)
|
js_GetErrorMessage(void *userRef, const unsigned errorNumber)
|
||||||
{
|
{
|
||||||
if ((errorNumber > 0) && (errorNumber < JSErr_Limit))
|
if (errorNumber > 0 && errorNumber < JSErr_Limit)
|
||||||
return &js_ErrorFormatString[errorNumber];
|
return &js_ErrorFormatString[errorNumber];
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -579,28 +579,6 @@ ErrorObject::createConstructor(JSContext *cx, JSProtoKey key)
|
||||||
return ctor;
|
return ctor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const JSErrorFormatString*
|
|
||||||
js_GetLocalizedErrorMessage(ExclusiveContext *cx, void *userRef, const char *locale,
|
|
||||||
const unsigned errorNumber)
|
|
||||||
{
|
|
||||||
const JSErrorFormatString *errorString = nullptr;
|
|
||||||
|
|
||||||
// The locale callbacks might not be thread safe, so don't call them if
|
|
||||||
// we're not on the main thread. When used with XPConnect,
|
|
||||||
// |localeGetErrorMessage| will be nullptr anyways.
|
|
||||||
if (cx->isJSContext() &&
|
|
||||||
cx->asJSContext()->runtime()->localeCallbacks &&
|
|
||||||
cx->asJSContext()->runtime()->localeCallbacks->localeGetErrorMessage)
|
|
||||||
{
|
|
||||||
JSLocaleCallbacks *callbacks = cx->asJSContext()->runtime()->localeCallbacks;
|
|
||||||
errorString = callbacks->localeGetErrorMessage(userRef, locale, errorNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!errorString)
|
|
||||||
errorString = js_GetErrorMessage(userRef, locale, errorNumber);
|
|
||||||
return errorString;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS_FRIEND_API(JSFlatString *)
|
JS_FRIEND_API(JSFlatString *)
|
||||||
js::GetErrorTypeName(JSRuntime *rt, int16_t exnType)
|
js::GetErrorTypeName(JSRuntime *rt, int16_t exnType)
|
||||||
{
|
{
|
||||||
|
@ -628,11 +606,9 @@ js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp,
|
||||||
|
|
||||||
// Find the exception index associated with this error.
|
// Find the exception index associated with this error.
|
||||||
JSErrNum errorNumber = static_cast<JSErrNum>(reportp->errorNumber);
|
JSErrNum errorNumber = static_cast<JSErrNum>(reportp->errorNumber);
|
||||||
const JSErrorFormatString *errorString;
|
if (!callback)
|
||||||
if (!callback || callback == js_GetErrorMessage)
|
callback = js_GetErrorMessage;
|
||||||
errorString = js_GetLocalizedErrorMessage(cx, nullptr, nullptr, errorNumber);
|
const JSErrorFormatString *errorString = callback(userRef, errorNumber);
|
||||||
else
|
|
||||||
errorString = callback(userRef, nullptr, errorNumber);
|
|
||||||
JSExnType exnType = errorString ? static_cast<JSExnType>(errorString->exnType) : JSEXN_NONE;
|
JSExnType exnType = errorString ? static_cast<JSExnType>(errorString->exnType) : JSEXN_NONE;
|
||||||
MOZ_ASSERT(exnType < JSEXN_LIMIT);
|
MOZ_ASSERT(exnType < JSEXN_LIMIT);
|
||||||
|
|
||||||
|
|
|
@ -76,10 +76,6 @@ js_ReportUncaughtException(JSContext *cx);
|
||||||
extern JSErrorReport *
|
extern JSErrorReport *
|
||||||
js_ErrorFromException(JSContext *cx, js::HandleObject obj);
|
js_ErrorFromException(JSContext *cx, js::HandleObject obj);
|
||||||
|
|
||||||
extern const JSErrorFormatString *
|
|
||||||
js_GetLocalizedErrorMessage(js::ExclusiveContext *cx, void *userRef, const char *locale,
|
|
||||||
const unsigned errorNumber);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make a copy of errobj parented to cx's compartment's global.
|
* Make a copy of errobj parented to cx's compartment's global.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1242,7 +1242,7 @@ typedef enum JSErrNum {
|
||||||
} JSErrNum;
|
} JSErrNum;
|
||||||
|
|
||||||
extern JS_FRIEND_API(const JSErrorFormatString *)
|
extern JS_FRIEND_API(const JSErrorFormatString *)
|
||||||
js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber);
|
js_GetErrorMessage(void *userRef, const unsigned errorNumber);
|
||||||
|
|
||||||
namespace js {
|
namespace js {
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ NewGlobalObject(JSContext *cx, JS::CompartmentOptions &options,
|
||||||
JSPrincipals *principals);
|
JSPrincipals *principals);
|
||||||
|
|
||||||
static const JSErrorFormatString *
|
static const JSErrorFormatString *
|
||||||
my_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber);
|
my_GetErrorMessage(void *userRef, const unsigned errorNumber);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5115,7 +5115,7 @@ static const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JSErrorFormatString *
|
static const JSErrorFormatString *
|
||||||
my_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber)
|
my_GetErrorMessage(void *userRef, const unsigned errorNumber)
|
||||||
{
|
{
|
||||||
if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
|
if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -120,8 +120,7 @@ js::intrinsic_ThrowError(JSContext *cx, unsigned argc, Value *vp)
|
||||||
uint32_t errorNumber = args[0].toInt32();
|
uint32_t errorNumber = args[0].toInt32();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
const JSErrorFormatString *efs =
|
const JSErrorFormatString *efs = js_GetErrorMessage(nullptr, errorNumber);
|
||||||
js_GetLocalizedErrorMessage(cx, nullptr, nullptr, errorNumber);
|
|
||||||
JS_ASSERT(efs->argCount == args.length() - 1);
|
JS_ASSERT(efs->argCount == args.length() - 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ struct XPCLocaleCallbacks : public JSLocaleCallbacks
|
||||||
localeToLowerCase = LocaleToLowerCase;
|
localeToLowerCase = LocaleToLowerCase;
|
||||||
localeCompare = LocaleCompare;
|
localeCompare = LocaleCompare;
|
||||||
localeToUnicode = LocaleToUnicode;
|
localeToUnicode = LocaleToUnicode;
|
||||||
localeGetErrorMessage = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~XPCLocaleCallbacks()
|
~XPCLocaleCallbacks()
|
||||||
|
|
|
@ -881,7 +881,7 @@ static const JSErrorFormatString jsShell_ErrorFormatString[JSShellErr_Limit] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const JSErrorFormatString *
|
static const JSErrorFormatString *
|
||||||
my_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber)
|
my_GetErrorMessage(void *userRef, const unsigned errorNumber)
|
||||||
{
|
{
|
||||||
if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
|
if (errorNumber == 0 || errorNumber >= JSShellErr_Limit)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче