@@ -59,15 +59,15 @@ struct callback_helper {
59
59
60
60
struct callback_args {
61
61
62
- v8 ::Persistent<Function, v8 ::CopyablePersistentTraits<Function> >* callback;
62
+ Nan ::Persistent<Function, Nan ::CopyablePersistentTraits<Function> >* callback;
63
63
char **stack;
64
64
size_t stack_size;
65
65
int signo;
66
66
long addr;
67
67
pthread_mutex_t mutex;
68
68
pthread_cond_t cond;
69
69
70
- callback_args (v8 ::Persistent<Function, v8 ::CopyablePersistentTraits<Function> >* callback, void * const * stack, size_t stack_size, int signo, long addr) :
70
+ callback_args (Nan ::Persistent<Function, Nan ::CopyablePersistentTraits<Function> >* callback, void * const * stack, size_t stack_size, int signo, long addr) :
71
71
callback (callback), stack(backtrace_symbols(stack, stack_size)), stack_size(stack_size), signo(signo), addr(addr) {
72
72
pthread_mutex_init (&mutex, NULL );
73
73
pthread_cond_init (&cond, NULL );
@@ -81,12 +81,11 @@ struct callback_helper {
81
81
};
82
82
83
83
uv_async_t * handle;
84
- v8 ::Persistent<Function, v8 ::CopyablePersistentTraits<Function> > callback;
84
+ Nan ::Persistent<Function, Nan ::CopyablePersistentTraits<Function> > callback;
85
85
86
86
callback_helper (Local<Function> func) {
87
- Isolate* isolate = Isolate::GetCurrent ();
88
87
// set the function reference
89
- callback.Reset (isolate, func);
88
+ callback.Reset (func);
90
89
91
90
// create the callback handle
92
91
handle = (uv_async_t *) malloc (sizeof (uv_async_t ));
@@ -113,7 +112,11 @@ struct callback_helper {
113
112
// directly execute the callback if we're on the main thread,
114
113
// otherwise have uv send it and await the mutex
115
114
if (Isolate::GetCurrent ()) {
115
+ #if defined(UV_VERSION_MAJOR) && UV_VERSION_MAJOR > 0
116
116
make_callback (handle);
117
+ #else
118
+ make_callback (handle, 0 );
119
+ #endif
117
120
} else {
118
121
// lock the callback mutex
119
122
pthread_mutex_lock (&args->mutex );
@@ -137,26 +140,30 @@ struct callback_helper {
137
140
free (handle);
138
141
}
139
142
143
+ #if defined(UV_VERSION_MAJOR) && UV_VERSION_MAJOR > 0
140
144
static void make_callback (uv_async_t * handle) {
141
- Isolate* isolate = Isolate::GetCurrent ();
142
- v8::HandleScope scope (isolate);
145
+ #else
146
+ static void make_callback (uv_async_t * handle, int status) {
147
+ #endif
148
+
149
+ Nan::HandleScope scope;
143
150
144
151
struct callback_args * args = (struct callback_args *) handle->data ;
145
152
146
153
// lock the mutex
147
154
pthread_mutex_lock (&args->mutex );
148
155
149
156
// build the stack arguments
150
- Local<Array> argStack = Array ::New(isolate, args->stack_size );
157
+ Local<Array> argStack = Nan ::New<Array>( args->stack_size );
151
158
for (size_t i = 0 ; i < args->stack_size ; i++) {
152
- Nan::Set (argStack, i, String::NewFromUtf8 (isolate, args->stack [i], v8::NewStringType:: kInternalized ).ToLocalChecked ());
159
+ Nan::Set (argStack, i, Nan::New<String>( args->stack [i]).ToLocalChecked ());
153
160
}
154
161
155
162
// collect all callback arguments
156
- Local<Value> argv[3 ] = {Number ::New(isolate, args->signo ), Number ::New(isolate, args->addr ), argStack};
163
+ Local<Value> argv[3 ] = {Nan ::New<Number>( args->signo ), Nan ::New<Number>( args->addr ), argStack};
157
164
158
165
// execute the callback function on the main threaod
159
- Nan::Call (Local<Function> ::New (isolate, *args->callback ), isolate-> GetCurrentContext ()->Global (), 3 , argv);
166
+ Nan::Call (Nan ::New<Function>( *args->callback ), Nan:: GetCurrentContext ()->Global (), 3 , argv);
160
167
161
168
// broadcast that we're done with the callback
162
169
pthread_cond_broadcast (&args->cond );
0 commit comments