Skip to content

Commit

Permalink
Removed need for NAN_GC_CALLBACK
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Oct 9, 2015
1 parent 9f42b4c commit 522aa35
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
71 changes: 43 additions & 28 deletions nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GCCallback F>
class GCCallback {
public:
static void call(
v8::Isolate *isolate, v8::GCType type, v8::GCCallbackFlags flags) {
F(type, flags);
}
};
}

template<GCCallback F>
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<F>::call, gc_type_filter);
}

NAN_INLINE void RemoveGCEpilogueCallback(
v8::Isolate::GCEpilogueCallback callback) {
v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(callback);
template<GCCallback F>
NAN_INLINE void RemoveGCEpilogueCallback() {
v8::Isolate::GetCurrent()->RemoveGCEpilogueCallback(
imp::GCCallback<F>::call);
}

template<GCCallback F>
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<F>::call, gc_type_filter);
}

NAN_INLINE void RemoveGCPrologueCallback(
v8::Isolate::GCPrologueCallback callback) {
v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(callback);
template<GCCallback F>
NAN_INLINE void RemoveGCPrologueCallback() {
v8::Isolate::GetCurrent()->RemoveGCPrologueCallback(
imp::GCCallback<F>::call);
}

NAN_INLINE void GetHeapStatistics(
Expand Down Expand Up @@ -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<GCCallback F>
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<GCCallback F>
NAN_INLINE void RemoveGCEpilogueCallback() {
v8::V8::RemoveGCEpilogueCallback(F);
}
template<GCCallback F>
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<GCCallback F>
NAN_INLINE void RemoveGCPrologueCallback() {
v8::V8::RemoveGCPrologueCallback(F);
}
NAN_INLINE void GetHeapStatistics(
v8::HeapStatistics *heap_statistics) {
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions test/cpp/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@ NAN_GC_CALLBACK(gcEpilogueCallback) {
}

NAN_METHOD(Hook) {
AddGCPrologueCallback(gcPrologueCallback);
AddGCEpilogueCallback(gcEpilogueCallback);
AddGCPrologueCallback<gcPrologueCallback>();
AddGCEpilogueCallback<gcEpilogueCallback>();
info.GetReturnValue().SetUndefined();
}

NAN_METHOD(Check) {
HandleScope scope;
info.GetReturnValue().Set(
New(prologue_called && epilogue_called));
RemoveGCPrologueCallback<gcPrologueCallback>();
RemoveGCEpilogueCallback<gcEpilogueCallback>();
}

NAN_MODULE_INIT(Init) {
Set(target
, New<v8::String>("hook").ToLocalChecked()
, New<v8::FunctionTemplate>(Hook)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Hook)).ToLocalChecked()
);
Set(target
, New<v8::String>("check").ToLocalChecked()
, New<v8::FunctionTemplate>(Check)->GetFunction()
, GetFunction(New<v8::FunctionTemplate>(Check)).ToLocalChecked()
);
}

Expand Down

0 comments on commit 522aa35

Please sign in to comment.