diff --git a/nan.h b/nan.h index a5cd8955..69e34875 100644 --- a/nan.h +++ b/nan.h @@ -595,29 +595,43 @@ class TryCatch { object->SetAlignedPointerInInternalField(index, value); } -# define NAN_GC_CALLBACK(name) \ - void name(v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) + typedef void (*GCCallback)(v8::GCType type, v8::GCCallbackFlags flags); +namespace imp { + template + class GCCallback { + public: + static void call( + v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) { + F(type, flags); + } + }; +} + + template NAN_INLINE void AddGCEpilogueCallback( - v8::Isolate::GCEpilogueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::Isolate::GetCurrent()->AddGCEpilogueCallback(callback, gc_type_filter); + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCEpilogueCallback( + imp::GCCallback::call, gc_type_filter); } - NAN_INLINE void RemoveGCEpilogueCallback( - v8::Isolate::GCEpilogueCallback callback) { - v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(callback); + template + NAN_INLINE void RemoveGCEpilogueCallback() { + v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback( + imp::GCCallback::call); } + template NAN_INLINE void AddGCPrologueCallback( - v8::Isolate::GCPrologueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::Isolate::GetCurrent()->AddGCPrologueCallback(callback, gc_type_filter); + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::Isolate::GetCurrent()->AddGCPrologueCallback( + imp::GCCallback::call, gc_type_filter); } - NAN_INLINE void RemoveGCPrologueCallback( - v8::Isolate::GCPrologueCallback callback) { - v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(callback); + template + NAN_INLINE void RemoveGCPrologueCallback() { + v8::Isolate::GetCurrent()->RemoveGCPrologueCallback( + imp::GCCallback::call); } NAN_INLINE void GetHeapStatistics( @@ -981,26 +995,25 @@ class Utf8String { object->SetPointerInInternalField(index, value); } -# define NAN_GC_CALLBACK(name) \ - void name(v8::GCType type, v8::GCCallbackFlags flags) + typedef void (*GCCallback)(v8::GCType type, v8::GCCallbackFlags flags); + template NAN_INLINE void AddGCEpilogueCallback( - v8::GCEpilogueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::V8::AddGCEpilogueCallback(callback, gc_type_filter); + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCEpilogueCallback(F, gc_type_filter); } - NAN_INLINE void RemoveGCEpilogueCallback( - v8::GCEpilogueCallback callback) { - v8::V8::RemoveGCEpilogueCallback(callback); + template + NAN_INLINE void RemoveGCEpilogueCallback() { + v8::V8::RemoveGCEpilogueCallback(F); } + template NAN_INLINE void AddGCPrologueCallback( - v8::GCPrologueCallback callback - , v8::GCType gc_type_filter = v8::kGCTypeAll) { - v8::V8::AddGCPrologueCallback(callback, gc_type_filter); + v8::GCType gc_type_filter = v8::kGCTypeAll) { + v8::V8::AddGCPrologueCallback(F, gc_type_filter); } - NAN_INLINE void RemoveGCPrologueCallback( - v8::GCPrologueCallback callback) { - v8::V8::RemoveGCPrologueCallback(callback); + template + NAN_INLINE void RemoveGCPrologueCallback() { + v8::V8::RemoveGCPrologueCallback(F); } NAN_INLINE void GetHeapStatistics( v8::HeapStatistics *heap_statistics) { @@ -1341,6 +1354,8 @@ typedef void NAN_INDEX_QUERY_RETURN_TYPE; Nan::NAN_INDEX_QUERY_RETURN_TYPE name( \ uint32_t index \ , Nan::NAN_INDEX_QUERY_ARGS_TYPE info) +# define NAN_GC_CALLBACK(name) \ + void name(v8::GCType type, v8::GCCallbackFlags flags) class Callback { public: diff --git a/test/cpp/gc.cpp b/test/cpp/gc.cpp index 67b6b8bd..4bfded8d 100644 --- a/test/cpp/gc.cpp +++ b/test/cpp/gc.cpp @@ -22,8 +22,8 @@ NAN_GC_CALLBACK(gcEpilogueCallback) { } NAN_METHOD(Hook) { - AddGCPrologueCallback(gcPrologueCallback); - AddGCEpilogueCallback(gcEpilogueCallback); + AddGCPrologueCallback(); + AddGCEpilogueCallback(); info.GetReturnValue().SetUndefined(); } @@ -31,16 +31,18 @@ NAN_METHOD(Check) { HandleScope scope; info.GetReturnValue().Set( New(prologue_called && epilogue_called)); + RemoveGCPrologueCallback(); + RemoveGCEpilogueCallback(); } NAN_MODULE_INIT(Init) { Set(target , New("hook").ToLocalChecked() - , New(Hook)->GetFunction() + , GetFunction(New(Hook)).ToLocalChecked() ); Set(target , New("check").ToLocalChecked() - , New(Check)->GetFunction() + , GetFunction(New(Check)).ToLocalChecked() ); }