Bug 743049 - Part 1: Add a friend API to get an error type name from a number. r=luke
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 11 Apr 2012 17:55:22 -0400
changeset 95212 b1e86ae73fc524a8350342dd31c585f3b3098be9
parent 95211 10b783e85c1ede51e2731d38308bdd12905b18c0
child 95213 9dbeef29e1cf3a87c0a42585465f9fe5fc879c4d
push id160
push userlsblakk@mozilla.com
push dateFri, 13 Jul 2012 18:18:57 +0000
treeherdermozilla-release@228ba1a111fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs743049
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 743049 - Part 1: Add a friend API to get an error type name from a number. r=luke
js/src/jsexn.cpp
js/src/jsfriendapi.h
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -1091,16 +1091,37 @@ js_GetLocalizedErrorMessage(JSContext* c
         errorString = cx->localeCallbacks
                         ->localeGetErrorMessage(userRef, locale, errorNumber);
     }
     if (!errorString)
         errorString = js_GetErrorMessage(userRef, locale, errorNumber);
     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[] = {
 #define MSG_DEF(name, number, count, exception, format) \
     {#name, #exception},
 #include "js.msg"
 #undef MSG_DEF
 };
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -787,16 +787,25 @@ GetTestingFunctions(JSContext *cx);
  * JSFreeOp.
  */
 inline JSFreeOp *
 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
 
 /* Implemented in jsdate.cpp. */
 
 /*
  * Detect whether the internal date value is NaN.  (Because failure is