From 05f4fe62d69fa44d570dc93f0ca0b5ee0dface20 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 7 Apr 2020 19:20:53 +0200 Subject: [PATCH 1/4] Node 12 compatibility Change-type: patch --- package.json | 2 +- src/async.cc | 8 +++++--- src/disk.cc | 23 ++++++++++++++--------- src/node_lkl.cc | 11 +++++++---- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 000d1f3..c8595c6 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,6 @@ "async": "^2.1.5", "bindings": "^1.2.1", "bluebird": "^3.5.3", - "nan": "^2.5.1" + "nan": "^2.14.0" } } diff --git a/src/async.cc b/src/async.cc index bbbab40..44f52c0 100644 --- a/src/async.cc +++ b/src/async.cc @@ -50,9 +50,10 @@ static NAN_METHOD(callback_wrapper) { if ((async == NULL) || (uv_is_closing((uv_handle_t*)async) != 0)) { return; } - auto data = info.Data()->ToObject(); + auto context = info.GetIsolate()->GetCurrentContext(); + auto data = info.Data()->ToObject(context).ToLocalChecked(); - void (*fn)(NAN_METHOD_ARGS_TYPE, void *) = data->Get(0).As()->Value(); + void (*fn)(NAN_METHOD_ARGS_TYPE, void *) = Get(data, (uint32_t)0).ToLocalChecked().As()->Value(); auto args = data->Get(1).As()->Value(); if (fn && args) { @@ -65,9 +66,10 @@ static NAN_METHOD(callback_wrapper) { } v8::Local make_callback(void (*fn)(NAN_METHOD_ARGS_TYPE, void *), void *args) { + auto context = GetCurrentContext(); auto data = New(); data->Set(0, New(fn)); data->Set(1, New(args)); - return New(callback_wrapper, data)->GetFunction(); + return New(callback_wrapper, data)->GetFunction(context).ToLocalChecked(); } diff --git a/src/disk.cc b/src/disk.cc index 281838a..3a4716d 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -56,11 +56,12 @@ struct request_state_t { }; static void get_capacity_done(NAN_METHOD_ARGS_TYPE info, get_capacity_state_t* s) { + auto context = info.GetIsolate()->GetCurrentContext(); if (info[0]->IsNull()) { s->ret = 0; - *(s->res) = info[1]->IntegerValue(); + *(s->res) = info[1]->IntegerValue(context).ToChecked(); } else { - s->ret = info[0]->IntegerValue(); + s->ret = info[0]->IntegerValue(context).ToChecked(); *(s->res) = 0; } @@ -83,7 +84,8 @@ static void request_done(NAN_METHOD_ARGS_TYPE info, request_state_t* s) { if (info[0]->IsNull()) { s->ret = 0; } else { - s->ret = info[0]->IntegerValue(); + auto context = info.GetIsolate()->GetCurrentContext(); + s->ret = info[0]->IntegerValue(context).ToChecked(); } // Unblocks the original lkl thread @@ -228,7 +230,8 @@ void do_disk_remove(disk_remove_args_t *args) { NAN_METHOD(disk_remove) { CHECK_ARGS(2); - unsigned int disk_id = info[0]->Uint32Value(); + auto context = info.GetIsolate()->GetCurrentContext(); + unsigned int disk_id = info[0]->Uint32Value(context).ToChecked(); Callback *callback = new Callback(info[1].As()); disk_remove_args_t *args = new disk_remove_args_t; args->disk_id = disk_id; @@ -283,15 +286,16 @@ void do_mount(mount_args_t* args) { NAN_METHOD(mount) { CHECK_ARGS(5); - unsigned int disk_id = info[0]->Uint32Value(); - bool readonly = info[1]->BooleanValue(); + auto context = info.GetIsolate()->GetCurrentContext(); + unsigned int disk_id = info[0]->Uint32Value(context).ToChecked(); + bool readonly = info[1]->BooleanValue(context).ToChecked(); char *fs_type = new char[10]; Utf8String fs_type_(info[2]); strncpy(fs_type, *fs_type_, sizeof(fs_type) - 1); fs_type[sizeof(fs_type) - 1] = '\0'; - unsigned int part = info[3]->Uint32Value(); + unsigned int part = info[3]->Uint32Value(context).ToChecked(); Callback *callback = new Callback(info[4].As()); @@ -338,8 +342,9 @@ void do_umount(umount_args_t* args) { NAN_METHOD(umount) { CHECK_ARGS(3); - unsigned int disk_id = info[0]->Uint32Value(); - unsigned int partition = info[1]->Uint32Value(); + auto context = info.GetIsolate()->GetCurrentContext(); + unsigned int disk_id = info[0]->Uint32Value(context).ToChecked(); + unsigned int partition = info[1]->Uint32Value(context).ToChecked(); Callback *callback = new Callback(info[2].As()); umount_args_t* args = new umount_args_t; args->disk_id = disk_id; diff --git a/src/node_lkl.cc b/src/node_lkl.cc index ae72a64..8c43bd6 100644 --- a/src/node_lkl.cc +++ b/src/node_lkl.cc @@ -15,7 +15,8 @@ NAN_METHOD(startKernel) { } lkl_host_ops.print = NULL; - int memory = info[0]->Uint32Value(); + auto context = info.GetIsolate()->GetCurrentContext(); + int memory = info[0]->Uint32Value(context).ToChecked(); init_async(); init_worker(); lkl_start_kernel(&lkl_host_ops, memory, ""); @@ -69,7 +70,8 @@ void do_syscall(syscall_args_t* args) { } void syscall_entry(NAN_METHOD_ARGS_TYPE info) { - long no = info[0]->IntegerValue(); + auto context = info.GetIsolate()->GetCurrentContext(); + long no = info[0]->IntegerValue(context).ToChecked(); long *params = new long[6]; std::vector *paths = new std::vector(); @@ -84,7 +86,7 @@ void syscall_entry(NAN_METHOD_ARGS_TYPE info) { params[i] = p; paths->push_back(p); } else { - params[i] = info[i + 1]->IntegerValue(); + params[i] = info[i + 1]->IntegerValue(context).ToChecked(); } } Callback *callback = new Callback(info[7].As()); @@ -198,8 +200,9 @@ NAN_METHOD(parseLklStat) { } NAN_METHOD(millisecondsToTimespec) { + auto context = info.GetIsolate()->GetCurrentContext(); auto *ts = new struct timespec; - auto milliseconds = info[0]->IntegerValue(); + auto milliseconds = info[0]->IntegerValue(context).ToChecked(); ts->tv_sec = milliseconds / 1000; ts->tv_nsec = (milliseconds % 1000) * 1000000; auto result = Nan::NewBuffer( From 9265fd6b4b7aa5b8bb97cd15c8e7870e22d696ec Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 7 Apr 2020 19:58:52 +0200 Subject: [PATCH 2/4] Add node-gyp as a dev dependency Change-type: patch --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c8595c6..4970c73 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "devDependencies": { "eslint": "^3.19.0", "file-disk": "^5.0.0", - "mocha": "^2.2.5" + "mocha": "^2.2.5", + "node-gyp": "^6.1.0" }, "dependencies": { "async": "^2.1.5", From 312a64ea4469179ff08b71155aaf9666c7fca20a Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 7 Apr 2020 19:59:21 +0200 Subject: [PATCH 3/4] Update bindings to ^1.5.0 Change-type: patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4970c73..82657dd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "dependencies": { "async": "^2.1.5", - "bindings": "^1.2.1", + "bindings": "^1.5.0", "bluebird": "^3.5.3", "nan": "^2.14.0" } From cbfd6ba5a58ead2bf9bcbf7dc9f561e5a9189b19 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 7 Apr 2020 20:02:14 +0200 Subject: [PATCH 4/4] Fix indentation Change-type: patch --- src/async.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async.cc b/src/async.cc index 44f52c0..db69145 100644 --- a/src/async.cc +++ b/src/async.cc @@ -67,7 +67,7 @@ static NAN_METHOD(callback_wrapper) { v8::Local make_callback(void (*fn)(NAN_METHOD_ARGS_TYPE, void *), void *args) { auto context = GetCurrentContext(); - auto data = New(); + auto data = New(); data->Set(0, New(fn)); data->Set(1, New(args));