Line data Source code
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/. */
6 :
7 : /* An implementaion of nsIException. */
8 :
9 : #include "xpcprivate.h"
10 : #include "nsError.h"
11 :
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 : */
20 :
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 : };
29 :
30 : #define RESULT_COUNT ((sizeof(map) / sizeof(map[0]))-1)
31 :
32 : // static
33 : bool
34 3960 : nsXPCException::NameAndFormatForNSResult(nsresult rv,
35 : const char** name,
36 : const char** format)
37 : {
38 :
39 374983 : for (const ResultMap* p = map; p->name; p++) {
40 373080 : if (rv == p->rv) {
41 2057 : if (name) *name = p->name;
42 2057 : if (format) *format = p->format;
43 2057 : return true;
44 : }
45 : }
46 1903 : return false;
47 : }
48 :
49 : // static
50 : const void*
51 2090 : nsXPCException::IterateNSResults(nsresult* rv,
52 : const char** name,
53 : const char** format,
54 : const void** iterp)
55 : {
56 2090 : const ResultMap* p = (const ResultMap*) *iterp;
57 2090 : if (!p)
58 11 : p = map;
59 : else
60 2079 : p++;
61 2090 : if (!p->name)
62 11 : p = nullptr;
63 : else {
64 2079 : if (rv)
65 2079 : *rv = p->rv;
66 2079 : if (name)
67 2079 : *name = p->name;
68 2079 : if (format)
69 0 : *format = p->format;
70 : }
71 2090 : *iterp = p;
72 2090 : return p;
73 : }
74 :
75 : // static
76 : uint32_t
77 0 : nsXPCException::GetNSResultCount()
78 : {
79 0 : return RESULT_COUNT;
80 : }
|