Bug 743049 - Part 1: Add a friend API to get an error type name from a number. r=luke

This commit is contained in:
Masatoshi Kimura 2012-04-11 17:55:22 -04:00
parent 8152b2083e
commit 5ca99795f4
2 changed files with 30 additions and 0 deletions

View File

@ -1096,6 +1096,27 @@ js_GetLocalizedErrorMessage(JSContext* cx, void *userRef, const char *locale,
return errorString;
}
namespace js {
JS_FRIEND_API(const jschar*)
GetErrorTypeNameFromNumber(JSContext* cx, const unsigned errorNumber)
{
const JSErrorFormatString *efs = js_GetErrorMessage(NULL, NULL, errorNumber);
/*
* JSEXN_INTERNALERR returns null to prevent that "InternalError: "
* is prepended before "uncaught exception: "
*/
if (!efs || efs->exnType <= JSEXN_NONE || efs->exnType >= JSEXN_LIMIT ||
efs->exnType == JSEXN_INTERNALERR)
{
return NULL;
}
JSProtoKey key = GetExceptionProtoKey(efs->exnType);
return cx->runtime->atomState.classAtoms[key]->chars();
}
} /* namespace js */
#if defined ( DEBUG_mccabe ) && defined ( PRINTNAMES )
/* For use below... get character strings for error name and exception name */
static struct exnname { char *name; char *exception; } errortoexnname[] = {

View File

@ -792,6 +792,15 @@ CastToJSFreeOp(FreeOp *fop)
return reinterpret_cast<JSFreeOp *>(fop);
}
/* Implemented in jsexn.cpp. */
/*
* Get an error type name from a number.
* If no exception is associated, return NULL.
*/
extern JS_FRIEND_API(const jschar*)
GetErrorTypeNameFromNumber(JSContext* cx, const unsigned errorNumber);
} /* namespace js */
#endif