/work/obj-fuzz/dist/include/mozilla/dom/DOMException.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 | | #ifndef mozilla_dom_DOMException_h__ |
8 | | #define mozilla_dom_DOMException_h__ |
9 | | |
10 | | // We intentionally shadow non-virtual methods, but gcc gets confused. |
11 | | #ifdef __GNUC__ |
12 | | #pragma GCC diagnostic push |
13 | | #pragma GCC diagnostic ignored "-Woverloaded-virtual" |
14 | | #endif |
15 | | |
16 | | #include <stdint.h> |
17 | | #include "jspubtd.h" |
18 | | #include "nsCOMPtr.h" |
19 | | #include "nsCycleCollectionParticipant.h" |
20 | | #include "nsID.h" |
21 | | #include "nsWrapperCache.h" |
22 | | #include "nsIException.h" |
23 | | #include "nsString.h" |
24 | | #include "mozilla/dom/BindingDeclarations.h" |
25 | | |
26 | | class nsIStackFrame; |
27 | | |
28 | | nsresult |
29 | | NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName, |
30 | | nsACString& aMessage, |
31 | | uint16_t* aCode = nullptr); |
32 | | |
33 | | namespace mozilla { |
34 | | class ErrorResult; |
35 | | |
36 | | namespace dom { |
37 | | |
38 | | class GlobalObject; |
39 | | |
40 | | #define MOZILLA_EXCEPTION_IID \ |
41 | | { 0x55eda557, 0xeba0, 0x4fe3, \ |
42 | | { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } } |
43 | | |
44 | | class Exception : public nsIException, |
45 | | public nsWrapperCache |
46 | | { |
47 | | public: |
48 | | NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID) |
49 | | |
50 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception) |
51 | | |
52 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
53 | | NS_DECL_NSIEXCEPTION |
54 | | |
55 | | const nsCString& GetMessageMoz() const |
56 | 0 | { |
57 | 0 | return mMessage; |
58 | 0 | } |
59 | | nsresult GetResult() const |
60 | 0 | { |
61 | 0 | return mResult; |
62 | 0 | } |
63 | | // DOMException wants different ToString behavior, so allow it to override. |
64 | | virtual void ToString(JSContext* aCx, nsACString& aReturn); |
65 | | |
66 | | |
67 | | // Cruft used by XPConnect for exceptions originating in JS implemented |
68 | | // components. |
69 | | bool StealJSVal(JS::Value* aVp); |
70 | | void StowJSVal(JS::Value& aVp); |
71 | | |
72 | | // WebIDL API |
73 | | virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) |
74 | | override; |
75 | | |
76 | 0 | nsISupports* GetParentObject() const { return nullptr; } |
77 | | |
78 | | void GetMessageMoz(nsString& retval); |
79 | | |
80 | | uint32_t Result() const; |
81 | | |
82 | | void GetName(nsAString& retval); |
83 | | |
84 | | virtual void GetErrorMessage(nsAString& aRetVal) |
85 | | { |
86 | | // Since GetName is non non-virtual and deals with different |
87 | | // member variables in Exception vs. DOMException, have a virtual |
88 | | // method to ensure the right error message creation. |
89 | | nsAutoString name; |
90 | | GetName(name); |
91 | | CreateErrorMessage(name, aRetVal); |
92 | | } |
93 | | |
94 | | void GetFilename(JSContext* aCx, nsAString& aFilename); |
95 | | |
96 | | uint32_t LineNumber(JSContext* aCx) const; |
97 | | |
98 | | uint32_t ColumnNumber() const; |
99 | | |
100 | | already_AddRefed<nsIStackFrame> GetLocation() const; |
101 | | |
102 | | nsISupports* GetData() const; |
103 | | |
104 | | void GetStack(JSContext* aCx, nsAString& aStack) const; |
105 | | |
106 | | void Stringify(JSContext* aCx, nsString& retval); |
107 | | |
108 | | Exception(const nsACString& aMessage, |
109 | | nsresult aResult, |
110 | | const nsACString& aName, |
111 | | nsIStackFrame *aLocation, |
112 | | nsISupports *aData); |
113 | | |
114 | | protected: |
115 | | virtual ~Exception(); |
116 | | |
117 | | void CreateErrorMessage(const nsAString& aName, nsAString& aRetVal) |
118 | | { |
119 | | // Create similar error message as what ErrorReport::init does in jsexn.cpp. |
120 | | if (!aName.IsEmpty() && !mMessage.IsEmpty()) { |
121 | | aRetVal.Assign(aName); |
122 | | aRetVal.AppendLiteral(": "); |
123 | | AppendUTF8toUTF16(mMessage, aRetVal); |
124 | | } else if (!aName.IsEmpty()) { |
125 | | aRetVal.Assign(aName); |
126 | | } else if (!mMessage.IsEmpty()) { |
127 | | CopyUTF8toUTF16(mMessage, aRetVal); |
128 | | } else { |
129 | | aRetVal.Truncate(); |
130 | | } |
131 | | } |
132 | | |
133 | | nsCString mMessage; |
134 | | nsresult mResult; |
135 | | nsCString mName; |
136 | | nsCOMPtr<nsIStackFrame> mLocation; |
137 | | nsCOMPtr<nsISupports> mData; |
138 | | |
139 | | bool mHoldingJSVal; |
140 | | JS::Heap<JS::Value> mThrownJSVal; |
141 | | }; |
142 | | |
143 | | NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID) |
144 | | |
145 | | class DOMException : public Exception |
146 | | { |
147 | | public: |
148 | | DOMException(nsresult aRv, const nsACString& aMessage, |
149 | | const nsACString& aName, uint16_t aCode); |
150 | | |
151 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(DOMException, Exception) |
152 | | |
153 | | // nsWrapperCache overrides |
154 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
155 | | override; |
156 | | |
157 | | static already_AddRefed<DOMException> |
158 | | Constructor(GlobalObject& /* unused */, |
159 | | const nsAString& aMessage, |
160 | | const Optional<nsAString>& aName, |
161 | | ErrorResult& aError); |
162 | | |
163 | 0 | uint16_t Code() const { |
164 | 0 | return mCode; |
165 | 0 | } |
166 | | |
167 | | // Intentionally shadow the Exception version. |
168 | | void GetName(nsString& retval); |
169 | | |
170 | | // Exception overrides |
171 | | void ToString(JSContext* aCx, nsACString& aReturn) override; |
172 | | |
173 | | virtual void GetErrorMessage(nsAString& aRetVal) override |
174 | | { |
175 | | // See the comment in Exception::GetErrorMessage. |
176 | | nsAutoString name; |
177 | | GetName(name); |
178 | | CreateErrorMessage(name, aRetVal); |
179 | | } |
180 | | |
181 | | static already_AddRefed<DOMException> |
182 | | Create(nsresult aRv); |
183 | | |
184 | | static already_AddRefed<DOMException> |
185 | | Create(nsresult aRv, const nsACString& aMessage); |
186 | | |
187 | | protected: |
188 | | |
189 | 0 | virtual ~DOMException() {} |
190 | | |
191 | | uint16_t mCode; |
192 | | }; |
193 | | |
194 | | } // namespace dom |
195 | | } // namespace mozilla |
196 | | |
197 | | #ifdef __GNUC__ |
198 | | #pragma GCC diagnostic pop |
199 | | #endif |
200 | | |
201 | | #endif |