Bug 1268313: Part 5 - Make NS_NewRunnableMethod able to call const functions. r=froydnj

This commit is contained in:
Kyle Huey 2016-05-05 01:44:59 -07:00
Родитель 156b8c1933
Коммит 7c2af31504
2 изменённых файлов: 32 добавлений и 0 удалений

Просмотреть файл

@ -342,6 +342,15 @@ struct nsRunnableMethodTraits<R(C::*)(As...), Owning, Cancelable>
static const bool can_cancel = Cancelable;
};
template<class C, typename R, bool Owning, bool Cancelable, typename... As>
struct nsRunnableMethodTraits<R(C::*)(As...) const, Owning, Cancelable>
{
typedef const C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
#ifdef NS_HAVE_STDCALL
template<class C, typename R, bool Owning, bool Cancelable, typename... As>
struct nsRunnableMethodTraits<R(__stdcall C::*)(As...), Owning, Cancelable>
@ -360,6 +369,23 @@ struct nsRunnableMethodTraits<R(NS_STDCALL C::*)(), Owning, Cancelable>
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
template<class C, typename R, bool Owning, bool Cancelable, typename... As>
struct nsRunnableMethodTraits<R(__stdcall C::*)(As...) const, Owning, Cancelable>
{
typedef const C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
template<class C, typename R, bool Owning, bool Cancelable>
struct nsRunnableMethodTraits<R(NS_STDCALL C::*)() const, Owning, Cancelable>
{
typedef const C class_type;
typedef R return_type;
typedef nsRunnableMethod<C, R, Owning, Cancelable> base_type;
static const bool can_cancel = Cancelable;
};
#endif

Просмотреть файл

@ -7,6 +7,7 @@
enum {
TEST_CALL_VOID_ARG_VOID_RETURN,
TEST_CALL_VOID_ARG_VOID_RETURN_CONST,
TEST_CALL_VOID_ARG_NONVOID_RETURN,
TEST_CALL_NONVOID_ARG_VOID_RETURN,
TEST_CALL_NONVOID_ARG_NONVOID_RETURN,
@ -63,6 +64,9 @@ public:
void DoBar1(void) {
gRunnableExecuted[TEST_CALL_VOID_ARG_VOID_RETURN] = true;
}
void DoBar1Const(void) const {
gRunnableExecuted[TEST_CALL_VOID_ARG_VOID_RETURN_CONST] = true;
}
nsresult DoBar2(void) {
gRunnableExecuted[TEST_CALL_VOID_ARG_NONVOID_RETURN] = true;
return NS_OK;
@ -120,6 +124,7 @@ int main(int argc, char** argv)
{
RefPtr<nsFoo> foo = new nsFoo();
RefPtr<nsBar> bar = new nsBar();
RefPtr<const nsBar> constBar = bar;
// This pointer will be freed at the end of the block
// Do not dereference this pointer in the runnable method!
@ -129,6 +134,7 @@ int main(int argc, char** argv)
char* message = (char*)"Test message";
NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar1));
NS_DispatchToMainThread(NS_NewRunnableMethod(constBar, &nsBar::DoBar1Const));
NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar2));
NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< RefPtr<nsFoo> >
(bar, &nsBar::DoBar3, foo));