зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1453345 part 4. Stop using XPCWrappedJS implementing nsIDOMEventListener in EventListenerInfo. r=smaug
MozReview-Commit-ID: I5oYAYaA6CV
This commit is contained in:
Родитель
4cfde58ac8
Коммит
3914e3a54e
|
@ -22,6 +22,7 @@
|
|||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/EventTargetBinding.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/TouchEvent.h"
|
||||
#include "mozilla/TimelineConsumers.h"
|
||||
#include "mozilla/EventTimelineMarker.h"
|
||||
|
@ -1569,16 +1570,28 @@ EventListenerManager::GetListenerInfo(nsCOMArray<nsIEventListenerInfo>* aList)
|
|||
} else {
|
||||
eventType.Assign(Substring(nsDependentAtomString(listener.mTypeAtom), 2));
|
||||
}
|
||||
nsCOMPtr<nsIDOMEventListener> callback = listener.mListener.ToXPCOMCallback();
|
||||
if (!callback) {
|
||||
// This will be null for cross-compartment event listeners which have been
|
||||
// destroyed.
|
||||
continue;
|
||||
|
||||
JS::Rooted<JSObject*> callback(RootingCx());
|
||||
if (JSEventHandler* handler = listener.GetJSEventHandler()) {
|
||||
if (handler->GetTypedEventHandler().HasEventHandler()) {
|
||||
callback = handler->GetTypedEventHandler().Ptr()->CallableOrNull();
|
||||
if (!callback) {
|
||||
// This will be null for cross-compartment event listeners
|
||||
// which have been destroyed.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (listener.mListenerType == Listener::eWebIDLListener) {
|
||||
callback = listener.mListener.GetWebIDLCallback()->CallbackOrNull();
|
||||
if (!callback) {
|
||||
// This will be null for cross-compartment event listeners
|
||||
// which have been destroyed.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// EventListenerInfo is defined in XPCOM, so we have to go ahead
|
||||
// and convert to an XPCOM callback here...
|
||||
|
||||
RefPtr<EventListenerInfo> info =
|
||||
new EventListenerInfo(eventType, callback.forget(),
|
||||
new EventListenerInfo(eventType, callback,
|
||||
listener.mFlags.mCapture,
|
||||
listener.mFlags.mAllowUntrustedEvents,
|
||||
listener.mFlags.mInSystemGroup);
|
||||
|
|
|
@ -80,7 +80,37 @@ EventListenerChange::GetCountOfEventListenerChangesAffectingAccessibility(
|
|||
* mozilla::EventListenerInfo
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(EventListenerInfo, mListener)
|
||||
EventListenerInfo::EventListenerInfo(const nsAString& aType,
|
||||
JS::Handle<JSObject*> aScriptedListener,
|
||||
bool aCapturing,
|
||||
bool aAllowsUntrusted,
|
||||
bool aInSystemEventGroup)
|
||||
: mType(aType)
|
||||
, mScriptedListener(aScriptedListener)
|
||||
, mCapturing(aCapturing)
|
||||
, mAllowsUntrusted(aAllowsUntrusted)
|
||||
, mInSystemEventGroup(aInSystemEventGroup)
|
||||
{
|
||||
HoldJSObjects(this);
|
||||
}
|
||||
|
||||
EventListenerInfo::~EventListenerInfo()
|
||||
{
|
||||
DropJSObjects(this);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(EventListenerInfo)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EventListenerInfo)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EventListenerInfo)
|
||||
tmp->mScriptedListener = nullptr;
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(EventListenerInfo)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptedListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EventListenerInfo)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIEventListenerInfo)
|
||||
|
@ -138,28 +168,13 @@ EventListenerInfo::GetJSVal(JSContext* aCx,
|
|||
Maybe<JSAutoCompartment>& aAc,
|
||||
JS::MutableHandle<JS::Value> aJSVal)
|
||||
{
|
||||
aJSVal.setNull();
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(mListener);
|
||||
if (wrappedJS) {
|
||||
JS::Rooted<JSObject*> object(aCx, wrappedJS->GetJSObject());
|
||||
if (!object) {
|
||||
return false;
|
||||
}
|
||||
aAc.emplace(aCx, object);
|
||||
aJSVal.setObject(*object);
|
||||
if (mScriptedListener) {
|
||||
aJSVal.setObject(*mScriptedListener);
|
||||
aAc.emplace(aCx, mScriptedListener);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<JSEventHandler> jsHandler = do_QueryInterface(mListener);
|
||||
if (jsHandler && jsHandler->GetTypedEventHandler().HasEventHandler()) {
|
||||
JS::Handle<JSObject*> handler =
|
||||
jsHandler->GetTypedEventHandler().Ptr()->CallableOrNull();
|
||||
if (handler) {
|
||||
aAc.emplace(aCx, handler);
|
||||
aJSVal.setObject(*handler);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
aJSVal.setNull();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,32 +48,24 @@ class EventListenerInfo final : public nsIEventListenerInfo
|
|||
{
|
||||
public:
|
||||
EventListenerInfo(const nsAString& aType,
|
||||
already_AddRefed<nsIDOMEventListener> aListener,
|
||||
JS::Handle<JSObject*> aScriptedListener,
|
||||
bool aCapturing,
|
||||
bool aAllowsUntrusted,
|
||||
bool aInSystemEventGroup)
|
||||
: mType(aType)
|
||||
, mListener(aListener)
|
||||
, mCapturing(aCapturing)
|
||||
, mAllowsUntrusted(aAllowsUntrusted)
|
||||
, mInSystemEventGroup(aInSystemEventGroup)
|
||||
{
|
||||
}
|
||||
bool aInSystemEventGroup);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(EventListenerInfo)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(EventListenerInfo)
|
||||
NS_DECL_NSIEVENTLISTENERINFO
|
||||
|
||||
protected:
|
||||
virtual ~EventListenerInfo() {}
|
||||
virtual ~EventListenerInfo();
|
||||
|
||||
bool GetJSVal(JSContext* aCx,
|
||||
Maybe<JSAutoCompartment>& aAc,
|
||||
JS::MutableHandle<JS::Value> aJSVal);
|
||||
|
||||
nsString mType;
|
||||
// nsReftPtr because that is what nsListenerStruct uses too.
|
||||
RefPtr<nsIDOMEventListener> mListener;
|
||||
JS::Heap<JSObject*> mScriptedListener; // May be null.
|
||||
bool mCapturing;
|
||||
bool mAllowsUntrusted;
|
||||
bool mInSystemEventGroup;
|
||||
|
|
Загрузка…
Ссылка в новой задаче