From 4937e76ba042d9cb7ca4781699d0ac3ffe5f8186 Mon Sep 17 00:00:00 2001 From: AbnerLee Date: Fri, 26 Apr 2019 01:08:50 +0800 Subject: [PATCH 1/4] replace Handle with Local --- src/common.cc | 8 ++++---- src/handle_map.cc | 2 +- src/handle_map.h | 2 +- src/main.cc | 2 +- src/unsafe_persistent.h | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common.cc b/src/common.cc index 563c943..4a5c570 100644 --- a/src/common.cc +++ b/src/common.cc @@ -24,7 +24,7 @@ static void MakeCallbackInMainThread(uv_async_t* handle, int status) { Nan::HandleScope scope; if (!g_callback.IsEmpty()) { - Handle type; + Local type; switch (g_type) { case EVENT_CHANGE: type = Nan::New("change").ToLocalChecked(); @@ -52,7 +52,7 @@ static void MakeCallbackInMainThread(uv_async_t* handle, int status) { return; } - Handle argv[] = { + Local argv[] = { type, WatcherHandleToV8Value(g_handle), Nan::New(g_new_path.data(), g_new_path.size()).ToLocalChecked(), @@ -121,7 +121,7 @@ NAN_METHOD(Watch) { if (!info[0]->IsString()) return Nan::ThrowTypeError("String required"); - Handle path = info[0]->ToString(); + Local path = info[0]->ToString(); WatcherHandle handle = PlatformWatch(*String::Utf8Value(path)); if (!PlatformIsHandleValid(handle)) { int error_number = PlatformInvalidHandleToErrorNumber(handle); @@ -154,7 +154,7 @@ NAN_METHOD(Unwatch) { Nan::HandleScope scope; if (!IsV8ValueWatcherHandle(info[0])) - return Nan::ThrowTypeError("Handle type required"); + return Nan::ThrowTypeError("Local type required"); PlatformUnwatch(V8ValueToWatcherHandle(info[0])); diff --git a/src/handle_map.cc b/src/handle_map.cc index 24a14f0..af6f7da 100644 --- a/src/handle_map.cc +++ b/src/handle_map.cc @@ -121,7 +121,7 @@ NAN_METHOD(HandleMap::Clear) { } // static -void HandleMap::Initialize(Handle target) { +void HandleMap::Initialize(Local target) { Nan::HandleScope scope; Local t = Nan::New(HandleMap::New); diff --git a/src/handle_map.h b/src/handle_map.h index 79f1ad6..a9638b0 100644 --- a/src/handle_map.h +++ b/src/handle_map.h @@ -8,7 +8,7 @@ class HandleMap : public Nan::ObjectWrap { public: - static void Initialize(Handle target); + static void Initialize(Local target); private: typedef std::map > Map; diff --git a/src/main.cc b/src/main.cc index e9d8b7d..898f45f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,7 +3,7 @@ namespace { -void Init(Handle exports) { +void Init(Local exports) { CommonInit(); PlatformInit(); diff --git a/src/unsafe_persistent.h b/src/unsafe_persistent.h index a9ae1c8..6b2fb8a 100644 --- a/src/unsafe_persistent.h +++ b/src/unsafe_persistent.h @@ -27,7 +27,7 @@ class NanUnsafePersistent : public NanUnsafePersistentTraits::HandleType { template NAN_INLINE void NanAssignUnsafePersistent( NanUnsafePersistent& handle - , v8::Handle obj) { + , v8::Local obj) { handle.Reset(); handle = NanUnsafePersistent(v8::Isolate::GetCurrent(), obj); } @@ -43,7 +43,7 @@ NAN_INLINE v8::Local NanUnsafePersistentToLocal(const NanUnsafePersistent template NAN_INLINE void NanAssignUnsafePersistent( v8::Persistent& handle - , v8::Handle obj) { + , v8::Local obj) { handle.Dispose(); handle = v8::Persistent::New(obj); } From 3623544bddb4cd290d890a0e625164fc557fc461 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 6 May 2019 11:57:42 -0400 Subject: [PATCH 2/4] Fix all compilation errors and warnings for Node.js 12 (V8 7.4). Depends on s/Handle/Local/ work started by @abnerlee in https://github.com/atom/node-pathwatcher/pull/127. --- src/common.cc | 18 +++++++++++------- src/common.h | 2 +- src/handle_map.cc | 8 ++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/common.cc b/src/common.cc index 4a5c570..b37c70c 100644 --- a/src/common.cc +++ b/src/common.cc @@ -58,7 +58,8 @@ static void MakeCallbackInMainThread(uv_async_t* handle, int status) { Nan::New(g_new_path.data(), g_new_path.size()).ToLocalChecked(), Nan::New(g_old_path.data(), g_old_path.size()).ToLocalChecked(), }; - Nan::New(g_callback)->Call(Nan::GetCurrentContext()->Global(), 4, argv); + Local context = Nan::GetCurrentContext(); + Nan::New(g_callback)->Call(context, context->Global(), 4, argv).ToLocalChecked(); } WakeupNewThread(); @@ -121,24 +122,27 @@ NAN_METHOD(Watch) { if (!info[0]->IsString()) return Nan::ThrowTypeError("String required"); - Local path = info[0]->ToString(); - WatcherHandle handle = PlatformWatch(*String::Utf8Value(path)); + Local context = Nan::GetCurrentContext(); + Local path = info[0]->ToString(context).ToLocalChecked(); + WatcherHandle handle = PlatformWatch(*String::Utf8Value(v8::Isolate::GetCurrent(), path)); if (!PlatformIsHandleValid(handle)) { int error_number = PlatformInvalidHandleToErrorNumber(handle); v8::Local err = v8::Exception::Error(Nan::New("Unable to watch path").ToLocalChecked()); v8::Local err_obj = err.As(); if (error_number != 0) { - err_obj->Set(Nan::New("errno").ToLocalChecked(), - Nan::New(error_number)); + err_obj->Set(context, + Nan::New("errno").ToLocalChecked(), + Nan::New(error_number)).FromJust(); #if NODE_VERSION_AT_LEAST(0, 11, 5) // Node 0.11.5 is the first version to contain libuv v0.11.6, which // contains https://github.com/libuv/libuv/commit/3ee4d3f183 which changes // uv_err_name from taking a struct uv_err_t (whose uv_err_code `code` is // a difficult-to-produce uv-specific errno) to just take an int which is // a negative errno. - err_obj->Set(Nan::New("code").ToLocalChecked(), - Nan::New(uv_err_name(-error_number)).ToLocalChecked()); + err_obj->Set(context, + Nan::New("code").ToLocalChecked(), + Nan::New(uv_err_name(-error_number)).ToLocalChecked()).FromJust(); #endif } return Nan::ThrowError(err); diff --git a/src/common.h b/src/common.h index a667800..8f0d85f 100644 --- a/src/common.h +++ b/src/common.h @@ -18,7 +18,7 @@ bool IsV8ValueWatcherHandle(Local value); // Correspoding definetions on OS X and Linux. typedef int32_t WatcherHandle; #define WatcherHandleToV8Value(h) Nan::New(h) -#define V8ValueToWatcherHandle(v) v->Int32Value() +#define V8ValueToWatcherHandle(v) v->Int32Value(Nan::GetCurrentContext()).FromJust() #define IsV8ValueWatcherHandle(v) v->IsInt32() #endif diff --git a/src/handle_map.cc b/src/handle_map.cc index af6f7da..c55a85f 100644 --- a/src/handle_map.cc +++ b/src/handle_map.cc @@ -86,11 +86,12 @@ NAN_METHOD(HandleMap::Values) { HandleMap* obj = Nan::ObjectWrap::Unwrap(info.This()); int i = 0; + v8::Local context = Nan::GetCurrentContext(); v8::Local keys = Nan::New(obj->map_.size()); for (Map::const_iterator iter = obj->map_.begin(); iter != obj->map_.end(); ++iter, ++i) { - keys->Set(i, NanUnsafePersistentToLocal(iter->second)); + keys->Set(context, i, NanUnsafePersistentToLocal(iter->second)).FromJust(); } info.GetReturnValue().Set(keys); @@ -135,5 +136,8 @@ void HandleMap::Initialize(Local target) { Nan::SetPrototypeMethod(t, "remove", Remove); Nan::SetPrototypeMethod(t, "clear", Clear); - target->Set(Nan::New("HandleMap").ToLocalChecked(), t->GetFunction()); + Local context = Nan::GetCurrentContext(); + target->Set(context, + Nan::New("HandleMap").ToLocalChecked(), + t->GetFunction(context).ToLocalChecked()).FromJust(); } From 9c889dfef62a5738ac1e94634c32887922fa1cfa Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 8 May 2019 20:11:23 +0000 Subject: [PATCH 3/4] Fix Windows build errors for Node.js 12, too. --- src/pathwatcher_win.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pathwatcher_win.cc b/src/pathwatcher_win.cc index 2e210bf..1a99bd4 100644 --- a/src/pathwatcher_win.cc +++ b/src/pathwatcher_win.cc @@ -99,18 +99,20 @@ static bool QueueReaddirchanges(HandleWrapper* handle) { } Local WatcherHandleToV8Value(WatcherHandle handle) { - Local value = Nan::New(g_object_template)->NewInstance(); - Nan::SetInternalFieldPointer(value->ToObject(), 0, handle); + Local context = Nan::GetCurrentContext(); + Local value = Nan::New(g_object_template)->NewInstance(context).ToLocalChecked(); + Nan::SetInternalFieldPointer(value->ToObject(context).ToLocalChecked(), 0, handle); return value; } WatcherHandle V8ValueToWatcherHandle(Local value) { return reinterpret_cast(Nan::GetInternalFieldPointer( - value->ToObject(), 0)); + value->ToObject(Nan::GetCurrentContext()).ToLocalChecked(), 0)); } bool IsV8ValueWatcherHandle(Local value) { - return value->IsObject() && value->ToObject()->InternalFieldCount() == 1; + return value->IsObject() && + value->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->InternalFieldCount() == 1; } void PlatformInit() { From b83a3432327f6e0d628884314cea87878b4cdf91 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 8 May 2019 16:04:06 -0400 Subject: [PATCH 4/4] Avoid removing vital build/ directory in prepublish script. I'm sure this isn't the best way to fix this problem, but without it the pathwatcher package gets installed without a build/Release directory, which makes the package totally unusable. The unnecessary cleaning happens because the prepublish script always runs after npm install. Very open to any other ways of preserving the build/ directory! --- Gruntfile.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 1177aa8..ed9c3a1 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -69,7 +69,7 @@ module.exports = (grunt) -> grunt.registerTask('lint', ['coffeelint', 'cpplint']) grunt.registerTask('default', ['coffee', 'lint', 'shell:rebuild']) grunt.registerTask('test', ['default', 'shell:test']) - grunt.registerTask('prepublish', ['clean', 'coffee', 'lint', 'shell:update-atomdoc', 'atomdoc']) + grunt.registerTask('prepublish', ['coffee', 'lint', 'shell:update-atomdoc', 'atomdoc']) grunt.registerTask 'clean', -> rm = require('rimraf').sync rm 'build'