2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCRTGlue.h"
|
2012-04-11 14:55:23 -07:00
|
|
|
#include "nsContentUtils.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "nsDOMException.h"
|
|
|
|
#include "nsIDOMDOMException.h"
|
|
|
|
#include "nsIDOMSVGException.h"
|
|
|
|
#include "nsIDOMXPathException.h"
|
2012-04-11 14:55:23 -07:00
|
|
|
#include "nsIDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
#define IMPL_INTERNAL_DOM_EXCEPTION_HEAD(domname) \
|
|
|
|
class ns##domname : public nsBaseDOMException, \
|
|
|
|
public nsIDOM##domname \
|
2007-03-22 10:30:00 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2012-04-11 14:55:21 -07:00
|
|
|
ns##domname(); \
|
|
|
|
virtual ~ns##domname(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
\
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
#define IMPL_INTERNAL_DOM_EXCEPTION_TAIL(domname) \
|
2007-03-22 10:30:00 -07:00
|
|
|
}; \
|
|
|
|
\
|
2012-04-11 14:55:21 -07:00
|
|
|
ns##domname::ns##domname() {} \
|
|
|
|
ns##domname::~ns##domname() {} \
|
2007-03-22 10:30:00 -07:00
|
|
|
\
|
2012-04-11 14:55:21 -07:00
|
|
|
DOMCI_DATA(domname, ns##domname) \
|
2010-01-12 05:08:43 -08:00
|
|
|
\
|
2012-04-11 14:55:21 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(ns##domname, nsBaseDOMException) \
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ns##domname, nsBaseDOMException) \
|
|
|
|
NS_INTERFACE_MAP_BEGIN(ns##domname) \
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOM##domname) \
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(domname) \
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBaseDOMException) \
|
|
|
|
\
|
|
|
|
nsresult \
|
|
|
|
NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
|
2012-04-11 14:55:21 -07:00
|
|
|
nsIException** aException) \
|
2007-03-22 10:30:00 -07:00
|
|
|
{ \
|
|
|
|
const char* name; \
|
|
|
|
const char* message; \
|
2012-04-11 14:55:21 -07:00
|
|
|
PRUint16 code; \
|
|
|
|
NSResultToNameAndMessage(aNSResult, &name, &message, &code); \
|
|
|
|
ns##domname* inst = new ns##domname(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY); \
|
2012-04-11 14:55:21 -07:00
|
|
|
inst->Init(aNSResult, name, message, code, aDefaultException); \
|
2007-03-22 10:30:00 -07:00
|
|
|
*aException = inst; \
|
|
|
|
NS_ADDREF(*aException); \
|
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
enum DOM4ErrorTypeCodeMap {
|
|
|
|
/* DOM4 errors from http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#domexception */
|
|
|
|
IndexSizeError = nsIDOMDOMException::INDEX_SIZE_ERR,
|
|
|
|
HierarchyRequestError = nsIDOMDOMException::HIERARCHY_REQUEST_ERR,
|
|
|
|
WrongDocumentError = nsIDOMDOMException::WRONG_DOCUMENT_ERR,
|
|
|
|
InvalidCharacterError = nsIDOMDOMException::INVALID_CHARACTER_ERR,
|
|
|
|
NoModificationAllowedError = nsIDOMDOMException::NO_MODIFICATION_ALLOWED_ERR,
|
|
|
|
NotFoundError = nsIDOMDOMException::NOT_FOUND_ERR,
|
|
|
|
NotSupportedError = nsIDOMDOMException::NOT_SUPPORTED_ERR,
|
|
|
|
// Can't remove until setNamedItem is removed
|
|
|
|
InUseAttributeError = nsIDOMDOMException::INUSE_ATTRIBUTE_ERR,
|
|
|
|
InvalidStateError = nsIDOMDOMException::INVALID_STATE_ERR,
|
|
|
|
SyntaxError = nsIDOMDOMException::SYNTAX_ERR,
|
|
|
|
InvalidModificationError = nsIDOMDOMException::INVALID_MODIFICATION_ERR,
|
|
|
|
NamespaceError = nsIDOMDOMException::NAMESPACE_ERR,
|
|
|
|
InvalidAccessError = nsIDOMDOMException::INVALID_ACCESS_ERR,
|
|
|
|
TypeMismatchError = nsIDOMDOMException::TYPE_MISMATCH_ERR,
|
|
|
|
SecurityError = nsIDOMDOMException::SECURITY_ERR,
|
|
|
|
NetworkError = nsIDOMDOMException::NETWORK_ERR,
|
|
|
|
AbortError = nsIDOMDOMException::ABORT_ERR,
|
|
|
|
URLMismatchError = nsIDOMDOMException::URL_MISMATCH_ERR,
|
|
|
|
QuotaExceededError = nsIDOMDOMException::QUOTA_EXCEEDED_ERR,
|
|
|
|
TimeoutError = nsIDOMDOMException::TIMEOUT_ERR,
|
|
|
|
InvalidNodeTypeError = nsIDOMDOMException::INVALID_NODE_TYPE_ERR,
|
|
|
|
DataCloneError = nsIDOMDOMException::DATA_CLONE_ERR,
|
|
|
|
|
|
|
|
/* XXX Should be JavaScript native TypeError */
|
|
|
|
TypeError = 0,
|
|
|
|
|
|
|
|
/* IndexedDB errors http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#exceptions */
|
|
|
|
UnknownError = 0,
|
|
|
|
ConstraintError = 0,
|
|
|
|
DataError = 0,
|
|
|
|
TransactionInactiveError = 0,
|
|
|
|
ReadOnlyError = 0,
|
|
|
|
VersionError = 0,
|
|
|
|
|
|
|
|
/* File API errors http://dev.w3.org/2006/webapi/FileAPI/#ErrorAndException */
|
|
|
|
NotReadableError = 0,
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
/* FileHandle API errors */
|
|
|
|
LockedFileInactiveError = 0,
|
2012-04-11 14:55:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DOM4_MSG_DEF(name, message, nsresult) {(nsresult), name, #name, message},
|
|
|
|
#define DOM_MSG_DEF(val, message) {(val), NS_ERROR_GET_CODE(val), #val, message},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static struct ResultStruct
|
|
|
|
{
|
|
|
|
nsresult mNSResult;
|
2012-04-11 14:55:21 -07:00
|
|
|
PRUint16 mCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
const char* mName;
|
|
|
|
const char* mMessage;
|
|
|
|
} gDOMErrorMsgMap[] = {
|
|
|
|
#include "domerr.msg"
|
2012-04-11 14:55:21 -07:00
|
|
|
{0, 0, nsnull, nsnull} // sentinel to mark end of array
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
#undef DOM4_MSG_DEF
|
2007-03-22 10:30:00 -07:00
|
|
|
#undef DOM_MSG_DEF
|
|
|
|
|
|
|
|
static void
|
|
|
|
NSResultToNameAndMessage(nsresult aNSResult,
|
|
|
|
const char** aName,
|
2012-04-11 14:55:21 -07:00
|
|
|
const char** aMessage,
|
|
|
|
PRUint16* aCode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-18 12:02:27 -07:00
|
|
|
*aName = nsnull;
|
|
|
|
*aMessage = nsnull;
|
2012-04-11 14:55:21 -07:00
|
|
|
*aCode = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
ResultStruct* result_struct = gDOMErrorMsgMap;
|
|
|
|
|
|
|
|
while (result_struct->mName) {
|
|
|
|
if (aNSResult == result_struct->mNSResult) {
|
|
|
|
*aName = result_struct->mName;
|
|
|
|
*aMessage = result_struct->mMessage;
|
2012-04-11 14:55:21 -07:00
|
|
|
*aCode = result_struct->mCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
++result_struct;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Huh, someone is throwing non-DOM errors using the DOM module!");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
|
|
|
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
|
2012-04-24 16:50:00 -07:00
|
|
|
const char** aMessage, PRUint16* aCode)
|
2010-11-10 15:25:44 -08:00
|
|
|
{
|
|
|
|
const char* name = nsnull;
|
|
|
|
const char* message = nsnull;
|
2012-04-11 14:55:21 -07:00
|
|
|
PRUint16 code = 0;
|
|
|
|
NSResultToNameAndMessage(aNSResult, &name, &message, &code);
|
2010-11-10 15:25:44 -08:00
|
|
|
|
|
|
|
if (name && message) {
|
|
|
|
*aName = name;
|
|
|
|
*aMessage = message;
|
2012-04-24 16:50:00 -07:00
|
|
|
if (aCode) {
|
|
|
|
*aCode = code;
|
|
|
|
}
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_HEAD(DOMException)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIDOMDOMEXCEPTION
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_TAIL(DOMException)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-02-22 16:34:14 -08:00
|
|
|
nsDOMException::GetCode(PRUint16* aCode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
2012-04-11 14:55:21 -07:00
|
|
|
*aCode = mCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-11 14:55:23 -07:00
|
|
|
// Warn only when the code was changed (IndexedDB or File API)
|
|
|
|
// or the code is useless (zero)
|
|
|
|
if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_INDEXEDDB ||
|
|
|
|
NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM_FILE ||
|
|
|
|
!mCode) {
|
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
|
|
|
|
if (doc) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eDOMExceptionCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_HEAD(SVGException)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIDOMSVGEXCEPTION
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_TAIL(SVGException)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGException::GetCode(PRUint16* aCode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
2012-04-11 14:55:21 -07:00
|
|
|
*aCode = mCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_HEAD(XPathException)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIDOMXPATHEXCEPTION
|
2012-04-11 14:55:21 -07:00
|
|
|
IMPL_INTERNAL_DOM_EXCEPTION_TAIL(XPathException)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXPathException::GetCode(PRUint16* aCode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
2012-04-11 14:55:21 -07:00
|
|
|
*aCode = mCode;
|
2007-07-24 21:29:47 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBaseDOMException::nsBaseDOMException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseDOMException::~nsBaseDOMException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsBaseDOMException, nsIException, nsIBaseDOMException)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-02-11 20:11:07 -08:00
|
|
|
nsBaseDOMException::GetMessageMoz(char **aMessage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMessage) {
|
|
|
|
*aMessage = NS_strdup(mMessage);
|
|
|
|
} else {
|
|
|
|
*aMessage = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetResult(PRUint32* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
*aResult = mResult;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetName(char **aName)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aName);
|
|
|
|
|
|
|
|
if (mName) {
|
|
|
|
*aName = NS_strdup(mName);
|
|
|
|
} else {
|
|
|
|
*aName = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetFilename(char **aFilename)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
return mInner->GetFilename(aFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aFilename);
|
|
|
|
|
|
|
|
*aFilename = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetLineNumber(PRUint32 *aLineNumber)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
return mInner->GetLineNumber(aLineNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aLineNumber);
|
|
|
|
|
|
|
|
*aLineNumber = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetColumnNumber(PRUint32 *aColumnNumber)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
return mInner->GetColumnNumber(aColumnNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnNumber);
|
|
|
|
|
|
|
|
*aColumnNumber = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetLocation(nsIStackFrame **aLocation)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
return mInner->GetLocation(aLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocation);
|
|
|
|
|
|
|
|
*aLocation = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetInner(nsIException **aInner)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInner);
|
|
|
|
|
|
|
|
*aInner = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::GetData(nsISupports **aData)
|
|
|
|
{
|
|
|
|
if (mInner) {
|
|
|
|
return mInner->GetData(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
|
|
|
|
*aData = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::ToString(char **aReturn)
|
|
|
|
{
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
|
|
|
static const char defaultMsg[] = "<no message>";
|
|
|
|
static const char defaultLocation[] = "<unknown>";
|
|
|
|
static const char defaultName[] = "<unknown>";
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* msg = mMessage ? mMessage : defaultMsg;
|
|
|
|
const char* resultName = mName ? mName : defaultName;
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
*aReturn = PR_smprintf(format, msg, mCode, mResult, resultName,
|
2007-03-22 10:30:00 -07:00
|
|
|
location.get());
|
|
|
|
|
|
|
|
return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseDOMException::Init(nsresult aNSResult, const char* aName,
|
2012-04-11 14:55:21 -07:00
|
|
|
const char* aMessage, PRUint16 aCode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIException* aDefaultException)
|
|
|
|
{
|
|
|
|
mResult = aNSResult;
|
|
|
|
mName = aName;
|
|
|
|
mMessage = aMessage;
|
2012-04-11 14:55:21 -07:00
|
|
|
mCode = aCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner = aDefaultException;
|
|
|
|
return NS_OK;
|
|
|
|
}
|