js/xpconnect/src/XPCException.cpp

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial