Skip to content

Commit 8a9e67a

Browse files
committed
Adds support for node 0.10.x and 0.12.x in the same version.
1 parent 7e08d3f commit 8a9e67a

File tree

11 files changed

+42
-59
lines changed

11 files changed

+42
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vagrant
12
node_modules
23
build
34
.lock-*

.vagrant/machines/default/virtualbox/action_provision

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vagrant/machines/default/virtualbox/action_set_name

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vagrant/machines/default/virtualbox/id

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vagrant/machines/default/virtualbox/index_uuid

Lines changed: 0 additions & 1 deletion
This file was deleted.

.vagrant/machines/default/virtualbox/private_key

Lines changed: 0 additions & 27 deletions
This file was deleted.

.vagrant/machines/default/virtualbox/synced_folders

Lines changed: 0 additions & 1 deletion
This file was deleted.

Vagrantfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
$script = <<SCRIPT
2-
sudo apt-get update -y
3-
apt-get install -y build-essential
2+
sudo apt-get install -y build-essential
43
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
4+
# curl -sL https://deb.nodesource.com/setup_0.10 | sudo bash -
5+
# curl -sL https://deb.nodesource.com/setup_iojs_1.x | sudo bash -
56
sudo apt-get install -y nodejs
7+
sudo npm install -g node-gyp
68
SCRIPT
79

810
Vagrant.configure("2") do |config|

src/bindings.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ namespace NodeInotify {
179179
Local<Integer> descriptor = NanNew<Integer>(watch_descriptor);
180180

181181
//Local<Function> callback = Local<Function>::Cast(args_->Get(callback_sym));
182+
#if NODE_VERSION_AT_LEAST(0, 11, 0)
182183
inotify->handle()->Set(descriptor, args_->Get(callback_sym));
184+
#else
185+
inotify->handle_->Set(descriptor, args_->Get(callback_sym));
186+
#endif
183187

184188
NanReturnValue(descriptor);
185189
}
@@ -269,16 +273,23 @@ namespace NodeInotify {
269273
argv[0] = obj;
270274

271275
inotify->Ref();
272-
Local<Value> callback_ = inotify->handle()->Get(NanNew<Integer>(event->wd));
276+
277+
#if NODE_VERSION_AT_LEAST(0, 11, 0)
278+
Local<Object> handle = inotify->handle();
279+
#else
280+
Persistent<Object> handle = inotify->handle_;
281+
#endif
282+
283+
Local<Value> callback_ = handle->Get(NanNew<Integer>(event->wd));
273284
Local<Function> callback = Local<Function>::Cast(callback_);
274285

275-
callback->Call(inotify->handle(), 1, argv);
286+
callback->Call(handle, 1, argv);
276287
inotify->Unref();
277288

278289
if(event->mask & IN_IGNORED) {
279290
//deleting callback because the watch was removed
280291
Local<Value> wd = NanNew<Integer>(event->wd);
281-
inotify->handle()->Delete(wd->ToString());
292+
handle->Delete(wd->ToString());
282293
}
283294

284295
if (try_catch.HasCaught()) {
@@ -289,6 +300,7 @@ namespace NodeInotify {
289300
}
290301

291302
NAN_GETTER(Inotify::GetPersistent) {
303+
NanScope();
292304
Inotify *inotify = ObjectWrap::Unwrap<Inotify>(args.This());
293305

294306
if (inotify->persistent) {
@@ -305,5 +317,4 @@ namespace NodeInotify {
305317
poll_stopped = 1;
306318
}
307319
}
308-
309320
}//namespace NodeInotify

src/bindings.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55

66
namespace NodeInotify {
77

8-
class Inotify : public ObjectWrap {
9-
public:
10-
static void Initialize(Handle<Object> target);
8+
class Inotify : public ObjectWrap {
9+
public:
10+
static void Initialize(Handle<Object> target);
1111

12-
Inotify();
13-
Inotify(bool nonpersistent);
14-
virtual ~Inotify();
15-
protected:
16-
static NAN_METHOD(New);
17-
static NAN_METHOD(AddWatch);
18-
static NAN_METHOD(RemoveWatch);
19-
static NAN_METHOD(Close);
20-
static NAN_GETTER(GetPersistent);
12+
Inotify();
13+
Inotify(bool nonpersistent);
14+
virtual ~Inotify();
15+
protected:
16+
static NAN_METHOD(New);
17+
static NAN_METHOD(AddWatch);
18+
static NAN_METHOD(RemoveWatch);
19+
static NAN_METHOD(Close);
20+
static NAN_GETTER(GetPersistent);
2121

22-
private:
23-
int fd;
24-
uv_poll_t* read_watcher;
25-
bool persistent;
26-
char poll_stopped;
27-
void StopPolling();
28-
static void Callback(uv_poll_t* watcher, int status, int revents);
29-
static void on_handle_close(uv_handle_t* handle);
30-
};
22+
private:
23+
int fd;
24+
uv_poll_t* read_watcher;
25+
bool persistent;
26+
char poll_stopped;
27+
void StopPolling();
28+
static void Callback(uv_poll_t* watcher, int status, int revents);
29+
static void on_handle_close(uv_handle_t* handle);
30+
};
3131

3232
} //namespace NodeInotify
3333

0 commit comments

Comments
 (0)