From 25a2bbb950b483e63e97fc0bf7d39fbb04b8acee Mon Sep 17 00:00:00 2001 From: datenpunk Date: Tue, 1 Sep 2015 13:56:52 +0200 Subject: [PATCH] Ported to Nan2 --- binding.gyp | 3 +++ package.json | 7 +++++- src/GcProfiler.cc | 57 ++++++++++++++++++++++++----------------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/binding.gyp b/binding.gyp index 1238a38..57f76ca 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,6 +3,9 @@ { "target_name": "GcProfiler", "sources": [ "src/GcProfiler.cc" ], + "include_dirs": [ + "", + "contributors": [{ + "name": "Daniel Khan", + "email": "daniel@khan.io" + }], "main": "./main.js", + "gypfile": true, "repository": { "type": "git", "url": "https://github.com/bretcope/node-gc-profiler.git" @@ -16,6 +21,6 @@ ], "license": "MIT", "dependencies": { - "nan": "^1.6.2" + "nan": "^2.0.8" } } diff --git a/src/GcProfiler.cc b/src/GcProfiler.cc index 49d88cb..ad4d60a 100644 --- a/src/GcProfiler.cc +++ b/src/GcProfiler.cc @@ -1,5 +1,5 @@ #include -#include "../node_modules/nan/nan.h" +#include #include #ifdef WIN32 @@ -26,8 +26,8 @@ namespace GcProfiler // static variables GcProfilerData * _data; - Persistent _callback; - Persistent _context; + Nan::Persistent _callback; + // Nan::Persistent _context; #ifdef WIN32 @@ -41,7 +41,7 @@ namespace GcProfiler #endif // function prototypes - void Init(Handle exports); + void Init(v8::Local exports, v8::Local module); NAN_METHOD(LoadProfiler); NAN_GC_CALLBACK(Before); NAN_GC_CALLBACK(After); @@ -55,27 +55,28 @@ namespace GcProfiler // --- functions --- - void Init (Handle exports) + void Init (v8::Local exports, v8::Local module) { - NODE_SET_METHOD(exports, "loadProfiler", LoadProfiler); + exports->Set(Nan::New("loadProfiler").ToLocalChecked(), Nan::New(LoadProfiler)->GetFunction()); } - NAN_METHOD(LoadProfiler) - { - NanScope(); - - if (args.Length() == 0 || !args[0]->IsFunction()) - { - NanThrowTypeError("Must provide a callback function to the profiler."); - } - - NanAssignPersistent(_callback, args[0].As()); - NanAddGCPrologueCallback(Before); - NanAddGCEpilogueCallback(After); - - NanReturnUndefined(); + + void LoadProfiler(const Nan::FunctionCallbackInfo& info) { + + if (info.Length() == 0 || !info[0]->IsFunction()) + { + Nan::ThrowTypeError("Must provide a callback function to the profiler."); + return; + } + + _callback.Reset(Nan::Persistent(info[0].As())); + + Nan::AddGCPrologueCallback(Before); + Nan::AddGCEpilogueCallback(After); + + return info.GetReturnValue().SetUndefined(); } - + NAN_GC_CALLBACK(Before) { _data = new GcProfilerData(); @@ -101,20 +102,20 @@ namespace GcProfiler void UvAsyncAfter(uv_work_t * req) { - NanScope(); + Nan::HandleScope scope; GcProfilerData * data = (GcProfilerData*)req->data; const unsigned argc = 4; - Handle argv[argc] = { - NanNew(data->startTime), - NanNew(data->duration), - NanNew((int)data->type), - NanNew((int)data->flags) + v8::Local argv[argc] = { + Nan::New(data->startTime), + Nan::New(data->duration), + Nan::New((int)data->type), + Nan::New((int)data->flags) }; delete data; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(_callback), argc, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(_callback), argc, argv); } #ifdef __MACH__