mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 667612: Make addEventListener not throw if passed a null listener. r=smaug
This commit is contained in:
parent
076571f0ef
commit
923d52af7d
@ -1059,8 +1059,9 @@ nsINode::AddEventListener(const nsAString& aType,
|
||||
|
||||
nsEventListenerManager* listener_manager = GetListenerManager(PR_TRUE);
|
||||
NS_ENSURE_STATE(listener_manager);
|
||||
return listener_manager->AddEventListener(aType, aListener, aUseCapture,
|
||||
aWantsUntrusted);
|
||||
listener_manager->AddEventListener(aType, aListener, aUseCapture,
|
||||
aWantsUntrusted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -126,7 +126,8 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
|
||||
|
||||
nsEventListenerManager* elm = GetListenerManager(PR_TRUE);
|
||||
NS_ENSURE_STATE(elm);
|
||||
return elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
||||
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -209,14 +209,17 @@ nsEventListenerManager::GetInnerWindowForTarget()
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
PRUint32 aType,
|
||||
nsIAtom* aTypeAtom,
|
||||
PRInt32 aFlags)
|
||||
{
|
||||
NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_TRUE(aType, NS_ERROR_FAILURE);
|
||||
NS_ABORT_IF_FALSE(aType && aTypeAtom, "Missing type");
|
||||
|
||||
if (!aListener) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<nsIDOMEventListener> kungFuDeathGrip = aListener;
|
||||
|
||||
@ -226,7 +229,7 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
ls = &mListeners.ElementAt(i);
|
||||
if (ls->mListener == aListener && ls->mFlags == aFlags &&
|
||||
EVENT_TYPE_EQUALS(ls, aType, aTypeAtom)) {
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,8 +294,6 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
if (window)
|
||||
window->SetHasTouchEventListeners();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
@ -334,14 +335,14 @@ ListenerCanHandle(nsListenerStruct* aLs, nsEvent* aEvent)
|
||||
(aLs->mEventType == aEvent->message);
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aListener,
|
||||
const nsAString& aType,
|
||||
PRInt32 aFlags)
|
||||
{
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + aType);
|
||||
PRUint32 type = nsContentUtils::GetEventId(atom);
|
||||
return AddEventListener(aListener, type, atom, aFlags);
|
||||
AddEventListener(aListener, type, atom, aFlags);
|
||||
}
|
||||
|
||||
void
|
||||
@ -943,8 +944,7 @@ nsEventListenerManager::Disconnect()
|
||||
RemoveAllListeners();
|
||||
}
|
||||
|
||||
// nsIDOMEventTarget interface
|
||||
nsresult
|
||||
void
|
||||
nsEventListenerManager::AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture,
|
||||
|
@ -84,10 +84,10 @@ public:
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsEventListenerManager)
|
||||
|
||||
nsresult AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture,
|
||||
PRBool aWantsUntrusted);
|
||||
void AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture,
|
||||
PRBool aWantsUntrusted);
|
||||
void RemoveEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture);
|
||||
@ -96,9 +96,9 @@ public:
|
||||
* Sets events listeners of all types.
|
||||
* @param an event listener
|
||||
*/
|
||||
nsresult AddEventListenerByType(nsIDOMEventListener *aListener,
|
||||
const nsAString& type,
|
||||
PRInt32 aFlags);
|
||||
void AddEventListenerByType(nsIDOMEventListener *aListener,
|
||||
const nsAString& type,
|
||||
PRInt32 aFlags);
|
||||
void RemoveEventListenerByType(nsIDOMEventListener *aListener,
|
||||
const nsAString& type,
|
||||
PRInt32 aFlags);
|
||||
@ -210,10 +210,10 @@ protected:
|
||||
void *aScopeGlobal,
|
||||
nsIAtom* aName, PRBool aIsString,
|
||||
PRBool aPermitUntrustedEvents);
|
||||
nsresult AddEventListener(nsIDOMEventListener *aListener,
|
||||
PRUint32 aType,
|
||||
nsIAtom* aTypeAtom,
|
||||
PRInt32 aFlags);
|
||||
void AddEventListener(nsIDOMEventListener *aListener,
|
||||
PRUint32 aType,
|
||||
nsIAtom* aTypeAtom,
|
||||
PRInt32 aFlags);
|
||||
void RemoveEventListener(nsIDOMEventListener *aListener,
|
||||
PRUint32 aType,
|
||||
nsIAtom* aUserType,
|
||||
|
@ -280,7 +280,8 @@ nsEventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT :
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT;
|
||||
return manager->AddEventListenerByType(aListener, aType, flags);
|
||||
manager->AddEventListenerByType(aListener, aType, flags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -107,6 +107,8 @@ _TEST_FILES = \
|
||||
test_bug662678.html \
|
||||
test_bug667919-1.html \
|
||||
test_bug667919-2.html \
|
||||
test_bug667612.html \
|
||||
empty.js \
|
||||
$(NULL)
|
||||
|
||||
#bug 585630
|
||||
|
0
content/events/test/empty.js
Normal file
0
content/events/test/empty.js
Normal file
39
content/events/test/test_bug667612.html
Normal file
39
content/events/test/test_bug667612.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=667612
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 667612</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/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=667612">Mozilla Bug 667612</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
xhr = new XMLHttpRequest;
|
||||
w = new Worker("empty.js");
|
||||
window.addEventListener("load", null, false);
|
||||
document.addEventListener("load", null, false);
|
||||
document.body.addEventListener("load", null, false);
|
||||
xhr.addEventListener("load", null, false);
|
||||
w.addEventListener("load", null, false);
|
||||
window.addEventListener("load", undefined, false);
|
||||
document.addEventListener("load", undefined, false);
|
||||
document.body.addEventListener("load", undefined, false);
|
||||
xhr.addEventListener("load", undefined, false);
|
||||
w.addEventListener("load", undefined, false);
|
||||
|
||||
ok(true, "didn't throw");
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -7376,8 +7376,8 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
|
||||
|
||||
nsEventListenerManager* manager = GetListenerManager(PR_TRUE);
|
||||
NS_ENSURE_STATE(manager);
|
||||
return manager->AddEventListener(aType, aListener, aUseCapture,
|
||||
aWantsUntrusted);
|
||||
manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsEventListenerManager*
|
||||
|
@ -146,7 +146,8 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
|
||||
|
||||
nsEventListenerManager* elm = GetListenerManager(PR_TRUE);
|
||||
NS_ENSURE_STATE(elm);
|
||||
return elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
||||
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsEventListenerManager*
|
||||
|
@ -126,78 +126,62 @@ nsEditorEventListener::InstallToEditor()
|
||||
nsCOMPtr<nsIDOMEventTarget> piTarget = mEditor->GetDOMEventTarget();
|
||||
NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// register the event listeners with the listener manager
|
||||
nsEventListenerManager* elmP = piTarget->GetListenerManager(PR_TRUE);
|
||||
NS_ENSURE_STATE(elmP);
|
||||
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("keypress"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_PRIV_EVENT_UNTRUSTED_PERMITTED |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("keypress"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_PRIV_EVENT_UNTRUSTED_PERMITTED |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
// See bug 455215, we cannot use the standard dragstart event yet
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("draggesture"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragenter"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragover"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragexit"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("drop"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("mousedown"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("mouseup"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("click"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Focus event doesn't bubble so adding the listener to capturing phase.
|
||||
// Make sure this works after bug 235441 gets fixed.
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("blur"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("focus"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("text"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("compositionstart"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("compositionend"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("draggesture"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragenter"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragover"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("dragexit"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("drop"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("mousedown"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("mouseup"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("click"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
// Focus event doesn't bubble so adding the listener to capturing phase.
|
||||
// Make sure this works after bug 235441 gets fixed.
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("blur"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("focus"),
|
||||
NS_EVENT_FLAG_CAPTURE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("text"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("compositionstart"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
elmP->AddEventListenerByType(this,
|
||||
NS_LITERAL_STRING("compositionend"),
|
||||
NS_EVENT_FLAG_BUBBLE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -887,15 +887,13 @@ nsDocShellTreeOwner::AddChromeListeners()
|
||||
GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
|
||||
|
||||
nsEventListenerManager* elmP = target->GetListenerManager(PR_TRUE);
|
||||
if (elmP)
|
||||
{
|
||||
rv = elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = elmP->AddEventListenerByType(this, NS_LITERAL_STRING("drop"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
if (elmP) {
|
||||
elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
elmP->AddEventListenerByType(this, NS_LITERAL_STRING("drop"),
|
||||
NS_EVENT_FLAG_BUBBLE |
|
||||
NS_EVENT_FLAG_SYSTEM_EVENT);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
Loading…
Reference in New Issue
Block a user