Bug 1876470 - AddEventListener/RemoveEventListener should not throw, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D226337
This commit is contained in:
Andrea Marchesini
2024-10-21 20:45:39 +00:00
parent d5a787c761
commit 4122537ef1
7 changed files with 13 additions and 23 deletions

View File

@@ -89,15 +89,15 @@ bool EventTarget::ComputeWantsUntrusted(
void EventTarget::AddEventListener(
const nsAString& aType, EventListener* aCallback,
const AddEventListenerOptionsOrBoolean& aOptions,
const Nullable<bool>& aWantsUntrusted, ErrorResult& aRv) {
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, &aOptions, aRv);
if (aRv.Failed()) {
const Nullable<bool>& aWantsUntrusted) {
IgnoredErrorResult rv;
bool wantsUntrusted = ComputeWantsUntrusted(aWantsUntrusted, &aOptions, rv);
if (NS_WARN_IF(rv.Failed())) {
return;
}
EventListenerManager* elm = GetOrCreateListenerManager();
if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
@@ -122,7 +122,7 @@ nsresult EventTarget::AddEventListener(const nsAString& aType,
void EventTarget::RemoveEventListener(
const nsAString& aType, EventListener* aListener,
const EventListenerOptionsOrBoolean& aOptions, ErrorResult& aRv) {
const EventListenerOptionsOrBoolean& aOptions) {
EventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aOptions);

View File

@@ -69,11 +69,9 @@ class EventTarget : public nsISupports, public nsWrapperCache {
ErrorResult& aRv);
void AddEventListener(const nsAString& aType, EventListener* aCallback,
const AddEventListenerOptionsOrBoolean& aOptions,
const Nullable<bool>& aWantsUntrusted,
ErrorResult& aRv);
const Nullable<bool>& aWantsUntrusted);
void RemoveEventListener(const nsAString& aType, EventListener* aCallback,
const EventListenerOptionsOrBoolean& aOptions,
ErrorResult& aRv);
const EventListenerOptionsOrBoolean& aOptions);
protected:
/**

View File

@@ -35,12 +35,10 @@ interface EventTarget {
differs in content and chrome. In content that default boolean
value is true, while in chrome the default boolean value is
false. */
[Throws]
undefined addEventListener(DOMString type,
EventListener? listener,
optional (AddEventListenerOptions or boolean) options = {},
optional boolean? wantsUntrusted = null);
[Throws]
undefined removeEventListener(DOMString type,
EventListener? listener,
optional (EventListenerOptions or boolean) options = {});

View File

@@ -16,10 +16,8 @@ interface MediaQueryList : EventTarget {
readonly attribute UTF8String media;
readonly attribute boolean matches;
[Throws]
undefined addListener(EventListener? listener);
[Throws]
undefined removeListener(EventListener? listener);
attribute EventHandler onchange;

View File

@@ -68,7 +68,7 @@ bool MediaQueryList::Matches() {
return mMatches;
}
void MediaQueryList::AddListener(EventListener* aListener, ErrorResult& aRv) {
void MediaQueryList::AddListener(EventListener* aListener) {
if (!aListener) {
return;
}
@@ -76,11 +76,10 @@ void MediaQueryList::AddListener(EventListener* aListener, ErrorResult& aRv) {
AddEventListenerOptionsOrBoolean options;
options.SetAsBoolean() = false;
AddEventListener(u"change"_ns, aListener, options, Nullable<bool>(), aRv);
AddEventListener(u"change"_ns, aListener, options, Nullable<bool>());
}
void MediaQueryList::RemoveListener(EventListener* aListener,
ErrorResult& aRv) {
void MediaQueryList::RemoveListener(EventListener* aListener) {
if (!aListener) {
return;
}
@@ -88,7 +87,7 @@ void MediaQueryList::RemoveListener(EventListener* aListener,
EventListenerOptionsOrBoolean options;
options.SetAsBoolean() = false;
RemoveEventListener(u"change"_ns, aListener, options, aRv);
RemoveEventListener(u"change"_ns, aListener, options);
}
bool MediaQueryList::HasListeners() const {

View File

@@ -53,8 +53,8 @@ class MediaQueryList final : public DOMEventTargetHelper,
// WebIDL methods
void GetMedia(nsACString& aMedia) const;
bool Matches();
void AddListener(EventListener* aListener, ErrorResult& aRv);
void RemoveListener(EventListener* aListener, ErrorResult& aRv);
void AddListener(EventListener* aListener);
void RemoveListener(EventListener* aListener);
IMPL_EVENT_HANDLER(change)

View File

@@ -1,6 +1,3 @@
[non-fully-active.https.html]
expected:
if (os == "android") and fission: [ERROR, TIMEOUT]
ERROR
[Permission change events shouldn't fire on non-fully active document]
expected: TIMEOUT