Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Fix all compilation errors and warnings for Node.js 12 (V8 7.4). #128

Merged
merged 4 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 14 additions & 10 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void MakeCallbackInMainThread(uv_async_t* handle, int status) {
Nan::HandleScope scope;

if (!g_callback.IsEmpty()) {
Handle<String> type;
Local<String> type;
switch (g_type) {
case EVENT_CHANGE:
type = Nan::New("change").ToLocalChecked();
Expand Down Expand Up @@ -52,13 +52,14 @@ static void MakeCallbackInMainThread(uv_async_t* handle, int status) {
return;
}

Handle<Value> argv[] = {
Local<Value> 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<v8::Context> context = Nan::GetCurrentContext();
Nan::New(g_callback)->Call(context, context->Global(), 4, argv).ToLocalChecked();
}

WakeupNewThread();
Expand Down Expand Up @@ -121,24 +122,27 @@ NAN_METHOD(Watch) {
if (!info[0]->IsString())
return Nan::ThrowTypeError("String required");

Handle<String> path = info[0]->ToString();
WatcherHandle handle = PlatformWatch(*String::Utf8Value(path));
Local<v8::Context> context = Nan::GetCurrentContext();
Local<String> 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<v8::Value> err =
v8::Exception::Error(Nan::New<v8::String>("Unable to watch path").ToLocalChecked());
v8::Local<v8::Object> err_obj = err.As<v8::Object>();
if (error_number != 0) {
err_obj->Set(Nan::New<v8::String>("errno").ToLocalChecked(),
Nan::New<v8::Integer>(error_number));
err_obj->Set(context,
Nan::New<v8::String>("errno").ToLocalChecked(),
Nan::New<v8::Integer>(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<v8::String>("code").ToLocalChecked(),
Nan::New<v8::String>(uv_err_name(-error_number)).ToLocalChecked());
err_obj->Set(context,
Nan::New<v8::String>("code").ToLocalChecked(),
Nan::New<v8::String>(uv_err_name(-error_number)).ToLocalChecked()).FromJust();
#endif
}
return Nan::ThrowError(err);
Expand All @@ -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]));

Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool IsV8ValueWatcherHandle(Local<Value> value);
// Correspoding definetions on OS X and Linux.
typedef int32_t WatcherHandle;
#define WatcherHandleToV8Value(h) Nan::New<Integer>(h)
#define V8ValueToWatcherHandle(v) v->Int32Value()
#define V8ValueToWatcherHandle(v) v->Int32Value(Nan::GetCurrentContext()).FromJust()
#define IsV8ValueWatcherHandle(v) v->IsInt32()
#endif

Expand Down
10 changes: 7 additions & 3 deletions src/handle_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ NAN_METHOD(HandleMap::Values) {
HandleMap* obj = Nan::ObjectWrap::Unwrap<HandleMap>(info.This());

int i = 0;
v8::Local<v8::Context> context = Nan::GetCurrentContext();
v8::Local<Array> keys = Nan::New<Array>(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);
Expand Down Expand Up @@ -121,7 +122,7 @@ NAN_METHOD(HandleMap::Clear) {
}

// static
void HandleMap::Initialize(Handle<Object> target) {
void HandleMap::Initialize(Local<Object> target) {
Nan::HandleScope scope;

Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(HandleMap::New);
Expand All @@ -135,5 +136,8 @@ void HandleMap::Initialize(Handle<Object> target) {
Nan::SetPrototypeMethod(t, "remove", Remove);
Nan::SetPrototypeMethod(t, "clear", Clear);

target->Set(Nan::New<String>("HandleMap").ToLocalChecked(), t->GetFunction());
Local<v8::Context> context = Nan::GetCurrentContext();
target->Set(context,
Nan::New<String>("HandleMap").ToLocalChecked(),
t->GetFunction(context).ToLocalChecked()).FromJust();
}
2 changes: 1 addition & 1 deletion src/handle_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class HandleMap : public Nan::ObjectWrap {
public:
static void Initialize(Handle<Object> target);
static void Initialize(Local<Object> target);

private:
typedef std::map<WatcherHandle, NanUnsafePersistent<Value> > Map;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace {

void Init(Handle<Object> exports) {
void Init(Local<Object> exports) {
CommonInit();
PlatformInit();

Expand Down
10 changes: 6 additions & 4 deletions src/pathwatcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,20 @@ static bool QueueReaddirchanges(HandleWrapper* handle) {
}

Local<Value> WatcherHandleToV8Value(WatcherHandle handle) {
Local<Value> value = Nan::New(g_object_template)->NewInstance();
Nan::SetInternalFieldPointer(value->ToObject(), 0, handle);
Local<v8::Context> context = Nan::GetCurrentContext();
Local<Value> value = Nan::New(g_object_template)->NewInstance(context).ToLocalChecked();
Nan::SetInternalFieldPointer(value->ToObject(context).ToLocalChecked(), 0, handle);
return value;
}

WatcherHandle V8ValueToWatcherHandle(Local<Value> value) {
return reinterpret_cast<WatcherHandle>(Nan::GetInternalFieldPointer(
value->ToObject(), 0));
value->ToObject(Nan::GetCurrentContext()).ToLocalChecked(), 0));
}

bool IsV8ValueWatcherHandle(Local<Value> value) {
return value->IsObject() && value->ToObject()->InternalFieldCount() == 1;
return value->IsObject() &&
value->ToObject(Nan::GetCurrentContext()).ToLocalChecked()->InternalFieldCount() == 1;
}

void PlatformInit() {
Expand Down
4 changes: 2 additions & 2 deletions src/unsafe_persistent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NanUnsafePersistent : public NanUnsafePersistentTraits<T>::HandleType {
template<typename T>
NAN_INLINE void NanAssignUnsafePersistent(
NanUnsafePersistent<T>& handle
, v8::Handle<T> obj) {
, v8::Local<T> obj) {
handle.Reset();
handle = NanUnsafePersistent<T>(v8::Isolate::GetCurrent(), obj);
}
Expand All @@ -43,7 +43,7 @@ NAN_INLINE v8::Local<T> NanUnsafePersistentToLocal(const NanUnsafePersistent<T>
template<typename T>
NAN_INLINE void NanAssignUnsafePersistent(
v8::Persistent<T>& handle
, v8::Handle<T> obj) {
, v8::Local<T> obj) {
handle.Dispose();
handle = v8::Persistent<T>::New(obj);
}
Expand Down