Bug 705640 - Implement DOMError as defined in DOM 4, r=mounir.
authorBen Turner <bent.mozilla@gmail.com>
Tue, 24 Jan 2012 02:13:41 -0800
changeset 86418 117f6d70c5848da872fae33c03702158e126adc0
parent 86417 8b5e839439588112886ad61edc0291ff69450890
child 86419 c3643d492d6825c5858dd9b76877745d3413bbe6
child 86439 30f32ca8241ae46acadb60e215c99de90372882a
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs705640
milestone12.0a1
Bug 705640 - Implement DOMError as defined in DOM 4, r=mounir.
dom/base/DOMError.cpp
dom/base/DOMError.h
dom/base/Makefile.in
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/base/nsIDOMDOMError.idl
dom/interfaces/core/nsIDOMDOMError.idl
dom/interfaces/core/nsIDOMDOMErrorHandler.idl
js/xpconnect/src/dom_quickstubs.qsconf
new file mode 100644
--- /dev/null
+++ b/dom/base/DOMError.cpp
@@ -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;
+}
new file mode 100644
--- /dev/null
+++ b/dom/base/DOMError.h
@@ -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__
--- a/dom/base/Makefile.in
+++ b/dom/base/Makefile.in
@@ -61,16 +61,17 @@ EXTRA_COMPONENTS = \
 	        Webapps.manifest \
 		$(NULL)
 
 EXTRA_JS_MODULES += Webapps.jsm \
 		$(NULL)
 endif
 
 XPIDLSRCS = \
+  nsIDOMDOMError.idl \
   nsIEntropyCollector.idl \
   nsIScriptChannel.idl \
   $(NULL)
 
 EXPORTS = \
   nsDOMCID.h \
   nsDOMClassInfoClasses.h \
   nsDOMClassInfoID.h \
@@ -98,16 +99,17 @@ EXPORTS = \
   nsWrapperCache.h \
   nsContentPermissionHelper.h \
   nsStructuredCloneContainer.h \
   nsDOMMemoryReporter.h \
   $(NULL)
 
 EXPORTS_NAMESPACES = mozilla/dom
 EXPORTS_mozilla/dom = \
+  DOMError.h \
   StructuredCloneTags.h \
   $(NULL)
 
 CPPSRCS =			\
 	nsBarProps.cpp          \
 	nsDOMException.cpp 	\
 	nsDOMWindowUtils.cpp 	\
 	nsJSEnvironment.cpp	\
@@ -127,16 +129,17 @@ CPPSRCS =			\
 	nsScriptNameSpaceManager.cpp \
 	nsDOMScriptObjectFactory.cpp \
 	nsQueryContentEventResult.cpp \
 	nsContentPermissionHelper.cpp \
 	nsStructuredCloneContainer.cpp \
 	nsDOMNavigationTiming.cpp \
 	nsPerformance.cpp	\
 	nsDOMMemoryReporter.cpp \
+	DOMError.cpp \
 	Navigator.cpp \
 	$(NULL)
 
 include $(topsrcdir)/dom/dom-config.mk
 
 ifdef MOZ_JSDEBUGGER
 DEFINES += -DMOZ_JSDEBUGGER
 endif
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -525,16 +525,18 @@ using mozilla::dom::indexedDB::IDBWrappe
 #include "mozilla/dom/network/Utils.h"
 
 #ifdef MOZ_B2G_RIL
 #include "Telephony.h"
 #include "TelephonyCall.h"
 #include "CallEvent.h"
 #endif
 
+#include "DOMError.h"
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
 
 static const char kDOMStringBundleURL[] =
   "chrome://global/locale/dom/dom.properties";
 
@@ -1614,16 +1616,19 @@ static nsDOMClassInfoData sClassInfoData
 #ifdef MOZ_B2G_RIL
   NS_DEFINE_CLASSINFO_DATA(Telephony, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   NS_DEFINE_CLASSINFO_DATA(TelephonyCall, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
   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();|
 struct nsContractIDMapData
 {
   PRInt32 mDOMClassInfoID;
   const char *mContractID;
 };
@@ -4347,16 +4352,20 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(CallEvent, nsIDOMCallEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMCallEvent)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
   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);
 
     if (i != eDOMClassInfoIDCount) {
       NS_ERROR("The number of items in sClassInfoData doesn't match the "
                "number of nsIDOMClassInfo ID's, this is bad! Fix it!");
 
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -532,8 +532,10 @@ DOMCI_CLASS(MozCSSKeyframesRule)
 DOMCI_CLASS(MediaQueryList)
 DOMCI_CLASS(CustomEvent)
 
 #ifdef MOZ_B2G_RIL
 DOMCI_CLASS(Telephony)
 DOMCI_CLASS(TelephonyCall)
 DOMCI_CLASS(CallEvent)
 #endif
+
+DOMCI_CLASS(DOMError)
new file mode 100644
--- /dev/null
+++ b/dom/base/nsIDOMDOMError.idl
@@ -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;
+};
deleted file mode 100644
--- a/dom/interfaces/core/nsIDOMDOMError.idl
+++ /dev/null
@@ -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;
-};
deleted file mode 100644
--- a/dom/interfaces/core/nsIDOMDOMErrorHandler.idl
+++ /dev/null
@@ -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);
-};
-
--- a/js/xpconnect/src/dom_quickstubs.qsconf
+++ b/js/xpconnect/src/dom_quickstubs.qsconf
@@ -462,16 +462,18 @@ members = [
     'nsIIDBObjectStore.*',
     'nsIIDBRequest.*',
     'nsIIDBTransaction.*',
     'nsIIDBFactory.*',
     'nsIIDBOpenDBRequest.*',
     'nsIIDBVersionChangeEvent.*',
     'nsIIndexedDatabaseUsageCallback.*',
     'nsIIndexedDatabaseManager.*',
+
+    'nsIDOMDOMError.*',
     ]
 
 # Most interfaces can be found by searching the includePath; to find
 # nsIDOMEvent, for example, just look for nsIDOMEvent.idl.  But IDL filenames
 # for very long interface names are slightly abbreviated, and many interfaces
 # don't have their own files, just for extra wackiness.  So qsgen.py needs
 # a little help.
 #