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.
11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
19 #include "nsCycleCollectionParticipant.h"
21 #include "nsIDOMDOMException.h"
22 #include "nsWrapperCache.h"
23 #include "xpcexception.h"
30 NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult
, nsACString
& aName
,
32 uint16_t* aCode
= nullptr);
39 #define MOZILLA_EXCEPTION_IID \
40 { 0x55eda557, 0xeba0, 0x4fe3, \
41 { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } }
43 class Exception
: public nsIXPCException
,
47 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID
)
49 NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID
)
51 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception
)
53 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
55 NS_DECL_NSIXPCEXCEPTION
57 // Cruft used by XPConnect for exceptions originating in JS implemented
59 bool StealJSVal(JS::Value
* aVp
);
60 void StowJSVal(JS::Value
& aVp
);
63 virtual JSObject
* WrapObject(JSContext
* cx
)
66 nsISupports
* GetParentObject() const { return nullptr; }
68 void GetMessageMoz(nsString
& retval
);
70 uint32_t Result() const;
72 void GetName(nsString
& retval
);
74 // The XPCOM GetFilename does the right thing. It might throw, but we want to
75 // return an empty filename in that case anyway, instead of throwing.
77 uint32_t LineNumber() const;
79 uint32_t ColumnNumber() const;
81 already_AddRefed
<nsIStackFrame
> GetLocation() const;
83 already_AddRefed
<nsISupports
> GetInner() const;
85 already_AddRefed
<nsISupports
> GetData() const;
87 void GetStack(nsAString
& aStack
, ErrorResult
& aRv
) const;
89 void Stringify(nsString
& retval
);
91 // XPCOM factory ctor.
94 Exception(const nsACString
& aMessage
,
96 const nsACString
& aName
,
97 nsIStackFrame
*aLocation
,
101 virtual ~Exception();
106 nsCOMPtr
<nsIStackFrame
> mLocation
;
107 nsCOMPtr
<nsISupports
> mData
;
110 nsCOMPtr
<nsIException
> mInner
;
114 JS::Heap
<JS::Value
> mThrownJSVal
;
117 static bool sEverMadeOneFromFactory
;
120 NS_DEFINE_STATIC_IID_ACCESSOR(Exception
, MOZILLA_EXCEPTION_IID
)
122 class DOMException
: public Exception
,
123 public nsIDOMDOMException
126 DOMException(nsresult aRv
, const nsACString
& aMessage
,
127 const nsACString
& aName
, uint16_t aCode
);
129 NS_DECL_ISUPPORTS_INHERITED
130 NS_DECL_NSIDOMDOMEXCEPTION
132 // nsIException overrides
133 NS_IMETHOD
ToString(nsACString
& aReturn
) MOZ_OVERRIDE
;
135 // nsWrapperCache overrides
136 virtual JSObject
* WrapObject(JSContext
* aCx
)
139 uint16_t Code() const {
143 // Intentionally shadow the nsXPCException version.
144 void GetMessageMoz(nsString
& retval
);
145 void GetName(nsString
& retval
);
147 static already_AddRefed
<DOMException
>
148 Create(nsresult aRv
);
152 virtual ~DOMException() {}
161 } // namespace mozilla
164 #pragma GCC diagnostic pop