1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/DOMException.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_DOMException_h__ 1.10 +#define mozilla_dom_DOMException_h__ 1.11 + 1.12 +// We intentionally shadow non-virtual methods, but gcc gets confused. 1.13 +#ifdef __GNUC__ 1.14 +#pragma GCC diagnostic push 1.15 +#pragma GCC diagnostic ignored "-Woverloaded-virtual" 1.16 +#endif 1.17 + 1.18 +#include <stdint.h> 1.19 +#include "jspubtd.h" 1.20 +#include "js/GCAPI.h" 1.21 +#include "nsCOMPtr.h" 1.22 +#include "nsCycleCollectionParticipant.h" 1.23 +#include "nsID.h" 1.24 +#include "nsIDOMDOMException.h" 1.25 +#include "nsWrapperCache.h" 1.26 +#include "xpcexception.h" 1.27 +#include "nsString.h" 1.28 + 1.29 +class nsIStackFrame; 1.30 +class nsString; 1.31 + 1.32 +nsresult 1.33 +NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName, 1.34 + nsACString& aMessage, 1.35 + uint16_t* aCode = nullptr); 1.36 + 1.37 +namespace mozilla { 1.38 +namespace dom { 1.39 + 1.40 +#define MOZILLA_EXCEPTION_IID \ 1.41 +{ 0x55eda557, 0xeba0, 0x4fe3, \ 1.42 + { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } } 1.43 + 1.44 +class Exception : public nsIXPCException, 1.45 + public nsWrapperCache 1.46 +{ 1.47 +public: 1.48 + NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID) 1.49 + 1.50 + NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID) 1.51 + 1.52 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception) 1.53 + 1.54 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.55 + NS_DECL_NSIEXCEPTION 1.56 + NS_DECL_NSIXPCEXCEPTION 1.57 + 1.58 + // Cruft used by XPConnect for exceptions originating in JS implemented 1.59 + // components. 1.60 + bool StealJSVal(JS::Value* aVp); 1.61 + void StowJSVal(JS::Value& aVp); 1.62 + 1.63 + // WebIDL API 1.64 + virtual JSObject* WrapObject(JSContext* cx) 1.65 + MOZ_OVERRIDE; 1.66 + 1.67 + nsISupports* GetParentObject() const { return nullptr; } 1.68 + 1.69 + void GetMessageMoz(nsString& retval); 1.70 + 1.71 + uint32_t Result() const; 1.72 + 1.73 + void GetName(nsString& retval); 1.74 + 1.75 + // The XPCOM GetFilename does the right thing. 1.76 + 1.77 + uint32_t LineNumber() const; 1.78 + 1.79 + uint32_t ColumnNumber() const; 1.80 + 1.81 + already_AddRefed<nsIStackFrame> GetLocation() const; 1.82 + 1.83 + already_AddRefed<nsISupports> GetInner() const; 1.84 + 1.85 + already_AddRefed<nsISupports> GetData() const; 1.86 + 1.87 + void Stringify(nsString& retval); 1.88 + 1.89 + // XPCOM factory ctor. 1.90 + Exception(); 1.91 + 1.92 + Exception(const nsACString& aMessage, 1.93 + nsresult aResult, 1.94 + const nsACString& aName, 1.95 + nsIStackFrame *aLocation, 1.96 + nsISupports *aData); 1.97 + 1.98 +protected: 1.99 + virtual ~Exception(); 1.100 + 1.101 + nsCString mMessage; 1.102 + nsresult mResult; 1.103 + nsCString mName; 1.104 + nsCOMPtr<nsIStackFrame> mLocation; 1.105 + nsCOMPtr<nsISupports> mData; 1.106 + nsString mFilename; 1.107 + int mLineNumber; 1.108 + nsCOMPtr<nsIException> mInner; 1.109 + bool mInitialized; 1.110 + 1.111 + bool mHoldingJSVal; 1.112 + JS::Heap<JS::Value> mThrownJSVal; 1.113 + 1.114 +private: 1.115 + static bool sEverMadeOneFromFactory; 1.116 +}; 1.117 + 1.118 +NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID) 1.119 + 1.120 +class DOMException : public Exception, 1.121 + public nsIDOMDOMException 1.122 +{ 1.123 +public: 1.124 + DOMException(nsresult aRv, const nsACString& aMessage, 1.125 + const nsACString& aName, uint16_t aCode); 1.126 + 1.127 + NS_DECL_ISUPPORTS_INHERITED 1.128 + NS_DECL_NSIDOMDOMEXCEPTION 1.129 + 1.130 + // nsIException overrides 1.131 + NS_IMETHOD ToString(nsACString& aReturn) MOZ_OVERRIDE; 1.132 + 1.133 + // nsWrapperCache overrides 1.134 + virtual JSObject* WrapObject(JSContext* aCx) 1.135 + MOZ_OVERRIDE; 1.136 + 1.137 + uint16_t Code() const { 1.138 + return mCode; 1.139 + } 1.140 + 1.141 + // Intentionally shadow the nsXPCException version. 1.142 + void GetMessageMoz(nsString& retval); 1.143 + void GetName(nsString& retval); 1.144 + 1.145 + static already_AddRefed<DOMException> 1.146 + Create(nsresult aRv); 1.147 + 1.148 +protected: 1.149 + 1.150 + virtual ~DOMException() {} 1.151 + 1.152 + nsCString mName; 1.153 + nsCString mMessage; 1.154 + 1.155 + uint16_t mCode; 1.156 +}; 1.157 + 1.158 +} // namespace dom 1.159 +} // namespace mozilla 1.160 + 1.161 +#ifdef __GNUC__ 1.162 +#pragma GCC diagnostic pop 1.163 +#endif 1.164 + 1.165 +#endif