Bumping manifests a=b2g-bump
[gecko.git] / dom / base / DOMException.h
blob9e8ce08d545522e3027f22b3ff51f0a0d99fd214
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 class ErrorResult;
37 namespace dom {
39 #define MOZILLA_EXCEPTION_IID \
40 { 0x55eda557, 0xeba0, 0x4fe3, \
41 { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } }
43 class Exception : public nsIXPCException,
44 public nsWrapperCache
46 public:
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
54 NS_DECL_NSIEXCEPTION
55 NS_DECL_NSIXPCEXCEPTION
57 // Cruft used by XPConnect for exceptions originating in JS implemented
58 // components.
59 bool StealJSVal(JS::Value* aVp);
60 void StowJSVal(JS::Value& aVp);
62 // WebIDL API
63 virtual JSObject* WrapObject(JSContext* cx)
64 MOZ_OVERRIDE;
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.
92 Exception();
94 Exception(const nsACString& aMessage,
95 nsresult aResult,
96 const nsACString& aName,
97 nsIStackFrame *aLocation,
98 nsISupports *aData);
100 protected:
101 virtual ~Exception();
103 nsCString mMessage;
104 nsresult mResult;
105 nsCString mName;
106 nsCOMPtr<nsIStackFrame> mLocation;
107 nsCOMPtr<nsISupports> mData;
108 nsString mFilename;
109 int mLineNumber;
110 nsCOMPtr<nsIException> mInner;
111 bool mInitialized;
113 bool mHoldingJSVal;
114 JS::Heap<JS::Value> mThrownJSVal;
116 private:
117 static bool sEverMadeOneFromFactory;
120 NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID)
122 class DOMException : public Exception,
123 public nsIDOMDOMException
125 public:
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)
137 MOZ_OVERRIDE;
139 uint16_t Code() const {
140 return mCode;
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);
150 protected:
152 virtual ~DOMException() {}
154 nsCString mName;
155 nsCString mMessage;
157 uint16_t mCode;
160 } // namespace dom
161 } // namespace mozilla
163 #ifdef __GNUC__
164 #pragma GCC diagnostic pop
165 #endif
167 #endif