Bug 950657. Give WebIDL callbacks an operator== that does the right thing. r=smaug

This commit is contained in:
Boris Zbarsky 2013-12-16 13:06:35 -05:00
parent 62323b2df8
commit 5636812c55
4 changed files with 18 additions and 16 deletions

View File

@ -102,6 +102,15 @@ protected:
Init(aCallbackObject->mCallback, aCallbackObject->mIncumbentGlobal);
}
bool operator==(const CallbackObject& aOther) const
{
JSObject* thisObj =
js::UncheckedUnwrap(CallbackPreserveColor());
JSObject* otherObj =
js::UncheckedUnwrap(aOther.CallbackPreserveColor());
return thisObj == otherObj;
}
private:
inline void Init(JSObject* aCallback, nsIGlobalObject* aIncumbentGlobal)
{
@ -304,11 +313,7 @@ public:
return false;
}
JSObject* thisObj =
js::UncheckedUnwrap(GetWebIDLCallback()->CallbackPreserveColor());
JSObject* otherObj =
js::UncheckedUnwrap(aOtherCallback->CallbackPreserveColor());
return thisObj == otherObj;
return *GetWebIDLCallback() == *aOtherCallback;
}
bool operator==(XPCOMCallbackT* aOtherCallback) const

View File

@ -10726,6 +10726,12 @@ class CGCallback(CGClass):
realMethods.append(method)
else:
realMethods.extend(self.getMethodImpls(method))
realMethods.append(
ClassMethod("operator==", "bool",
[Argument("const %s&" % name, "aOther")],
inline=True, bodyInHeader=True,
const=True,
body=("return %s::operator==(aOther);" % baseName)))
CGClass.__init__(self, name,
bases=[ClassBase(baseName)],
constructors=self.getConstructors(),

View File

@ -137,11 +137,8 @@ MediaQueryList::AddListener(MediaQueryListListener& aListener)
RecomputeMatches();
}
CallbackType callback(&aListener);
for (uint32_t i = 0; i < mCallbacks.Length(); ++i) {
CallbackType thisCallback(mCallbacks[i]);
if (callback == thisCallback) {
if (aListener == *mCallbacks[i]) {
// Already registered
return;
}
@ -172,11 +169,8 @@ MediaQueryList::RemoveListener(nsIDOMMediaQueryListListener *aListener)
void
MediaQueryList::RemoveListener(MediaQueryListListener& aListener)
{
CallbackType callback(&aListener);
for (uint32_t i = 0; i < mCallbacks.Length(); ++i) {
CallbackType thisCallback(mCallbacks[i]);
if (callback == thisCallback) {
if (aListener == *mCallbacks[i]) {
mCallbacks.RemoveElementAt(i);
if (!HasListeners()) {
// See NS_ADDREF_THIS() in AddListener.

View File

@ -44,9 +44,6 @@ public:
nsISupports* GetParentObject() const;
typedef CallbackObjectHolder<mozilla::dom::MediaQueryListListener,
nsIDOMMediaQueryListListener> CallbackType;
struct HandleChangeData {
nsRefPtr<MediaQueryList> mql;
nsCOMPtr<nsIDOMMediaQueryListListener> listener;