mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 478304 - 'Let nsRunnableMethod be used with non-void-returning functions'. r=bsmedberg.
This commit is contained in:
parent
a5d5876901
commit
fc39babfc2
@ -500,30 +500,6 @@ nsACProxyListener::GetInterface(const nsIID & aIID, void **aResult)
|
||||
return QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class to resume timeouts on a window asynchronously.
|
||||
*/
|
||||
class nsResumeTimeoutsRunnable : public nsIRunnable
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsResumeTimeoutsRunnable(nsPIDOMWindow* aWindow)
|
||||
: mWindow(aWindow)
|
||||
{
|
||||
NS_ASSERTION(aWindow, "Null pointer!");
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() {
|
||||
return mWindow->ResumeTimeouts();
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsResumeTimeoutsRunnable, nsIRunnable)
|
||||
|
||||
/**
|
||||
* Gets the nsIDocument given the script context. Will return nsnull on failure.
|
||||
*
|
||||
@ -2813,7 +2789,9 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
|
||||
nsCOMPtr<nsPIDOMWindow> suspendedWindow(do_QueryInterface(topWindow));
|
||||
if (suspendedWindow) {
|
||||
suspendedWindow->SuspendTimeouts();
|
||||
resumeTimeoutRunnable = new nsResumeTimeoutsRunnable(suspendedWindow);
|
||||
resumeTimeoutRunnable = NS_NEW_RUNNABLE_METHOD(nsPIDOMWindow,
|
||||
suspendedWindow.get(),
|
||||
ResumeTimeouts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsXBLBinding.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIXPConnectWrappedJS;
|
||||
@ -61,7 +62,6 @@ class nsStyleSet;
|
||||
class nsXBLBinding;
|
||||
template<class E> class nsRefPtr;
|
||||
typedef nsTArray<nsRefPtr<nsXBLBinding> > nsBindingList;
|
||||
template<class T> class nsRunnableMethod;
|
||||
class nsIPrincipal;
|
||||
|
||||
class nsBindingManager : public nsStubMutationObserver
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "nsRegion.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class nsImageLoader;
|
||||
#ifdef IBMBIDI
|
||||
@ -92,7 +93,6 @@ class nsILookAndFeel;
|
||||
class nsICSSPseudoComparator;
|
||||
class nsIAtom;
|
||||
struct nsStyleBackground;
|
||||
template <class T> class nsRunnableMethod;
|
||||
class nsIRunnable;
|
||||
class gfxUserFontSet;
|
||||
class nsUserFontSet;
|
||||
|
@ -247,13 +247,13 @@ protected:
|
||||
// An event that can be used to call a method on a class. The class type must
|
||||
// support reference counting. This event supports Revoke for use
|
||||
// with nsRevocableEventPtr.
|
||||
template <class T>
|
||||
template <class ClassType, typename ReturnType = void>
|
||||
class nsRunnableMethod : public nsRunnable
|
||||
{
|
||||
public:
|
||||
typedef void (T::*Method)();
|
||||
typedef ReturnType (ClassType::*Method)();
|
||||
|
||||
nsRunnableMethod(T *obj, Method method)
|
||||
nsRunnableMethod(ClassType *obj, Method method)
|
||||
: mObj(obj), mMethod(method) {
|
||||
NS_ADDREF(mObj);
|
||||
}
|
||||
@ -264,18 +264,38 @@ public:
|
||||
(mObj->*mMethod)();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void Revoke() {
|
||||
NS_IF_RELEASE(mObj);
|
||||
}
|
||||
|
||||
private:
|
||||
// These ReturnTypeEnforcer classes set up a blacklist for return types that
|
||||
// we know are not safe. The default ReturnTypeEnforcer compiles just fine but
|
||||
// already_AddRefed will not.
|
||||
template <typename OtherReturnType>
|
||||
class ReturnTypeEnforcer
|
||||
{
|
||||
public:
|
||||
typedef int ReturnTypeIsSafe;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class ReturnTypeEnforcer<already_AddRefed<T> >
|
||||
{
|
||||
// No ReturnTypeIsSafe makes this illegal!
|
||||
};
|
||||
|
||||
// Make sure this return type is safe.
|
||||
typedef typename ReturnTypeEnforcer<ReturnType>::ReturnTypeIsSafe check;
|
||||
|
||||
protected:
|
||||
virtual ~nsRunnableMethod() {
|
||||
NS_IF_RELEASE(mObj);
|
||||
}
|
||||
|
||||
T *mObj;
|
||||
Method mMethod;
|
||||
private:
|
||||
ClassType* mObj;
|
||||
Method mMethod;
|
||||
};
|
||||
|
||||
// Use this helper macro like so:
|
||||
@ -290,8 +310,16 @@ private:
|
||||
//
|
||||
// NOTE: Attempts to make this a template function caused VC6 to barf :-(
|
||||
//
|
||||
|
||||
#define NS_NEW_RUNNABLE_METHOD(class_, obj_, method_) \
|
||||
new nsRunnableMethod<class_>(obj_, &class_::method_)
|
||||
ns_new_runnable_method(obj_, &class_::method_)
|
||||
|
||||
template<class ClassType, typename ReturnType>
|
||||
nsRunnableMethod<ClassType, ReturnType>*
|
||||
ns_new_runnable_method(ClassType* obj, ReturnType (ClassType::*method)())
|
||||
{
|
||||
return new nsRunnableMethod<ClassType, ReturnType>(obj, method);
|
||||
}
|
||||
|
||||
#endif // XPCOM_GLUE_AVOID_NSPR
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user