Bug 705640 - Implement DOMError as defined in DOM 4, r=mounir.

--HG--
extra : transplant_source : %15%98Xx%C3%F3%89%95%94%5Eu%99%B0%CC%8B%E0V%3A4%C6
This commit is contained in:
Ben Turner 2012-01-24 02:13:41 -08:00
Родитель 182ee449ce
Коммит a9c7587993
9 изменённых файлов: 159 добавлений и 116 удалений

82
dom/base/DOMError.cpp Normal file
Просмотреть файл

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
#include "DOMError.h"
#include "mozilla/Util.h"
#include "nsDOMClassInfo.h"
using mozilla::ArrayLength;
using mozilla::dom::DOMError;
namespace {
struct NameMap
{
PRUint16 code;
const char* name;
};
} // anonymous namespace
// static
already_AddRefed<nsIDOMDOMError>
DOMError::CreateForDOMExceptionCode(PRUint16 aDOMExceptionCode)
{
// All of these codes (and yes, some are skipped) come from the spec.
static const NameMap kNames[] = {
{ 1, "IndexSizeError" },
{ 3, "HierarchyRequestError" },
{ 4, "WrongDocumentError" },
{ 5, "InvalidCharacterError" },
{ 7, "NoModificationAllowedError" },
{ 8, "NotFoundError" },
{ 9, "NotSupportedError" },
{ 11, "InvalidStateError" },
{ 12, "SyntaxError" },
{ 13, "InvalidModificationError" },
{ 14, "NamespaceError" },
{ 15, "InvalidAccessError" },
{ 17, "TypeMismatchError" },
{ 18, "SecurityError" },
{ 19, "NetworkError" },
{ 20, "AbortError" },
{ 21, "URLMismatchError" },
{ 22, "QuotaExceededError" },
{ 23, "TimeoutError" },
{ 24, "InvalidNodeTypeError" },
{ 25, "DataCloneError" }
};
for (size_t index = 0; index < ArrayLength(kNames); index++) {
if (kNames[index].code == aDOMExceptionCode) {
nsString name;
name.AssignASCII(kNames[index].name);
return CreateWithName(name);
}
}
NS_NOTREACHED("Unknown DOMException code!");
return nsnull;
}
NS_IMPL_ADDREF(DOMError)
NS_IMPL_RELEASE(DOMError)
NS_INTERFACE_MAP_BEGIN(DOMError)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMError)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMError)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
DOMCI_DATA(DOMError, DOMError)
NS_IMETHODIMP
DOMError::GetName(nsAString& aName)
{
aName = mName;
return NS_OK;
}

48
dom/base/DOMError.h Normal file
Просмотреть файл

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_domerror_h__
#define mozilla_dom_domerror_h__
#include "nsIDOMDOMError.h"
#include "nsCOMPtr.h"
#include "nsStringGlue.h"
namespace mozilla {
namespace dom {
class DOMError : public nsIDOMDOMError
{
nsString mName;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMDOMERROR
static already_AddRefed<nsIDOMDOMError>
CreateForDOMExceptionCode(PRUint16 aDOMExceptionCode);
static already_AddRefed<nsIDOMDOMError>
CreateWithName(const nsAString& aName)
{
nsCOMPtr<nsIDOMDOMError> error = new DOMError(aName);
return error.forget();
}
protected:
DOMError(const nsAString& aName)
: mName(aName)
{ }
virtual ~DOMError()
{ }
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_domerror_h__

Просмотреть файл

@ -66,6 +66,7 @@ EXTRA_JS_MODULES += Webapps.jsm \
endif
XPIDLSRCS = \
nsIDOMDOMError.idl \
nsIEntropyCollector.idl \
nsIScriptChannel.idl \
$(NULL)
@ -103,6 +104,7 @@ EXPORTS = \
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
DOMError.h \
StructuredCloneTags.h \
$(NULL)
@ -132,6 +134,7 @@ CPPSRCS = \
nsDOMNavigationTiming.cpp \
nsPerformance.cpp \
nsDOMMemoryReporter.cpp \
DOMError.cpp \
Navigator.cpp \
$(NULL)

Просмотреть файл

@ -530,6 +530,8 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "CallEvent.h"
#endif
#include "DOMError.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -1619,6 +1621,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(CallEvent, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CLASSINFO_DATA(DOMError, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
// Objects that should be constructable through |new Name();|
@ -4352,6 +4357,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif
DOM_CLASSINFO_MAP_BEGIN(DOMError, nsIDOMDOMError)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMError)
DOM_CLASSINFO_MAP_END
#ifdef NS_DEBUG
{
PRUint32 i = ArrayLength(sClassInfoData);

Просмотреть файл

@ -537,3 +537,5 @@ DOMCI_CLASS(Telephony)
DOMCI_CLASS(TelephonyCall)
DOMCI_CLASS(CallEvent)
#endif
DOMCI_CLASS(DOMError)

Просмотреть файл

@ -0,0 +1,13 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
#include "nsISupports.idl"
[scriptable, builtinclass, uuid(e4e28307-d409-4cf7-93cd-6ea8e889f87a)]
interface nsIDOMDOMError : nsISupports
{
readonly attribute DOMString name;
};

Просмотреть файл

@ -1,62 +0,0 @@
/* -*- 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):
* Boris Zbarsky <bzbarsky@mit.edu> (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 "domstubs.idl"
/**
* The nsIDOMDOMError interface is "An non-zero implementation
* dependent error code describing the error, or 0 if there is no
* error." [sic]
*
* For more information on this interface please see
* http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20020409/core.html
*/
[scriptable, uuid(475790ce-d8fa-4e02-a167-e6308ba9b120)]
interface nsIDOMDOMError : nsISupports
{
const unsigned short SEVERITY_WARNING = 0;
const unsigned short SEVERITY_ERROR = 1;
const unsigned short SEVERITY_FATAL_ERROR = 2;
readonly attribute unsigned short severity;
readonly attribute DOMString message;
// XXX This should be a DOMObject, not an nsISupports; do we need to
// do some magic to make that work?
readonly attribute nsISupports relatedException;
readonly attribute nsIDOMDOMLocator location;
};

Просмотреть файл

@ -1,54 +0,0 @@
/* -*- 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):
* Boris Zbarsky <bzbarsky@mit.edu> (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 "domstubs.idl"
/**
* The nsIDOMDOMErrorHandler interface is a basic interface for DOM
* error handlers
*
* For more information on this interface please see
* http://www.w3.org/TR/2002/WD-DOM-Level-3-Core-20020409/core.html
*/
[scriptable, uuid(2d958bdf-740d-43f4-9e5c-5d930f4f3876)]
interface nsIDOMDOMErrorHandler : nsISupports
{
boolean handleError(in nsIDOMDOMError error);
};

Просмотреть файл

@ -467,6 +467,8 @@ members = [
'nsIIDBVersionChangeEvent.*',
'nsIIndexedDatabaseUsageCallback.*',
'nsIIndexedDatabaseManager.*',
'nsIDOMDOMError.*',
]
# Most interfaces can be found by searching the includePath; to find