michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=99: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* An implementaion of nsIException. */ michael@0: michael@0: #include "xpcprivate.h" michael@0: #include "nsError.h" michael@0: michael@0: /***************************************************************************/ michael@0: /* Quick and dirty mapping of well known result codes to strings. We only michael@0: * call this when building an exception object, so iterating the short array michael@0: * is not too bad. michael@0: * michael@0: * It sure would be nice to have exceptions declared in idl and available michael@0: * in some more global way at runtime. michael@0: */ michael@0: michael@0: static const struct ResultMap michael@0: {nsresult rv; const char* name; const char* format;} map[] = { michael@0: #define XPC_MSG_DEF(val, format) \ michael@0: {(val), #val, format}, michael@0: #include "xpc.msg" michael@0: #undef XPC_MSG_DEF michael@0: {NS_OK,0,0} // sentinel to mark end of array michael@0: }; michael@0: michael@0: #define RESULT_COUNT ((sizeof(map) / sizeof(map[0]))-1) michael@0: michael@0: // static michael@0: bool michael@0: nsXPCException::NameAndFormatForNSResult(nsresult rv, michael@0: const char** name, michael@0: const char** format) michael@0: { michael@0: michael@0: for (const ResultMap* p = map; p->name; p++) { michael@0: if (rv == p->rv) { michael@0: if (name) *name = p->name; michael@0: if (format) *format = p->format; michael@0: return true; michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: // static michael@0: const void* michael@0: nsXPCException::IterateNSResults(nsresult* rv, michael@0: const char** name, michael@0: const char** format, michael@0: const void** iterp) michael@0: { michael@0: const ResultMap* p = (const ResultMap*) *iterp; michael@0: if (!p) michael@0: p = map; michael@0: else michael@0: p++; michael@0: if (!p->name) michael@0: p = nullptr; michael@0: else { michael@0: if (rv) michael@0: *rv = p->rv; michael@0: if (name) michael@0: *name = p->name; michael@0: if (format) michael@0: *format = p->format; michael@0: } michael@0: *iterp = p; michael@0: return p; michael@0: } michael@0: michael@0: // static michael@0: uint32_t michael@0: nsXPCException::GetNSResultCount() michael@0: { michael@0: return RESULT_COUNT; michael@0: }