зеркало из https://github.com/mozilla/pjs.git
Bug 641477 - Throw UNSPECIFIED_EVENT_TYPE_ERR if event isn't initialized before dispatching, r=sicking
This commit is contained in:
Родитель
764b2943a5
Коммит
975003f00a
|
@ -472,6 +472,12 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
|
|||
NS_ERROR_ILLEGAL_VALUE);
|
||||
NS_ASSERTION(!aTargets || !aEvent->message, "Wrong parameters!");
|
||||
|
||||
// If we're dispatching an already created DOMEvent object, make
|
||||
// sure it is initialized!
|
||||
// If aTargets is non-null, the event isn't going to be dispatched.
|
||||
NS_ENSURE_TRUE(aEvent->message || !aDOMEvent || aTargets,
|
||||
NS_ERROR_DOM_UNSPECIFIED_EVENT_TYPE_ERR);
|
||||
|
||||
#ifdef NS_FUNCTION_TIMER
|
||||
const char* timer_event_name = nsDOMEvent::GetEventName(aEvent->message);
|
||||
NS_TIME_FUNCTION_MIN_FMT(20, "Dispatching '%s' event",
|
||||
|
|
|
@ -99,6 +99,7 @@ _TEST_FILES = \
|
|||
test_bug605242.html \
|
||||
test_bug607464.html \
|
||||
test_bug624127.html \
|
||||
test_bug641477.html \
|
||||
$(NULL)
|
||||
|
||||
#bug 585630
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=641477
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 641477</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=641477">Mozilla Bug 641477</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 641477 **/
|
||||
|
||||
var didThrow = false;
|
||||
|
||||
var e = document.createEvent("Event");
|
||||
try {
|
||||
document.dispatchEvent(e);
|
||||
} catch(ex) {
|
||||
didThrow = (ex.code == 0);
|
||||
}
|
||||
|
||||
ok(didThrow, "Should have thrown UNSPECIFIED_EVENT_TYPE_ERR!");
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -124,6 +124,8 @@ 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_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) */
|
||||
|
||||
DOM_MSG_DEF(NS_OK , "Success")
|
||||
|
|
|
@ -500,6 +500,7 @@ using namespace mozilla::dom;
|
|||
#include "mozilla/dom/indexedDB/IDBKeyRange.h"
|
||||
#include "mozilla/dom/indexedDB/IDBIndex.h"
|
||||
#include "nsIIDBDatabaseException.h"
|
||||
#include "nsIDOMEventException.h"
|
||||
|
||||
static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
||||
|
||||
|
@ -1478,6 +1479,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
|||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBDatabaseException, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(EventException, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
};
|
||||
|
||||
// Objects that should be constructable through |new Name();|
|
||||
|
@ -4160,6 +4164,11 @@ nsDOMClassInfo::Init()
|
|||
DOM_CLASSINFO_MAP_ENTRY(nsIException)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(EventException, nsIDOMEventException)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventException)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIException)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
{
|
||||
PRUint32 i = NS_ARRAY_LENGTH(sClassInfoData);
|
||||
|
|
|
@ -505,3 +505,5 @@ DOMCI_CLASS(IDBIndex)
|
|||
DOMCI_CLASS(IDBVersionChangeEvent)
|
||||
DOMCI_CLASS(IDBVersionChangeRequest)
|
||||
DOMCI_CLASS(IDBDatabaseException)
|
||||
|
||||
DOMCI_CLASS(EventException)
|
||||
|
|
|
@ -128,4 +128,6 @@
|
|||
#define NS_ERROR_DOM_FILE_NOT_FOUND_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 0)
|
||||
#define NS_ERROR_DOM_FILE_NOT_READABLE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_FILE, 1)
|
||||
|
||||
#define NS_ERROR_DOM_UNSPECIFIED_EVENT_TYPE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_EVENTS, 0)
|
||||
|
||||
#endif // nsDOMError_h__
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "nsIIDBDatabaseException.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIDOMEventException.h"
|
||||
|
||||
#define DOM_MSG_DEF(val, message) {(val), #val, message},
|
||||
|
||||
|
@ -237,6 +238,23 @@ nsDOMFileException::GetCode(PRUint16* aCode)
|
|||
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,
|
||||
nsIIDBDatabaseException)
|
||||
NS_DECL_NSIIDBDATABASEEXCEPTION
|
||||
|
|
|
@ -78,4 +78,5 @@ DECL_INTERNAL_DOM_EXCEPTION(SVGException)
|
|||
#endif
|
||||
DECL_INTERNAL_DOM_EXCEPTION(XPathException)
|
||||
DECL_INTERNAL_DOM_EXCEPTION(FileException)
|
||||
DECL_INTERNAL_DOM_EXCEPTION(EventException)
|
||||
DECL_INTERNAL_DOM_EXCEPTION(IDBDatabaseException)
|
||||
|
|
|
@ -94,6 +94,7 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
|
|||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_XPCONNECT);
|
||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_EVENTS);
|
||||
}
|
||||
|
||||
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
|
||||
|
@ -298,6 +299,8 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject,
|
|||
NS_ERROR_MODULE_DOM_XPATH);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
NS_ERROR_MODULE_XPCONNECT);
|
||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
||||
NS_ERROR_MODULE_DOM_EVENTS);
|
||||
}
|
||||
|
||||
NS_RELEASE(gExceptionProvider);
|
||||
|
@ -401,6 +404,8 @@ nsDOMExceptionProvider::GetException(nsresult result,
|
|||
return NS_NewFileException(result, aDefaultException, _retval);
|
||||
case NS_ERROR_MODULE_DOM_INDEXEDDB:
|
||||
return NS_NewIDBDatabaseException(result, aDefaultException, _retval);
|
||||
case NS_ERROR_MODULE_DOM_EVENTS:
|
||||
return NS_NewEventException(result, aDefaultException, _retval);
|
||||
default:
|
||||
return NS_NewDOMException(result, aDefaultException, _retval);
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ XPIDLSRCS = \
|
|||
nsIDOMTransitionEvent.idl \
|
||||
nsIDOMPopStateEvent.idl \
|
||||
nsIDOMCloseEvent.idl \
|
||||
nsIDOMEventException.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* ***** 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;
|
||||
};
|
|
@ -98,6 +98,7 @@
|
|||
#define NS_ERROR_MODULE_SCHEMA 31
|
||||
#define NS_ERROR_MODULE_DOM_FILE 32
|
||||
#define NS_ERROR_MODULE_DOM_INDEXEDDB 33
|
||||
#define NS_ERROR_MODULE_DOM_EVENTS 34
|
||||
|
||||
/* NS_ERROR_MODULE_GENERAL should be used by modules that do not
|
||||
* care if return code values overlap. Callers of methods that
|
||||
|
|
Загрузка…
Ссылка в новой задаче