Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #ifndef mozilla_dom_DOMException_h__
7 #define mozilla_dom_DOMException_h__
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
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"
26 class nsIStackFrame;
27 class nsString;
29 nsresult
30 NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName,
31 nsACString& aMessage,
32 uint16_t* aCode = nullptr);
34 namespace mozilla {
35 namespace dom {
37 #define MOZILLA_EXCEPTION_IID \
38 { 0x55eda557, 0xeba0, 0x4fe3, \
39 { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } }
41 class Exception : public nsIXPCException,
42 public nsWrapperCache
43 {
44 public:
45 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID)
47 NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID)
49 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception)
51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
52 NS_DECL_NSIEXCEPTION
53 NS_DECL_NSIXPCEXCEPTION
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);
60 // WebIDL API
61 virtual JSObject* WrapObject(JSContext* cx)
62 MOZ_OVERRIDE;
64 nsISupports* GetParentObject() const { return nullptr; }
66 void GetMessageMoz(nsString& retval);
68 uint32_t Result() const;
70 void GetName(nsString& retval);
72 // The XPCOM GetFilename does the right thing.
74 uint32_t LineNumber() const;
76 uint32_t ColumnNumber() const;
78 already_AddRefed<nsIStackFrame> GetLocation() const;
80 already_AddRefed<nsISupports> GetInner() const;
82 already_AddRefed<nsISupports> GetData() const;
84 void Stringify(nsString& retval);
86 // XPCOM factory ctor.
87 Exception();
89 Exception(const nsACString& aMessage,
90 nsresult aResult,
91 const nsACString& aName,
92 nsIStackFrame *aLocation,
93 nsISupports *aData);
95 protected:
96 virtual ~Exception();
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;
108 bool mHoldingJSVal;
109 JS::Heap<JS::Value> mThrownJSVal;
111 private:
112 static bool sEverMadeOneFromFactory;
113 };
115 NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID)
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);
124 NS_DECL_ISUPPORTS_INHERITED
125 NS_DECL_NSIDOMDOMEXCEPTION
127 // nsIException overrides
128 NS_IMETHOD ToString(nsACString& aReturn) MOZ_OVERRIDE;
130 // nsWrapperCache overrides
131 virtual JSObject* WrapObject(JSContext* aCx)
132 MOZ_OVERRIDE;
134 uint16_t Code() const {
135 return mCode;
136 }
138 // Intentionally shadow the nsXPCException version.
139 void GetMessageMoz(nsString& retval);
140 void GetName(nsString& retval);
142 static already_AddRefed<DOMException>
143 Create(nsresult aRv);
145 protected:
147 virtual ~DOMException() {}
149 nsCString mName;
150 nsCString mMessage;
152 uint16_t mCode;
153 };
155 } // namespace dom
156 } // namespace mozilla
158 #ifdef __GNUC__
159 #pragma GCC diagnostic pop
160 #endif
162 #endif