Bug 687486 - Throw INVALID_STATE_ERR when dispatching uninitialized events; r=smaug

This commit is contained in:
Ms2ger 2011-10-09 20:23:13 +02:00
parent dcb3ae74ee
commit 2f93d04a35
12 changed files with 4 additions and 86 deletions

View File

@ -479,7 +479,7 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
// sure it is initialized! // sure it is initialized!
// If aTargets is non-null, the event isn't going to be dispatched. // If aTargets is non-null, the event isn't going to be dispatched.
NS_ENSURE_TRUE(aEvent->message || !aDOMEvent || aTargets, NS_ENSURE_TRUE(aEvent->message || !aDOMEvent || aTargets,
NS_ERROR_DOM_UNSPECIFIED_EVENT_TYPE_ERR); NS_ERROR_DOM_INVALID_STATE_ERR);
#ifdef NS_FUNCTION_TIMER #ifdef NS_FUNCTION_TIMER
const char* timer_event_name = nsDOMEvent::GetEventName(aEvent->message); const char* timer_event_name = nsDOMEvent::GetEventName(aEvent->message);

View File

@ -26,10 +26,10 @@ try {
is(e.type, "", "Event type should be empty string before initialization"); is(e.type, "", "Event type should be empty string before initialization");
document.dispatchEvent(e); document.dispatchEvent(e);
} catch(ex) { } catch(ex) {
didThrow = (ex.code == 0); didThrow = (ex.code == DOMException.INVALID_STATE_ERR);
} }
ok(didThrow, "Should have thrown UNSPECIFIED_EVENT_TYPE_ERR!"); ok(didThrow, "Should have thrown INVALID_STATE_ERR!");
</script> </script>
</pre> </pre>

View File

@ -122,8 +122,6 @@ DOM_MSG_DEF(NS_ERROR_DOM_QUOTA_REACHED, "Persistent storage maximum size reached
DOM_MSG_DEF(NS_ERROR_DOM_FILE_NOT_FOUND_ERR, "File was not found") DOM_MSG_DEF(NS_ERROR_DOM_FILE_NOT_FOUND_ERR, "File was not found")
DOM_MSG_DEF(NS_ERROR_DOM_FILE_NOT_READABLE_ERR, "File could not be read") DOM_MSG_DEF(NS_ERROR_DOM_FILE_NOT_READABLE_ERR, "File could not be read")
DOM_MSG_DEF(NS_ERROR_DOM_UNSPECIFIED_EVENT_TYPE_ERR, "Unspecified event type")
/* common global codes (from nsError.h) */ /* common global codes (from nsError.h) */
DOM_MSG_DEF(NS_OK , "Success") DOM_MSG_DEF(NS_OK , "Success")

View File

@ -496,7 +496,6 @@
#include "mozilla/dom/indexedDB/IDBKeyRange.h" #include "mozilla/dom/indexedDB/IDBKeyRange.h"
#include "mozilla/dom/indexedDB/IDBIndex.h" #include "mozilla/dom/indexedDB/IDBIndex.h"
#include "nsIIDBDatabaseException.h" #include "nsIIDBDatabaseException.h"
#include "nsIDOMEventException.h"
#include "nsIDOMMediaQueryList.h" #include "nsIDOMMediaQueryList.h"
@ -1502,9 +1501,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(IDBDatabaseException, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(IDBDatabaseException, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS) DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(EventException, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Touch, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(Touch, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS) DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(TouchList, nsDOMTouchListSH, NS_DEFINE_CLASSINFO_DATA(TouchList, nsDOMTouchListSH,
@ -4096,11 +4092,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIException) DOM_CLASSINFO_MAP_ENTRY(nsIException)
DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(EventException, nsIDOMEventException)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventException)
DOM_CLASSINFO_MAP_ENTRY(nsIException)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_MAYBE_DISABLE(Touch, nsIDOMTouch, DOM_CLASSINFO_MAP_BEGIN_MAYBE_DISABLE(Touch, nsIDOMTouch,
!nsDOMTouchEvent::PrefEnabled()) !nsDOMTouchEvent::PrefEnabled())
DOM_CLASSINFO_MAP_ENTRY(nsIDOMTouch) DOM_CLASSINFO_MAP_ENTRY(nsIDOMTouch)

View File

@ -509,8 +509,6 @@ DOMCI_CLASS(IDBVersionChangeEvent)
DOMCI_CLASS(IDBVersionChangeRequest) DOMCI_CLASS(IDBVersionChangeRequest)
DOMCI_CLASS(IDBDatabaseException) DOMCI_CLASS(IDBDatabaseException)
DOMCI_CLASS(EventException)
DOMCI_CLASS(Touch) DOMCI_CLASS(Touch)
DOMCI_CLASS(TouchList) DOMCI_CLASS(TouchList)
DOMCI_CLASS(TouchEvent) DOMCI_CLASS(TouchEvent)

View File

@ -127,6 +127,4 @@
#define NS_ERROR_DOM_FILE_NOT_READABLE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 1) #define NS_ERROR_DOM_FILE_NOT_READABLE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 1)
#define NS_ERROR_DOM_FILE_ABORT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 2) #define NS_ERROR_DOM_FILE_ABORT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 2)
#define NS_ERROR_DOM_UNSPECIFIED_EVENT_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_EVENTS, 0)
#endif // nsDOMError_h__ #endif // nsDOMError_h__

View File

@ -49,7 +49,6 @@
#include "nsIIDBDatabaseException.h" #include "nsIIDBDatabaseException.h"
#include "nsString.h" #include "nsString.h"
#include "prprf.h" #include "prprf.h"
#include "nsIDOMEventException.h"
#define DOM_MSG_DEF(val, message) {(val), #val, message}, #define DOM_MSG_DEF(val, message) {(val), #val, message},
@ -236,23 +235,6 @@ nsDOMFileException::GetCode(PRUint16* aCode)
return NS_OK; return NS_OK;
} }
IMPL_INTERNAL_DOM_EXCEPTION_HEAD(nsDOMEventException, nsIDOMEventException)
NS_DECL_NSIDOMEVENTEXCEPTION
IMPL_INTERNAL_DOM_EXCEPTION_TAIL(nsDOMEventException, nsIDOMEventException,
EventException, NS_ERROR_MODULE_DOM_EVENTS,
NSResultToNameAndMessage)
NS_IMETHODIMP
nsDOMEventException::GetCode(PRUint16* aCode)
{
NS_ENSURE_ARG_POINTER(aCode);
nsresult result;
GetResult(&result);
*aCode = NS_ERROR_GET_CODE(result);
return NS_OK;
}
IMPL_INTERNAL_DOM_EXCEPTION_HEAD(nsIDBDatabaseException, IMPL_INTERNAL_DOM_EXCEPTION_HEAD(nsIDBDatabaseException,
nsIIDBDatabaseException) nsIIDBDatabaseException)
NS_DECL_NSIIDBDATABASEEXCEPTION NS_DECL_NSIIDBDATABASEEXCEPTION

View File

@ -76,5 +76,4 @@ DECL_INTERNAL_DOM_EXCEPTION(RangeException)
DECL_INTERNAL_DOM_EXCEPTION(SVGException) DECL_INTERNAL_DOM_EXCEPTION(SVGException)
DECL_INTERNAL_DOM_EXCEPTION(XPathException) DECL_INTERNAL_DOM_EXCEPTION(XPathException)
DECL_INTERNAL_DOM_EXCEPTION(FileException) DECL_INTERNAL_DOM_EXCEPTION(FileException)
DECL_INTERNAL_DOM_EXCEPTION(EventException)
DECL_INTERNAL_DOM_EXCEPTION(IDBDatabaseException) DECL_INTERNAL_DOM_EXCEPTION(IDBDatabaseException)

View File

@ -398,8 +398,6 @@ nsDOMExceptionProvider::GetException(nsresult result,
return NS_NewFileException(result, aDefaultException, _retval); return NS_NewFileException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_DOM_INDEXEDDB: case NS_ERROR_MODULE_DOM_INDEXEDDB:
return NS_NewIDBDatabaseException(result, aDefaultException, _retval); return NS_NewIDBDatabaseException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_DOM_EVENTS:
return NS_NewEventException(result, aDefaultException, _retval);
default: default:
return NS_NewDOMException(result, aDefaultException, _retval); return NS_NewDOMException(result, aDefaultException, _retval);
} }

View File

@ -82,7 +82,6 @@ XPIDLSRCS = \
nsIDOMAnimationEvent.idl \ nsIDOMAnimationEvent.idl \
nsIDOMPopStateEvent.idl \ nsIDOMPopStateEvent.idl \
nsIDOMCloseEvent.idl \ nsIDOMCloseEvent.idl \
nsIDOMEventException.idl \
nsIDOMTouchEvent.idl \ nsIDOMTouchEvent.idl \
nsIDOMHashChangeEvent.idl \ nsIDOMHashChangeEvent.idl \
nsIDOMCustomEvent.idl \ nsIDOMCustomEvent.idl \

View File

@ -1,45 +0,0 @@
/* ***** 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.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 "nsISupports.idl"
[scriptable, uuid(825f3aad-501a-4ecd-959e-cf8f0f8a984a)]
interface nsIDOMEventException : nsISupports
{
const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0;
readonly attribute unsigned short code;
};

View File

@ -160,7 +160,7 @@ interface nsIDOMEventTarget : nsISupports
* @return Indicates whether any of the listeners which handled the * @return Indicates whether any of the listeners which handled the
* event called preventDefault. If preventDefault was called * event called preventDefault. If preventDefault was called
* the value is false, else the value is true. * the value is false, else the value is true.
* @throws UNSPECIFIED_EVENT_TYPE_ERR: Raised if the Event's type was * @throws INVALID_STATE_ERR: Raised if the Event's type was
* not specified by initializing the event before * not specified by initializing the event before
* dispatchEvent was called. Specification of the Event's * dispatchEvent was called. Specification of the Event's
* type as null or an empty string will also trigger this * type as null or an empty string will also trigger this