diff --git a/mozilla/dom/macbuild/dom_rangeIDL.xml b/mozilla/dom/macbuild/dom_rangeIDL.xml
index 8e1b99d4897..38a064155b2 100644
--- a/mozilla/dom/macbuild/dom_rangeIDL.xml
+++ b/mozilla/dom/macbuild/dom_rangeIDL.xml
@@ -731,6 +731,13 @@
Text
+
+ Name
+ nsIDOMRangeException.idl
+ MacOS
+ Text
+
+
@@ -748,6 +755,11 @@
nsIDOMRange.idl
MacOS
+
+ Name
+ nsIDOMRangeException.idl
+ MacOS
+
@@ -1428,6 +1440,13 @@
Text
+
+ Name
+ nsIDOMRangeException.idl
+ MacOS
+ Text
+
+
@@ -1445,6 +1464,11 @@
nsIDOMRange.idl
MacOS
+
+ Name
+ nsIDOMRangeException.idl
+ MacOS
+
@@ -1473,6 +1497,12 @@
nsIDOMRange.idl
MacOS
+
+ headers
+ Name
+ nsIDOMRangeException.idl
+ MacOS
+
diff --git a/mozilla/dom/public/MANIFEST b/mozilla/dom/public/MANIFEST
index 79aa3fd2500..714a1d341e9 100644
--- a/mozilla/dom/public/MANIFEST
+++ b/mozilla/dom/public/MANIFEST
@@ -33,3 +33,4 @@ nsIScriptNameSpaceManager.h
nsDOMError.h
nsIJSEventListener.h
nsIDOMClassInfo.h
+nsIBaseDOMException.h
diff --git a/mozilla/dom/public/Makefile.in b/mozilla/dom/public/Makefile.in
index 1fe3e7b8e84..10c15142d1b 100644
--- a/mozilla/dom/public/Makefile.in
+++ b/mozilla/dom/public/Makefile.in
@@ -48,6 +48,7 @@ EXPORTS=nsIScriptContext.h \
nsDOMError.h \
nsIJSEventListener.h \
nsIDOMClassInfo.h \
+ nsIBaseDOMException.h \
$(NULL)
include $(topsrcdir)/config/rules.mk
diff --git a/mozilla/dom/public/idl/range/MANIFEST_IDL b/mozilla/dom/public/idl/range/MANIFEST_IDL
index 70d28124d68..3d397e82dad 100644
--- a/mozilla/dom/public/idl/range/MANIFEST_IDL
+++ b/mozilla/dom/public/idl/range/MANIFEST_IDL
@@ -1,3 +1,4 @@
nsIDOMDocumentRange.idl
nsIDOMNSRange.idl
nsIDOMRange.idl
+nsIDOMRangeException.idl
diff --git a/mozilla/dom/public/idl/range/Makefile.in b/mozilla/dom/public/idl/range/Makefile.in
index daf15bf3d71..555f77f34cd 100644
--- a/mozilla/dom/public/idl/range/Makefile.in
+++ b/mozilla/dom/public/idl/range/Makefile.in
@@ -33,6 +33,7 @@ XPIDLSRCS = \
nsIDOMDocumentRange.idl \
nsIDOMNSRange.idl \
nsIDOMRange.idl \
+ nsIDOMRangeException.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk
diff --git a/mozilla/dom/public/idl/range/makefile.win b/mozilla/dom/public/idl/range/makefile.win
index b21c1520264..1d15ccd1950 100644
--- a/mozilla/dom/public/idl/range/makefile.win
+++ b/mozilla/dom/public/idl/range/makefile.win
@@ -28,6 +28,7 @@ XPIDLSRCS = \
.\nsIDOMDocumentRange.idl \
.\nsIDOMNSRange.idl \
.\nsIDOMRange.idl \
+ .\nsIDOMRangeException.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>
diff --git a/mozilla/dom/public/idl/range/nsIDOMRangeException.idl b/mozilla/dom/public/idl/range/nsIDOMRangeException.idl
new file mode 100644
index 00000000000..9840f8207d4
--- /dev/null
+++ b/mozilla/dom/public/idl/range/nsIDOMRangeException.idl
@@ -0,0 +1,54 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Peter Van der Beken (original author)
+ *
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * The complete Range spec is located at:
+ * http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
+ */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(0f807301-39d2-11d6-a7f2-8f504ff870dc)]
+interface nsIDOMRangeException : nsISupports
+{
+ const unsigned short BAD_BOUNDARYPOINTS_ERR = 1;
+ const unsigned short INVALID_NODE_TYPE_ERR = 2;
+
+ readonly attribute unsigned short code;
+};
diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win
index 18e73b0e9e7..21bcfbfa251 100644
--- a/mozilla/dom/public/makefile.win
+++ b/mozilla/dom/public/makefile.win
@@ -46,6 +46,7 @@ EXPORTS=nsIScriptContext.h \
nsDOMError.h \
nsIJSEventListener.h \
nsIDOMClassInfo.h \
+ nsIBaseDOMException.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>
diff --git a/mozilla/dom/public/nsDOMError.h b/mozilla/dom/public/nsDOMError.h
index 14b47619062..165e3a02ff4 100644
--- a/mozilla/dom/public/nsDOMError.h
+++ b/mozilla/dom/public/nsDOMError.h
@@ -67,10 +67,8 @@
/* DOM error codes from http://www.w3.org/TR/DOM-Level-2/range.html */
-// Note! These should have their own error MODULE and correct codes
-// (101 should be 1, 102 should be 2)
-#define NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,101)
-#define NS_ERROR_DOM_RANGE_INVALID_NODE_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,102)
+#define NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_RANGE, 1)
+#define NS_ERROR_DOM_RANGE_INVALID_NODE_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_RANGE, 2)
/* DOM error codes defined by us */
@@ -90,13 +88,4 @@
#define NS_ERROR_DOM_BAD_URI NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,1012)
#define NS_ERROR_DOM_RETVAL_UNDEFINED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM,1013)
-// XXX Not the right place for this.
-#include "nsIDOMDOMException.h"
-
-extern "C" nsresult NS_NewDOMException(nsIDOMDOMException** aException,
- nsresult aResult,
- const char* aName,
- const char* aMessage,
- const char* aLocation);
-
#endif // nsDOMError_h__
diff --git a/mozilla/dom/public/nsIBaseDOMException.h b/mozilla/dom/public/nsIBaseDOMException.h
new file mode 100644
index 00000000000..e64d9f8eb59
--- /dev/null
+++ b/mozilla/dom/public/nsIBaseDOMException.h
@@ -0,0 +1,128 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Peter Van der Beken (original author)
+ *
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsIBaseDOMException_h___
+#define nsIBaseDOMException_h___
+
+#include "nsIDOMClassInfo.h"
+
+// {1f13b201-39fa-11d6-a7f2-df501ff820dc}
+#define NS_BASE_DOM_EXCEPTION_CID \
+{ 0x1f13b201, 0x39fa, 0x11d6, \
+{ 0xa7, 0xf2, 0xdf, 0x50, 0x1f, 0xf8, 0x20, 0xdc } }
+
+// {731d9701-39f8-11d6-a7f2-b39073384c9c}
+#define NS_IBASEDOMEXCEPTION_IID \
+{ 0x731d9701, 0x39f8, 0x11d6, \
+{ 0xa7, 0xf2, 0xb3, 0x90, 0x73, 0x38, 0x4c, 0x9c } }
+
+class nsIBaseDOMException : public nsISupports {
+public:
+ NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBASEDOMEXCEPTION_IID)
+
+ NS_IMETHOD Init(nsresult aNSResult, const char* aName,
+ const char* aMessage,
+ nsIException* aDefaultException) = 0;
+};
+
+
+#define IMPL_DOM_EXCEPTION_HEAD(classname, ifname) \
+class classname : public nsIException, \
+ public ifname \
+{ \
+public: \
+ classname(nsIException* aInner); \
+ virtual ~classname(); \
+ \
+ NS_DECL_ISUPPORTS \
+ NS_FORWARD_NSIEXCEPTION(mBase->)
+
+// Note: the exception implemented by this macro doesn't free the pointers
+// it gets from the mapping_function and assumes they will be valid
+// as long as the exception object is alive.
+
+#define IMPL_DOM_EXCEPTION_TAIL(classname, ifname, domname, module, \
+ mapping_function) \
+private: \
+ nsCOMPtr mBase; \
+}; \
+ \
+classname::classname(nsIException* aInner) : mBase(aInner) \
+{ \
+ NS_INIT_ISUPPORTS(); \
+} \
+classname::~classname() {} \
+ \
+NS_IMPL_ADDREF(classname) \
+NS_IMPL_RELEASE(classname) \
+NS_INTERFACE_MAP_BEGIN(classname) \
+ NS_INTERFACE_MAP_ENTRY(nsIException) \
+ NS_INTERFACE_MAP_ENTRY(ifname) \
+ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException) \
+ NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(domname) \
+NS_INTERFACE_MAP_END \
+ \
+NS_DEFINE_CID(kBaseDOMException_CID_##domname, NS_BASE_DOM_EXCEPTION_CID); \
+ \
+nsresult \
+NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
+ nsIException** aException); \
+nsresult \
+NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
+ nsIException** aException) \
+{ \
+ if (!(NS_ERROR_GET_MODULE(aNSResult) == module)) { \
+ NS_WARNING("Trying to create an exception for the wrong error module."); \
+ return NS_ERROR_FAILURE; \
+ } \
+ const char* name; \
+ const char* message; \
+ mapping_function(aNSResult, &name, &message); \
+ nsCOMPtr baseException = \
+ do_CreateInstance(kBaseDOMException_CID_##domname); \
+ NS_ENSURE_TRUE(baseException, NS_ERROR_OUT_OF_MEMORY); \
+ baseException->Init(aNSResult, name, message, aDefaultException); \
+ nsCOMPtr inner = do_QueryInterface(baseException); \
+ *aException = new classname(inner); \
+ NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY); \
+ NS_ADDREF(*aException); \
+ return NS_OK; \
+}
+
+#endif /* nsIBaseDOMException_h___ */
diff --git a/mozilla/dom/public/nsIDOMClassInfo.h b/mozilla/dom/public/nsIDOMClassInfo.h
index daa33cc0c85..bdd2187f1cc 100644
--- a/mozilla/dom/public/nsIDOMClassInfo.h
+++ b/mozilla/dom/public/nsIDOMClassInfo.h
@@ -252,6 +252,8 @@ enum nsDOMClassInfoID {
// RGBColor object used by getComputedStyle
eDOMClassInfo_CSSRGBColor_id,
+ eDOMClassInfo_RangeException_id,
+
// This one better be the last one in this list
eDOMClassInfoIDCount
};
diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp
index b5abfd895dc..e862cf15c10 100644
--- a/mozilla/dom/src/base/nsDOMClassInfo.cpp
+++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp
@@ -96,6 +96,7 @@
// DOM core includes
#include "nsDOMError.h"
+#include "nsIDOMDOMException.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMNamedNodeMap.h"
@@ -254,6 +255,7 @@
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
+#include "nsIDOMRangeException.h"
#include "nsIDOMTreeWalker.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMXULElement.h"
@@ -772,6 +774,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(CSSRGBColor, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
+ NS_DEFINE_CLASSINFO_DATA(RangeException, nsDOMGenericSH,
+ DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
nsIXPConnect *nsDOMClassInfo::sXPConnect = nsnull;
@@ -2034,6 +2038,11 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMAbstractView)
DOM_CLASSINFO_MAP_END
+ DOM_CLASSINFO_MAP_BEGIN(RangeException, nsIDOMRangeException)
+ DOM_CLASSINFO_MAP_ENTRY(nsIDOMRangeException)
+ DOM_CLASSINFO_MAP_ENTRY(nsIException)
+ DOM_CLASSINFO_MAP_END
+
#ifdef NS_DEBUG
{
PRUint32 i = sizeof(sClassInfoData) / sizeof(sClassInfoData[0]);
diff --git a/mozilla/dom/src/base/nsDOMException.cpp b/mozilla/dom/src/base/nsDOMException.cpp
index 10019b5cbd2..be602d4b24c 100644
--- a/mozilla/dom/src/base/nsDOMException.cpp
+++ b/mozilla/dom/src/base/nsDOMException.cpp
@@ -37,13 +37,16 @@
*
* ***** END LICENSE BLOCK ***** */
-#include "nsIDOMDOMException.h"
-#include "nsDOMError.h"
-#include "nsDOMClassInfo.h"
+#include "nsCOMPtr.h"
#include "nsCRT.h"
+#include "nsDOMClassInfo.h"
+#include "nsDOMError.h"
+#include "nsDOMException.h"
+#include "nsIDOMDOMException.h"
+#include "nsIDOMRangeException.h"
+#include "nsString.h"
#include "prprf.h"
-
#define DOM_MSG_DEF(val, message) {(val), #val, message},
static struct ResultStruct
@@ -58,15 +61,23 @@ static struct ResultStruct
#undef DOM_MSG_DEF
+static void
+NSResultToNameAndMessage(nsresult aNSResult,
+ const char** aName,
+ const char** aMessage);
-static const ResultStruct *
-NSResultToResultStruct(nsresult aNSResult)
+void
+NSResultToNameAndMessage(nsresult aNSResult,
+ const char** aName,
+ const char** aMessage)
{
ResultStruct* result_struct = gDOMErrorMsgMap;
while (result_struct->mName) {
if (aNSResult == result_struct->mNSResult) {
- return result_struct;
+ *aName = result_struct->mName;
+ *aMessage = result_struct->mMessage;
+ return;
}
++result_struct;
@@ -74,92 +85,60 @@ NSResultToResultStruct(nsresult aNSResult)
NS_WARNING("Huh, someone is throwing non-DOM errors using the DOM module!");
- return nsnull;
+ return;
}
-
-class nsDOMException : public nsIException,
- public nsIDOMDOMException
-{
-public:
- nsDOMException(nsresult aNSResult, nsIException* aInner);
- virtual ~nsDOMException();
-
- NS_DECL_ISUPPORTS
+IMPL_INTERNAL_DOM_EXCEPTION_HEAD(nsDOMException, nsIDOMDOMException)
NS_DECL_NSIDOMDOMEXCEPTION
-
- // nsIException
- NS_DECL_NSIEXCEPTION
-
-protected:
- nsresult mResult;
- nsCOMPtr mInner;
-};
-
-nsresult
-NS_NewDOMException(nsresult aNSResult, nsIException* aDefaultException,
- nsIException** aException)
-{
- *aException = new nsDOMException(aNSResult, aDefaultException);
- NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY);
-
- NS_ADDREF(*aException);
-
- return NS_OK;
-}
-
-
-nsDOMException::nsDOMException(nsresult aNSResult, nsIException* aInner)
- : mResult(aNSResult), mInner(aInner)
-{
- NS_INIT_ISUPPORTS();
-}
-
-nsDOMException::~nsDOMException()
-{
-}
-
-// XPConnect interface list for nsDOMException
-NS_CLASSINFO_MAP_BEGIN(DOMException)
- NS_CLASSINFO_MAP_ENTRY(nsIException)
- NS_CLASSINFO_MAP_ENTRY(nsIDOMDOMException)
-NS_CLASSINFO_MAP_END
-
-
-// QueryInterface implementation for nsDOMException
-NS_INTERFACE_MAP_BEGIN(nsDOMException)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
- NS_INTERFACE_MAP_ENTRY(nsIException)
- NS_INTERFACE_MAP_ENTRY(nsIDOMDOMException)
- NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMException)
-NS_INTERFACE_MAP_END
-
-
-NS_IMPL_ADDREF(nsDOMException)
-NS_IMPL_RELEASE(nsDOMException)
-
+IMPL_INTERNAL_DOM_EXCEPTION_TAIL(nsDOMException, nsIDOMDOMException,
+ DOMException, NS_ERROR_MODULE_DOM,
+ NSResultToNameAndMessage)
NS_IMETHODIMP
nsDOMException::GetCode(PRUint32* aCode)
{
- if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM) {
- *aCode = NS_ERROR_GET_CODE(mResult);
- } else {
- NS_WARNING("Non DOM nsresult passed to a DOM exception!");
-
- *aCode = (PRUint32)mResult;
- }
+ NS_ENSURE_ARG_POINTER(aCode);
+ nsresult result;
+ GetResult(&result);
+ *aCode = NS_ERROR_GET_CODE(result);
return NS_OK;
}
-NS_IMETHODIMP
-nsDOMException::GetMessage(char **aMessage)
-{
- const ResultStruct *rs = NSResultToResultStruct(mResult);
+IMPL_INTERNAL_DOM_EXCEPTION_HEAD(nsRangeException, nsIDOMRangeException)
+ NS_DECL_NSIDOMRANGEEXCEPTION
+IMPL_INTERNAL_DOM_EXCEPTION_TAIL(nsRangeException, nsIDOMRangeException,
+ RangeException, NS_ERROR_MODULE_DOM_RANGE,
+ NSResultToNameAndMessage)
- if (rs) {
- *aMessage = nsCRT::strdup(rs->mMessage);
+NS_IMETHODIMP
+nsRangeException::GetCode(PRUint16* aCode)
+{
+ NS_ENSURE_ARG_POINTER(aCode);
+ nsresult result;
+ GetResult(&result);
+ *aCode = NS_ERROR_GET_CODE(result);
+
+ return NS_OK;
+}
+
+
+nsBaseDOMException::nsBaseDOMException()
+{
+ NS_INIT_ISUPPORTS();
+}
+
+nsBaseDOMException::~nsBaseDOMException()
+{
+}
+
+NS_IMPL_ISUPPORTS2(nsBaseDOMException, nsIException, nsIBaseDOMException);
+
+NS_IMETHODIMP
+nsBaseDOMException::GetMessage(char **aMessage)
+{
+ if (mMessage) {
+ *aMessage = nsCRT::strdup(mMessage);
} else {
*aMessage = nsnull;
}
@@ -168,7 +147,7 @@ nsDOMException::GetMessage(char **aMessage)
}
NS_IMETHODIMP
-nsDOMException::GetResult(PRUint32* aResult)
+nsBaseDOMException::GetResult(PRUint32* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
@@ -178,14 +157,12 @@ nsDOMException::GetResult(PRUint32* aResult)
}
NS_IMETHODIMP
-nsDOMException::GetName(char **aName)
+nsBaseDOMException::GetName(char **aName)
{
NS_ENSURE_ARG_POINTER(aName);
- const ResultStruct *rs = NSResultToResultStruct(mResult);
-
- if (rs) {
- *aName = nsCRT::strdup(rs->mName);
+ if (mName) {
+ *aName = nsCRT::strdup(mName);
} else {
*aName = nsnull;
}
@@ -194,7 +171,7 @@ nsDOMException::GetName(char **aName)
}
NS_IMETHODIMP
-nsDOMException::GetFilename(char **aFilename)
+nsBaseDOMException::GetFilename(char **aFilename)
{
if (mInner) {
return mInner->GetFilename(aFilename);
@@ -208,7 +185,7 @@ nsDOMException::GetFilename(char **aFilename)
}
NS_IMETHODIMP
-nsDOMException::GetLineNumber(PRUint32 *aLineNumber)
+nsBaseDOMException::GetLineNumber(PRUint32 *aLineNumber)
{
if (mInner) {
return mInner->GetLineNumber(aLineNumber);
@@ -222,7 +199,7 @@ nsDOMException::GetLineNumber(PRUint32 *aLineNumber)
}
NS_IMETHODIMP
-nsDOMException::GetColumnNumber(PRUint32 *aColumnNumber)
+nsBaseDOMException::GetColumnNumber(PRUint32 *aColumnNumber)
{
if (mInner) {
return mInner->GetColumnNumber(aColumnNumber);
@@ -236,7 +213,7 @@ nsDOMException::GetColumnNumber(PRUint32 *aColumnNumber)
}
NS_IMETHODIMP
-nsDOMException::GetLocation(nsIStackFrame **aLocation)
+nsBaseDOMException::GetLocation(nsIStackFrame **aLocation)
{
if (mInner) {
return mInner->GetLocation(aLocation);
@@ -250,7 +227,7 @@ nsDOMException::GetLocation(nsIStackFrame **aLocation)
}
NS_IMETHODIMP
-nsDOMException::GetInner(nsIException **aInner)
+nsBaseDOMException::GetInner(nsIException **aInner)
{
NS_ENSURE_ARG_POINTER(aInner);
@@ -260,7 +237,7 @@ nsDOMException::GetInner(nsIException **aInner)
}
NS_IMETHODIMP
-nsDOMException::GetData(nsISupports **aData)
+nsBaseDOMException::GetData(nsISupports **aData)
{
if (mInner) {
return mInner->GetData(aData);
@@ -274,12 +251,10 @@ nsDOMException::GetData(nsISupports **aData)
}
NS_IMETHODIMP
-nsDOMException::ToString(char **aReturn)
+nsBaseDOMException::ToString(char **aReturn)
{
*aReturn = nsnull;
- const ResultStruct *rs = NSResultToResultStruct(mResult);
-
static const char defaultMsg[] = "";
static const char defaultLocation[] = "";
static const char defaultName[] = "";
@@ -310,14 +285,24 @@ nsDOMException::ToString(char **aReturn)
location = defaultLocation;
}
- const char* msg = rs ? rs->mMessage : defaultMsg;
- const char* resultName = rs ? rs->mName : defaultName;
- PRUint32 code;
-
- GetCode(&code);
+ const char* msg = mMessage ? mMessage : defaultMsg;
+ const char* resultName = mName ? mName : defaultName;
+ PRUint32 code = NS_ERROR_GET_CODE(mResult);
*aReturn = PR_smprintf(format, msg, code, mResult, resultName,
location.get());
return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
+
+NS_IMETHODIMP
+nsBaseDOMException::Init(nsresult aNSResult, const char* aName,
+ const char* aMessage,
+ nsIException* aDefaultException)
+{
+ mResult = aNSResult;
+ mName = aName;
+ mMessage = aMessage;
+ mInner = aDefaultException;
+ return NS_OK;
+}
diff --git a/mozilla/dom/src/base/nsDOMException.h b/mozilla/dom/src/base/nsDOMException.h
new file mode 100644
index 00000000000..2e5c0cfee27
--- /dev/null
+++ b/mozilla/dom/src/base/nsDOMException.h
@@ -0,0 +1,112 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Peter Van der Beken (original author)
+ *
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsCOMPtr.h"
+#include "nsIBaseDOMException.h"
+#include "nsIException.h"
+
+class nsBaseDOMException : public nsIException,
+ public nsIBaseDOMException
+{
+public:
+ nsBaseDOMException();
+ virtual ~nsBaseDOMException();
+
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIEXCEPTION
+ NS_IMETHOD Init(nsresult aNSResult, const char* aName,
+ const char* aMessage,
+ nsIException* aDefaultException);
+
+protected:
+ nsresult mResult;
+ const char* mName;
+ const char* mMessage;
+ nsCOMPtr mInner;
+};
+
+#define IMPL_INTERNAL_DOM_EXCEPTION_HEAD(classname, ifname) \
+class classname : public nsBaseDOMException, \
+ public ifname \
+{ \
+public: \
+ classname(); \
+ virtual ~classname(); \
+ \
+ NS_DECL_ISUPPORTS_INHERITED
+
+#define IMPL_INTERNAL_DOM_EXCEPTION_TAIL(classname, ifname, domname, module, \
+ mapping_function) \
+}; \
+ \
+classname::classname() {} \
+classname::~classname() {} \
+ \
+NS_IMPL_ADDREF_INHERITED(classname, nsBaseDOMException) \
+NS_IMPL_RELEASE_INHERITED(classname, nsBaseDOMException) \
+NS_CLASSINFO_MAP_BEGIN(domname) \
+ NS_CLASSINFO_MAP_ENTRY(nsIException) \
+ NS_CLASSINFO_MAP_ENTRY(ifname) \
+NS_CLASSINFO_MAP_END \
+NS_INTERFACE_MAP_BEGIN(classname) \
+ NS_INTERFACE_MAP_ENTRY(ifname) \
+ NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(domname) \
+NS_INTERFACE_MAP_END_INHERITING(nsBaseDOMException) \
+ \
+nsresult \
+NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
+ nsIException** aException); \
+nsresult \
+NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
+ nsIException** aException) \
+{ \
+ if (!(NS_ERROR_GET_MODULE(aNSResult) == module)) { \
+ NS_WARNING("Trying to create an exception for the wrong error module."); \
+ return NS_ERROR_FAILURE; \
+ } \
+ const char* name; \
+ const char* message; \
+ mapping_function(aNSResult, &name, &message); \
+ classname* inst = new classname(); \
+ NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); \
+ inst->Init(aNSResult, name, message, aDefaultException); \
+ *aException = inst; \
+ NS_ADDREF(*aException); \
+ return NS_OK; \
+}
diff --git a/mozilla/dom/src/build/nsDOMFactory.cpp b/mozilla/dom/src/build/nsDOMFactory.cpp
index 9772eb6f6cf..d0867e9159e 100644
--- a/mozilla/dom/src/build/nsDOMFactory.cpp
+++ b/mozilla/dom/src/build/nsDOMFactory.cpp
@@ -47,8 +47,8 @@
#include "nsIObserverService.h"
#include "nsIJSContextStack.h"
#include "nsIExceptionService.h"
-
#include "nsScriptNameSpaceManager.h"
+#include "nsDOMException.h"
extern nsresult NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
nsIScriptContext **aContext);
@@ -64,6 +64,10 @@ extern nsresult NS_NewDOMException(nsresult aResult,
nsIException* aDefaultException,
nsIException** aException);
+extern nsresult NS_NewRangeException(nsresult aResult,
+ nsIException* aDefaultException,
+ nsIException** aException);
+
//////////////////////////////////////////////////////////////////////
@@ -121,6 +125,7 @@ nsDOMSOFactory::nsDOMSOFactory()
if (xs) {
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
+ xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM_RANGE);
}
}
@@ -240,6 +245,9 @@ NS_IMETHODIMP
nsDOMSOFactory::GetException(nsresult result, nsIException *aDefaultException,
nsIException **_retval)
{
+ if (NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM_RANGE) {
+ return NS_NewRangeException(result, aDefaultException, _retval);
+ }
return NS_NewDOMException(result, aDefaultException, _retval);
}
@@ -268,12 +276,18 @@ nsDOMSOFactory::RegisterDOMClassInfo(const char *aName,
//////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSOFactory);
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseDOMException);
static const nsModuleComponentInfo gDOMModuleInfo[] = {
{ "Script Object Factory",
NS_DOM_SCRIPT_OBJECT_FACTORY_CID,
nsnull,
nsDOMSOFactoryConstructor
+ },
+ { "Base DOM Exception",
+ NS_BASE_DOM_EXCEPTION_CID,
+ nsnull,
+ nsBaseDOMExceptionConstructor
}
};
diff --git a/mozilla/extensions/transformiix/source/xpath/nsXPathException.cpp b/mozilla/extensions/transformiix/source/xpath/nsXPathException.cpp
index 8ebd9cb3c4d..a6647c9ede6 100644
--- a/mozilla/extensions/transformiix/source/xpath/nsXPathException.cpp
+++ b/mozilla/extensions/transformiix/source/xpath/nsXPathException.cpp
@@ -40,9 +40,60 @@
#include "nsXPathException.h"
#include "nsCRT.h"
#include "nsIDOMClassInfo.h"
+#include "nsIBaseDOMException.h"
#include "nsString.h"
#include "prprf.h"
+static const char* kInvalidExpressionErrName = "NS_ERROR_DOM_INVALID_EXPRESSION_ERR";
+static const char* kInvalidExpressionErrMessage = NS_ERROR_DOM_INVALID_EXPRESSION_MSG;
+static const char* kTypeErrName = "NS_ERROR_DOM_TYPE_ERR";
+static const char* kTypeErrMessage = NS_ERROR_DOM_TYPE_MSG;
+
+static void
+TXResultToNameAndMessage(nsresult aNSResult,
+ const char** aName,
+ const char** aMessage);
+
+void
+TXResultToNameAndMessage(nsresult aNSResult,
+ const char** aName,
+ const char** aMessage)
+{
+ if (aNSResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) {
+ *aName = kInvalidExpressionErrName;
+ *aMessage = kInvalidExpressionErrMessage;
+ }
+ else if (aNSResult == NS_ERROR_DOM_TYPE_ERR) {
+ *aName = kTypeErrName;
+ *aMessage = kTypeErrMessage;
+ }
+ else {
+ NS_WARNING("Huh, someone is throwing non-XPath DOM errors using the XPath DOM module!");
+ *aName = nsnull;
+ *aMessage = nsnull;
+ }
+
+ return;
+}
+
+
+IMPL_DOM_EXCEPTION_HEAD(nsXPathException, nsIDOMXPathException)
+ NS_DECL_NSIDOMXPATHEXCEPTION
+IMPL_DOM_EXCEPTION_TAIL(nsXPathException, nsIDOMXPathException, XPathException,
+ NS_ERROR_MODULE_DOM_XPATH, TXResultToNameAndMessage)
+
+NS_IMETHODIMP
+nsXPathException::GetCode(PRUint16* aCode)
+{
+ NS_ENSURE_ARG_POINTER(aCode);
+ nsresult result;
+ mBase->GetResult(&result);
+ *aCode = NS_ERROR_GET_CODE(result);
+
+ return NS_OK;
+}
+
+
NS_IMPL_ISUPPORTS1(nsXPathExceptionProvider, nsIExceptionProvider)
nsXPathExceptionProvider::nsXPathExceptionProvider()
@@ -61,222 +112,8 @@ nsXPathExceptionProvider::GetException(nsresult aNSResult,
{
NS_ENSURE_ARG_POINTER(aException);
- *aException = new nsXPathException(aNSResult, aDefaultException);
+ NS_NewXPathException(aNSResult, aDefaultException, aException);
NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY);
- NS_IF_ADDREF(*aException);
-
return NS_OK;
}
-
-NS_IMPL_ADDREF(nsXPathException)
-NS_IMPL_RELEASE(nsXPathException)
-NS_INTERFACE_MAP_BEGIN(nsXPathException)
- NS_INTERFACE_MAP_ENTRY(nsIException)
- NS_INTERFACE_MAP_ENTRY(nsIDOMXPathException)
- NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
- NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(XPathException)
-NS_INTERFACE_MAP_END
-
-nsXPathException::nsXPathException(nsresult aNSResult, nsIException* aInner)
- : mResult(aNSResult),
- mInner(aInner)
-{
- NS_INIT_ISUPPORTS();
-}
-
-nsXPathException::~nsXPathException()
-{
-}
-
-NS_IMETHODIMP
-nsXPathException::GetCode(PRUint16* aCode)
-{
- NS_ENSURE_ARG_POINTER(aCode);
-
- if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_XPATH) {
- *aCode = NS_ERROR_GET_CODE(mResult);
- } else {
- NS_WARNING("Non DOM nsresult passed to a DOM exception!");
-
- *aCode = (PRUint32)mResult;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetMessage(char **aMessage)
-{
- NS_ENSURE_ARG_POINTER(aMessage);
-
- if (mResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) {
- *aMessage = nsCRT::strdup(NS_ERROR_DOM_INVALID_EXPRESSION_MSG);
- }
- else if (mResult == NS_ERROR_DOM_TYPE_ERR) {
- *aMessage = nsCRT::strdup(NS_ERROR_DOM_TYPE_MSG);
- }
- else {
- *aMessage = nsnull;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetResult(PRUint32* aResult)
-{
- NS_ENSURE_ARG_POINTER(aResult);
-
- *aResult = mResult;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetName(char **aName)
-{
- NS_ENSURE_ARG_POINTER(aName);
-
- if (mResult == NS_ERROR_DOM_INVALID_EXPRESSION_ERR) {
- *aName = nsCRT::strdup("NS_ERROR_DOM_INVALID_EXPRESSION_ERR");
- }
- else if (mResult == NS_ERROR_DOM_TYPE_ERR) {
- *aName = nsCRT::strdup("NS_ERROR_DOM_TYPE_ERR");
- }
- else {
- *aName = nsnull;
- }
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetFilename(char **aFilename)
-{
- if (mInner) {
- return mInner->GetFilename(aFilename);
- }
-
- NS_ENSURE_ARG_POINTER(aFilename);
-
- *aFilename = nsnull;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetLineNumber(PRUint32 *aLineNumber)
-{
- if (mInner) {
- return mInner->GetLineNumber(aLineNumber);
- }
-
- NS_ENSURE_ARG_POINTER(aLineNumber);
-
- *aLineNumber = 0;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetColumnNumber(PRUint32 *aColumnNumber)
-{
- if (mInner) {
- return mInner->GetColumnNumber(aColumnNumber);
- }
-
- NS_ENSURE_ARG_POINTER(aColumnNumber);
-
- *aColumnNumber = 0;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetLocation(nsIStackFrame **aLocation)
-{
- if (mInner) {
- return mInner->GetLocation(aLocation);
- }
-
- NS_ENSURE_ARG_POINTER(aLocation);
-
- *aLocation = nsnull;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetInner(nsIException **aInner)
-{
- NS_ENSURE_ARG_POINTER(aInner);
-
- *aInner = nsnull;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::GetData(nsISupports **aData)
-{
- if (mInner) {
- return mInner->GetData(aData);
- }
-
- NS_ENSURE_ARG_POINTER(aData);
-
- *aData = nsnull;
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPathException::ToString(char **aReturn)
-{
- *aReturn = nsnull;
-
- static const char defaultMsg[] = "";
- static const char defaultLocation[] = "";
- static const char defaultName[] = "";
- static const char format[] =
- "[Exception... \"%s\" code: \"%d\" nsresult: \"0x%x (%s)\" location: \"%s\"]";
-
- nsCAutoString location;
-
- if (mInner) {
- nsXPIDLCString filename;
-
- mInner->GetFilename(getter_Copies(filename));
-
- if (!filename.IsEmpty()) {
- PRUint32 line_nr = 0;
-
- mInner->GetLineNumber(&line_nr);
-
- char *temp = PR_smprintf("%s Line: %d", filename.get(), line_nr);
- if (temp) {
- location.Assign(temp);
- PR_smprintf_free(temp);
- }
- }
- }
-
- if (location.IsEmpty()) {
- location = defaultLocation;
- }
-
- char* msg;
- char* resultName;
- PRUint16 code;
-
- GetMessage(&msg);
- GetName(&resultName);
- GetCode(&code);
-
- *aReturn = PR_smprintf(format, (msg ? msg : defaultMsg), code, mResult,
- (resultName ? resultName : defaultName), location.get());
-
- return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
-}
-
diff --git a/mozilla/extensions/transformiix/source/xpath/nsXPathException.h b/mozilla/extensions/transformiix/source/xpath/nsXPathException.h
index 66f8a1622fb..67f767b33d0 100644
--- a/mozilla/extensions/transformiix/source/xpath/nsXPathException.h
+++ b/mozilla/extensions/transformiix/source/xpath/nsXPathException.h
@@ -66,28 +66,4 @@ public:
NS_DECL_NSIEXCEPTIONPROVIDER
};
-/**
- * A class for evaluating an XPath expression string
- */
-class nsXPathException : public nsIException,
- public nsIDOMXPathException
-{
-public:
- nsXPathException(nsresult aNSResult, nsIException* aInner);
- virtual ~nsXPathException();
-
- // nsISupports interface
- NS_DECL_ISUPPORTS
-
- // nsIException interface
- NS_DECL_NSIEXCEPTION
-
- // nsIDOMXPathException interface
- NS_DECL_NSIDOMXPATHEXCEPTION
-
-private:
- nsresult mResult;
- nsCOMPtr mInner;
-};
-
#endif
diff --git a/mozilla/xpcom/base/nsError.h b/mozilla/xpcom/base/nsError.h
index 98963d6cb53..cf11ebd5d02 100644
--- a/mozilla/xpcom/base/nsError.h
+++ b/mozilla/xpcom/base/nsError.h
@@ -87,6 +87,7 @@
#define NS_ERROR_MODULE_LDAP 20
#define NS_ERROR_MODULE_SECURITY 21
#define NS_ERROR_MODULE_DOM_XPATH 22
+#define NS_ERROR_MODULE_DOM_RANGE 23
// NS_ERROR_MODULE_GENERAL should be used by modules that don't
// care if return code values overlap. Callers of methods that
// return such codes should be aware that they are not