js/xpconnect/src/XPCException.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /* An implementaion of nsIException. */
     9 #include "xpcprivate.h"
    10 #include "nsError.h"
    12 /***************************************************************************/
    13 /* Quick and dirty mapping of well known result codes to strings. We only
    14 *  call this when building an exception object, so iterating the short array
    15 *  is not too bad.
    16 *
    17 *  It sure would be nice to have exceptions declared in idl and available
    18 *  in some more global way at runtime.
    19 */
    21 static const struct ResultMap
    22 {nsresult rv; const char* name; const char* format;} map[] = {
    23 #define XPC_MSG_DEF(val, format) \
    24     {(val), #val, format},
    25 #include "xpc.msg"
    26 #undef XPC_MSG_DEF
    27     {NS_OK,0,0}   // sentinel to mark end of array
    28 };
    30 #define RESULT_COUNT ((sizeof(map) / sizeof(map[0]))-1)
    32 // static
    33 bool
    34 nsXPCException::NameAndFormatForNSResult(nsresult rv,
    35                                          const char** name,
    36                                          const char** format)
    37 {
    39     for (const ResultMap* p = map; p->name; p++) {
    40         if (rv == p->rv) {
    41             if (name) *name = p->name;
    42             if (format) *format = p->format;
    43             return true;
    44         }
    45     }
    46     return false;
    47 }
    49 // static
    50 const void*
    51 nsXPCException::IterateNSResults(nsresult* rv,
    52                                  const char** name,
    53                                  const char** format,
    54                                  const void** iterp)
    55 {
    56     const ResultMap* p = (const ResultMap*) *iterp;
    57     if (!p)
    58         p = map;
    59     else
    60         p++;
    61     if (!p->name)
    62         p = nullptr;
    63     else {
    64         if (rv)
    65             *rv = p->rv;
    66         if (name)
    67             *name = p->name;
    68         if (format)
    69             *format = p->format;
    70     }
    71     *iterp = p;
    72     return p;
    73 }
    75 // static
    76 uint32_t
    77 nsXPCException::GetNSResultCount()
    78 {
    79     return RESULT_COUNT;
    80 }

mercurial