|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_dom_DOMException_h__ |
|
7 #define mozilla_dom_DOMException_h__ |
|
8 |
|
9 // We intentionally shadow non-virtual methods, but gcc gets confused. |
|
10 #ifdef __GNUC__ |
|
11 #pragma GCC diagnostic push |
|
12 #pragma GCC diagnostic ignored "-Woverloaded-virtual" |
|
13 #endif |
|
14 |
|
15 #include <stdint.h> |
|
16 #include "jspubtd.h" |
|
17 #include "js/GCAPI.h" |
|
18 #include "nsCOMPtr.h" |
|
19 #include "nsCycleCollectionParticipant.h" |
|
20 #include "nsID.h" |
|
21 #include "nsIDOMDOMException.h" |
|
22 #include "nsWrapperCache.h" |
|
23 #include "xpcexception.h" |
|
24 #include "nsString.h" |
|
25 |
|
26 class nsIStackFrame; |
|
27 class nsString; |
|
28 |
|
29 nsresult |
|
30 NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName, |
|
31 nsACString& aMessage, |
|
32 uint16_t* aCode = nullptr); |
|
33 |
|
34 namespace mozilla { |
|
35 namespace dom { |
|
36 |
|
37 #define MOZILLA_EXCEPTION_IID \ |
|
38 { 0x55eda557, 0xeba0, 0x4fe3, \ |
|
39 { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } } |
|
40 |
|
41 class Exception : public nsIXPCException, |
|
42 public nsWrapperCache |
|
43 { |
|
44 public: |
|
45 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID) |
|
46 |
|
47 NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID) |
|
48 |
|
49 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception) |
|
50 |
|
51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
52 NS_DECL_NSIEXCEPTION |
|
53 NS_DECL_NSIXPCEXCEPTION |
|
54 |
|
55 // Cruft used by XPConnect for exceptions originating in JS implemented |
|
56 // components. |
|
57 bool StealJSVal(JS::Value* aVp); |
|
58 void StowJSVal(JS::Value& aVp); |
|
59 |
|
60 // WebIDL API |
|
61 virtual JSObject* WrapObject(JSContext* cx) |
|
62 MOZ_OVERRIDE; |
|
63 |
|
64 nsISupports* GetParentObject() const { return nullptr; } |
|
65 |
|
66 void GetMessageMoz(nsString& retval); |
|
67 |
|
68 uint32_t Result() const; |
|
69 |
|
70 void GetName(nsString& retval); |
|
71 |
|
72 // The XPCOM GetFilename does the right thing. |
|
73 |
|
74 uint32_t LineNumber() const; |
|
75 |
|
76 uint32_t ColumnNumber() const; |
|
77 |
|
78 already_AddRefed<nsIStackFrame> GetLocation() const; |
|
79 |
|
80 already_AddRefed<nsISupports> GetInner() const; |
|
81 |
|
82 already_AddRefed<nsISupports> GetData() const; |
|
83 |
|
84 void Stringify(nsString& retval); |
|
85 |
|
86 // XPCOM factory ctor. |
|
87 Exception(); |
|
88 |
|
89 Exception(const nsACString& aMessage, |
|
90 nsresult aResult, |
|
91 const nsACString& aName, |
|
92 nsIStackFrame *aLocation, |
|
93 nsISupports *aData); |
|
94 |
|
95 protected: |
|
96 virtual ~Exception(); |
|
97 |
|
98 nsCString mMessage; |
|
99 nsresult mResult; |
|
100 nsCString mName; |
|
101 nsCOMPtr<nsIStackFrame> mLocation; |
|
102 nsCOMPtr<nsISupports> mData; |
|
103 nsString mFilename; |
|
104 int mLineNumber; |
|
105 nsCOMPtr<nsIException> mInner; |
|
106 bool mInitialized; |
|
107 |
|
108 bool mHoldingJSVal; |
|
109 JS::Heap<JS::Value> mThrownJSVal; |
|
110 |
|
111 private: |
|
112 static bool sEverMadeOneFromFactory; |
|
113 }; |
|
114 |
|
115 NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID) |
|
116 |
|
117 class DOMException : public Exception, |
|
118 public nsIDOMDOMException |
|
119 { |
|
120 public: |
|
121 DOMException(nsresult aRv, const nsACString& aMessage, |
|
122 const nsACString& aName, uint16_t aCode); |
|
123 |
|
124 NS_DECL_ISUPPORTS_INHERITED |
|
125 NS_DECL_NSIDOMDOMEXCEPTION |
|
126 |
|
127 // nsIException overrides |
|
128 NS_IMETHOD ToString(nsACString& aReturn) MOZ_OVERRIDE; |
|
129 |
|
130 // nsWrapperCache overrides |
|
131 virtual JSObject* WrapObject(JSContext* aCx) |
|
132 MOZ_OVERRIDE; |
|
133 |
|
134 uint16_t Code() const { |
|
135 return mCode; |
|
136 } |
|
137 |
|
138 // Intentionally shadow the nsXPCException version. |
|
139 void GetMessageMoz(nsString& retval); |
|
140 void GetName(nsString& retval); |
|
141 |
|
142 static already_AddRefed<DOMException> |
|
143 Create(nsresult aRv); |
|
144 |
|
145 protected: |
|
146 |
|
147 virtual ~DOMException() {} |
|
148 |
|
149 nsCString mName; |
|
150 nsCString mMessage; |
|
151 |
|
152 uint16_t mCode; |
|
153 }; |
|
154 |
|
155 } // namespace dom |
|
156 } // namespace mozilla |
|
157 |
|
158 #ifdef __GNUC__ |
|
159 #pragma GCC diagnostic pop |
|
160 #endif |
|
161 |
|
162 #endif |