99#include < dirent.h>
1010#include < math.h>
1111#include < node.h>
12+ #include < node_internals.h>
1213#include < v8.h>
1314#include < v8-debug.h>
1415#include < unistd.h>
2829#include < sys/time.h>
2930#include < algorithm>
3031
32+ #include < nan.h>
33+
3134#ifdef __APPLE__
3235 #include < sys/sysctl.h>
3336 #include < crt_externs.h>
3740#endif
3841
3942#define THROW_BAD_ARGS () \
40- return ThrowException( \
43+ NanReturnValue ( ThrowException( \
4144 Exception::TypeError (String::New(__FUNCTION__)) \
42- )
45+ ))
4346
4447
4548using namespace std;
@@ -135,7 +138,11 @@ void NodeMonitor::setStatistics() {
135138
136139 // obtain memory ration
137140 v8::HeapStatistics v8stats;
141+ #if (NODE_MODULE_VERSION > 0x000B)
142+ nan_isolate->GetHeapStatistics (&v8stats);
143+ #else
138144 V8::GetHeapStatistics (&v8stats);
145+ #endif
139146 double pmem = (v8stats.used_heap_size () / (double ) v8stats.total_heap_size ());
140147
141148 // Obtains the CPU usage
@@ -318,7 +325,7 @@ void CpuUsageTracker::CalculateCpuUsage(CpuUsage* cur_usage,
318325
319326// calls the function which return the Int value
320327unsigned int NodeMonitor::getIntFunction (const char * funcName) {
321- HandleScope scope ;
328+ NanScope () ;
322329
323330 Local<Value> pr = Context::GetCurrent ()->Global ()->Get (String::New (" process" ));
324331
@@ -329,7 +336,7 @@ unsigned int NodeMonitor::getIntFunction(const char* funcName) {
329336 if (fval->IsFunction ()) {
330337 Local<Function> fn = Local<Function>::Cast (fval);
331338 Local<Value> argv[1 ];
332- argv[0 ] = Local <Value>:: New (Null ());
339+ argv[0 ] = NanNewLocal <Value>(Null ());
333340 Local<Value> res = fn->Call (Context::GetCurrent ()->Global (), 1 , argv);
334341 if (res->IsNumber ()) {
335342 return res->Uint32Value ();
@@ -508,29 +515,32 @@ NodeMonitor::NodeMonitor() :
508515 memset (&ipcAddr_, 0 ,sizeof (struct sockaddr_un ));
509516}
510517
511- static Handle<Value> GetterIPCMonitorPath (Local<String> property,
512- const AccessorInfo& info) {
513- return String::New (_ipcMonitorPath.c_str ());
518+ static NAN_GETTER (GetterIPCMonitorPath) {
519+ NanScope ();
520+ NanReturnValue ( String::New (_ipcMonitorPath.c_str () ));
514521}
515522
516- static Handle<Value> SetterIPCMonitorPath (const Arguments& args) {
523+ static NAN_METHOD (SetterIPCMonitorPath) {
524+ NanScope ();
517525 if (args.Length () < 1 ||
518526 (!args[0 ]->IsString () && !args[0 ]->IsUndefined () && !args[0 ]->IsNull ())) {
519527 THROW_BAD_ARGS ();
520528 }
521529 String::Utf8Value ipcMonitorPath (args[0 ]);
522530 _ipcMonitorPath = *ipcMonitorPath;
523- return Undefined (); ;
531+ NanReturnValue ( Undefined ()) ;
524532}
525533
526- static Handle<Value> StartMonitor (const Arguments& args) {
534+ static NAN_METHOD (StartMonitor) {
535+ NanScope ();
527536 NodeMonitor::Initialize ();
528- return Undefined ();
537+ NanReturnValue ( Undefined () );
529538}
530539
531- static Handle<Value> StopMonitor (const Arguments& args) {
540+ static NAN_METHOD (StopMonitor) {
541+ NanScope ();
532542 NodeMonitor::Stop ();
533- return Undefined ();
543+ NanReturnValue ( Undefined () );
534544}
535545
536546void LogStackTrace (Handle<Object> obj) {
@@ -573,19 +583,31 @@ void DebugEventHandler(DebugEvent event,
573583 LogStackTrace (exec_state);
574584}
575585
586+ void DebugEventHandler2 (const v8::Debug::EventDetails& event_details) {
587+ LogStackTrace (event_details.GetExecutionState ());
588+ }
589+
576590static void SignalHangupHandler (int signal) {
591+ #if (NODE_MODULE_VERSION > 0x000B)
592+ // Node 0.11+
593+ v8::Debug::SetDebugEventListener2 (DebugEventHandler2);
594+ #else
577595 v8::Debug::SetDebugEventListener (DebugEventHandler);
596+ #endif
578597 v8::Debug::DebugBreak ();
579598}
580599
581600extern " C" void
582601init (Handle<Object> target) {
583- HandleScope scope ;
602+ NanScope () ;
584603
585604 NODE_PROT_RO_PROPERTY (target, " ipcMonitorPath" , GetterIPCMonitorPath);
586- NODE_SET_METHOD (target, " setIpcMonitorPath" , SetterIPCMonitorPath);
587- NODE_SET_METHOD (target, " start" , StartMonitor);
588- NODE_SET_METHOD (target, " stop" , StopMonitor);
605+ target->Set (NanSymbol (" setIpcMonitorPath" ),
606+ FunctionTemplate::New (SetterIPCMonitorPath)->GetFunction ());
607+ target->Set (NanSymbol (" start" ),
608+ FunctionTemplate::New (StartMonitor)->GetFunction ());
609+ target->Set (NanSymbol (" stop" ),
610+ FunctionTemplate::New (StopMonitor)->GetFunction ());
589611
590612 RegisterSignalHandler (SIGHUP, SignalHangupHandler);
591613}
0 commit comments