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

Commit

Permalink
Merge pull request #128 from meteor/update-for-node-12
Browse files Browse the repository at this point in the history
Fix all compilation errors and warnings for Node.js 12 (V8 7.4).
  • Loading branch information
rafeca authored Jun 12, 2019
2 parents e9d54f5 + b83a343 commit a53cf69
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
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
18 changes: 11 additions & 7 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<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");

Local<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 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
8 changes: 6 additions & 2 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 @@ -135,5 +136,8 @@ void HandleMap::Initialize(Local<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();
}
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

0 comments on commit a53cf69

Please sign in to comment.