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' diff --git a/src/common.cc b/src/common.cc index 563c943..b37c70c 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,13 +52,14 @@ 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(), 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"); - Handle 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); @@ -154,7 +158,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/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 24a14f0..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); @@ -121,7 +122,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); @@ -135,5 +136,8 @@ void HandleMap::Initialize(Handle 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(); } 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/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() { 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); }