dom/base/DOMException.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_dom_DOMException_h__
michael@0 7 #define mozilla_dom_DOMException_h__
michael@0 8
michael@0 9 // We intentionally shadow non-virtual methods, but gcc gets confused.
michael@0 10 #ifdef __GNUC__
michael@0 11 #pragma GCC diagnostic push
michael@0 12 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
michael@0 13 #endif
michael@0 14
michael@0 15 #include <stdint.h>
michael@0 16 #include "jspubtd.h"
michael@0 17 #include "js/GCAPI.h"
michael@0 18 #include "nsCOMPtr.h"
michael@0 19 #include "nsCycleCollectionParticipant.h"
michael@0 20 #include "nsID.h"
michael@0 21 #include "nsIDOMDOMException.h"
michael@0 22 #include "nsWrapperCache.h"
michael@0 23 #include "xpcexception.h"
michael@0 24 #include "nsString.h"
michael@0 25
michael@0 26 class nsIStackFrame;
michael@0 27 class nsString;
michael@0 28
michael@0 29 nsresult
michael@0 30 NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, nsACString& aName,
michael@0 31 nsACString& aMessage,
michael@0 32 uint16_t* aCode = nullptr);
michael@0 33
michael@0 34 namespace mozilla {
michael@0 35 namespace dom {
michael@0 36
michael@0 37 #define MOZILLA_EXCEPTION_IID \
michael@0 38 { 0x55eda557, 0xeba0, 0x4fe3, \
michael@0 39 { 0xae, 0x2e, 0xf3, 0x94, 0x49, 0x23, 0x62, 0xd6 } }
michael@0 40
michael@0 41 class Exception : public nsIXPCException,
michael@0 42 public nsWrapperCache
michael@0 43 {
michael@0 44 public:
michael@0 45 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_EXCEPTION_IID)
michael@0 46
michael@0 47 NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCEXCEPTION_CID)
michael@0 48
michael@0 49 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Exception)
michael@0 50
michael@0 51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 52 NS_DECL_NSIEXCEPTION
michael@0 53 NS_DECL_NSIXPCEXCEPTION
michael@0 54
michael@0 55 // Cruft used by XPConnect for exceptions originating in JS implemented
michael@0 56 // components.
michael@0 57 bool StealJSVal(JS::Value* aVp);
michael@0 58 void StowJSVal(JS::Value& aVp);
michael@0 59
michael@0 60 // WebIDL API
michael@0 61 virtual JSObject* WrapObject(JSContext* cx)
michael@0 62 MOZ_OVERRIDE;
michael@0 63
michael@0 64 nsISupports* GetParentObject() const { return nullptr; }
michael@0 65
michael@0 66 void GetMessageMoz(nsString& retval);
michael@0 67
michael@0 68 uint32_t Result() const;
michael@0 69
michael@0 70 void GetName(nsString& retval);
michael@0 71
michael@0 72 // The XPCOM GetFilename does the right thing.
michael@0 73
michael@0 74 uint32_t LineNumber() const;
michael@0 75
michael@0 76 uint32_t ColumnNumber() const;
michael@0 77
michael@0 78 already_AddRefed<nsIStackFrame> GetLocation() const;
michael@0 79
michael@0 80 already_AddRefed<nsISupports> GetInner() const;
michael@0 81
michael@0 82 already_AddRefed<nsISupports> GetData() const;
michael@0 83
michael@0 84 void Stringify(nsString& retval);
michael@0 85
michael@0 86 // XPCOM factory ctor.
michael@0 87 Exception();
michael@0 88
michael@0 89 Exception(const nsACString& aMessage,
michael@0 90 nsresult aResult,
michael@0 91 const nsACString& aName,
michael@0 92 nsIStackFrame *aLocation,
michael@0 93 nsISupports *aData);
michael@0 94
michael@0 95 protected:
michael@0 96 virtual ~Exception();
michael@0 97
michael@0 98 nsCString mMessage;
michael@0 99 nsresult mResult;
michael@0 100 nsCString mName;
michael@0 101 nsCOMPtr<nsIStackFrame> mLocation;
michael@0 102 nsCOMPtr<nsISupports> mData;
michael@0 103 nsString mFilename;
michael@0 104 int mLineNumber;
michael@0 105 nsCOMPtr<nsIException> mInner;
michael@0 106 bool mInitialized;
michael@0 107
michael@0 108 bool mHoldingJSVal;
michael@0 109 JS::Heap<JS::Value> mThrownJSVal;
michael@0 110
michael@0 111 private:
michael@0 112 static bool sEverMadeOneFromFactory;
michael@0 113 };
michael@0 114
michael@0 115 NS_DEFINE_STATIC_IID_ACCESSOR(Exception, MOZILLA_EXCEPTION_IID)
michael@0 116
michael@0 117 class DOMException : public Exception,
michael@0 118 public nsIDOMDOMException
michael@0 119 {
michael@0 120 public:
michael@0 121 DOMException(nsresult aRv, const nsACString& aMessage,
michael@0 122 const nsACString& aName, uint16_t aCode);
michael@0 123
michael@0 124 NS_DECL_ISUPPORTS_INHERITED
michael@0 125 NS_DECL_NSIDOMDOMEXCEPTION
michael@0 126
michael@0 127 // nsIException overrides
michael@0 128 NS_IMETHOD ToString(nsACString& aReturn) MOZ_OVERRIDE;
michael@0 129
michael@0 130 // nsWrapperCache overrides
michael@0 131 virtual JSObject* WrapObject(JSContext* aCx)
michael@0 132 MOZ_OVERRIDE;
michael@0 133
michael@0 134 uint16_t Code() const {
michael@0 135 return mCode;
michael@0 136 }
michael@0 137
michael@0 138 // Intentionally shadow the nsXPCException version.
michael@0 139 void GetMessageMoz(nsString& retval);
michael@0 140 void GetName(nsString& retval);
michael@0 141
michael@0 142 static already_AddRefed<DOMException>
michael@0 143 Create(nsresult aRv);
michael@0 144
michael@0 145 protected:
michael@0 146
michael@0 147 virtual ~DOMException() {}
michael@0 148
michael@0 149 nsCString mName;
michael@0 150 nsCString mMessage;
michael@0 151
michael@0 152 uint16_t mCode;
michael@0 153 };
michael@0 154
michael@0 155 } // namespace dom
michael@0 156 } // namespace mozilla
michael@0 157
michael@0 158 #ifdef __GNUC__
michael@0 159 #pragma GCC diagnostic pop
michael@0 160 #endif
michael@0 161
michael@0 162 #endif

mercurial