From 71a41644dde28c2a3202207aaadb9f406ea5e3d1 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 May 2018 09:44:50 +0200 Subject: [PATCH 1/6] use bindings --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0d65f21..10642e4 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "darwin" ], "dependencies": { + "bindings": "~1.3.0", "nan": "^2.4.0" } } From 4eb0ca09cfddbc0ffff5a26a8cb0e36af1dc76f4 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 May 2018 09:45:31 +0200 Subject: [PATCH 2/6] use bindings --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e331a80..9a3c0c5 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ var events = require('events'); -var binding = require('./build/Release/binding.node'); +var binding = require('bindings')('xpc-connection.node'); var XpcConnection = binding.XpcConnection; inherits(XpcConnection, events.EventEmitter); From f8210d7aab65c6c5387178b1ba70034c1931479e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 May 2018 09:45:54 +0200 Subject: [PATCH 3/6] rename target --- binding.gyp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binding.gyp b/binding.gyp index 921c42c..35bd721 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,7 +1,7 @@ { 'targets': [ { - 'target_name': 'binding', + 'target_name': 'xpc-connection', 'conditions': [ ['OS=="mac"', { 'sources': [ @@ -25,4 +25,4 @@ ] } ] -} \ No newline at end of file +} From 1897b5bb7aae8e980ec66c413a5b1687dd298fc5 Mon Sep 17 00:00:00 2001 From: ty Date: Tue, 12 Jun 2018 19:28:23 +0800 Subject: [PATCH 4/6] Fix GetRealNamedProperty build error in cpp --- src/XpcConnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XpcConnection.cpp b/src/XpcConnection.cpp index 480e1a6..2a48ca0 100644 --- a/src/XpcConnection.cpp +++ b/src/XpcConnection.cpp @@ -140,7 +140,7 @@ xpc_object_t XpcConnection::ObjectToXpcObject(Local object) { if (propertyName->IsString()) { Nan::Utf8String propertyNameString(propertyName); - Local propertyValue = object->GetRealNamedProperty(propertyName->ToString()); + Local propertyValue = Nan::GetRealNamedProperty(object, propertyName->ToString()).ToLocalChecked(); xpc_object_t xpcValue = XpcConnection::ValueToXpcObject(propertyValue); xpc_dictionary_set_value(xpcObject, *propertyNameString, xpcValue); From 8ff8b20e1146a1cb13cc57f9802593995014f31e Mon Sep 17 00:00:00 2001 From: ty Date: Tue, 12 Jun 2018 22:13:50 +0800 Subject: [PATCH 5/6] Replace `node::MakeCallback` with AsyncResource call --- .gitignore | 1 + src/XpcConnection.cpp | 9 +++++---- src/XpcConnection.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8d251dd..afa07c1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ npm-debug.log build/ node_modules/ +.idea \ No newline at end of file diff --git a/src/XpcConnection.cpp b/src/XpcConnection.cpp index 2a48ca0..8dd4183 100644 --- a/src/XpcConnection.cpp +++ b/src/XpcConnection.cpp @@ -28,7 +28,8 @@ NAN_MODULE_INIT(XpcConnection::Init) { XpcConnection::XpcConnection(std::string serviceName) : node::ObjectWrap(), - serviceName(serviceName) { + serviceName(serviceName), + asyncResource("XpcConnection") { this->asyncHandle = new uv_async_t; @@ -250,8 +251,8 @@ void XpcConnection::processEventQueue() { Nan::New("error").ToLocalChecked(), Nan::New(message).ToLocalChecked() }; - - Nan::MakeCallback(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); + + this->asyncResource.runInAsyncScope(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); } else if (eventType == XPC_TYPE_DICTIONARY) { Local eventObject = XpcConnection::XpcDictionaryToObject(event); @@ -260,7 +261,7 @@ void XpcConnection::processEventQueue() { eventObject }; - Nan::MakeCallback(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); + this->asyncResource.runInAsyncScope(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); } xpc_release(event); diff --git a/src/XpcConnection.h b/src/XpcConnection.h index 114ed58..ab98277 100644 --- a/src/XpcConnection.h +++ b/src/XpcConnection.h @@ -45,6 +45,7 @@ class XpcConnection : public node::ObjectWrap { xpc_connection_t xpcConnnection; Nan::Persistent This; + Nan::AsyncResource asyncResource; uv_async_t* asyncHandle; uv_mutex_t eventQueueMutex; From a5f8d2c7d0180176184d03566f09461f09abcf25 Mon Sep 17 00:00:00 2001 From: ty Date: Mon, 17 Feb 2020 19:50:58 +0800 Subject: [PATCH 6/6] Update Nan api to work with node v12 and v13 --- src/XpcConnection.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/XpcConnection.cpp b/src/XpcConnection.cpp index 8dd4183..1e9ad15 100644 --- a/src/XpcConnection.cpp +++ b/src/XpcConnection.cpp @@ -23,7 +23,7 @@ NAN_MODULE_INIT(XpcConnection::Init) { Nan::SetPrototypeMethod(tmpl, "setup", Setup); Nan::SetPrototypeMethod(tmpl, "sendMessage", SendMessage); - target->Set(Nan::New("XpcConnection").ToLocalChecked(), tmpl->GetFunction()); + Nan::Set(target, Nan::New("XpcConnection").ToLocalChecked(), Nan::GetFunction(tmpl).ToLocalChecked()); } XpcConnection::XpcConnection(std::string serviceName) : @@ -101,7 +101,7 @@ xpc_object_t XpcConnection::ValueToXpcObject(Local value) { xpc_object_t xpcObject = NULL; if (value->IsInt32() || value->IsUint32()) { - xpcObject = xpc_int64_create(value->IntegerValue()); + xpcObject = xpc_int64_create(Nan::To(value).FromJust()); } else if (value->IsString()) { Nan::Utf8String valueString(value); @@ -111,9 +111,10 @@ xpc_object_t XpcConnection::ValueToXpcObject(Local value) { xpcObject = XpcConnection::ArrayToXpcObject(valueArray); } else if (node::Buffer::HasInstance(value)) { - Local valueObject = value->ToObject(); + Local valueObject = Nan::To(value).ToLocalChecked(); - if (valueObject->HasRealNamedProperty(Nan::New("isUuid").ToLocalChecked())) { + + if (Nan::HasRealNamedProperty(valueObject, Nan::New("isUuid").ToLocalChecked()).FromJust()) { uuid_t *uuid = (uuid_t *)node::Buffer::Data(valueObject); xpcObject = xpc_uuid_create(*uuid); @@ -121,7 +122,7 @@ xpc_object_t XpcConnection::ValueToXpcObject(Local value) { xpcObject = xpc_data_create(node::Buffer::Data(valueObject), node::Buffer::Length(valueObject)); } } else if (value->IsObject()) { - Local valueObject = value->ToObject(); + Local valueObject = Nan::To(value).ToLocalChecked(); xpcObject = XpcConnection::ObjectToXpcObject(valueObject); } else { @@ -133,15 +134,15 @@ xpc_object_t XpcConnection::ValueToXpcObject(Local value) { xpc_object_t XpcConnection::ObjectToXpcObject(Local object) { xpc_object_t xpcObject = xpc_dictionary_create(NULL, NULL, 0); - Local propertyNames = object->GetPropertyNames(); + Local propertyNames = Nan::GetPropertyNames(object).ToLocalChecked(); for(uint32_t i = 0; i < propertyNames->Length(); i++) { - Local propertyName = propertyNames->Get(i); + Local propertyName = Nan::Get(propertyNames, i).ToLocalChecked(); if (propertyName->IsString()) { Nan::Utf8String propertyNameString(propertyName); - Local propertyValue = Nan::GetRealNamedProperty(object, propertyName->ToString()).ToLocalChecked(); + Local propertyValue = Nan::GetRealNamedProperty(object, Nan::To(propertyName).ToLocalChecked()).ToLocalChecked(); xpc_object_t xpcValue = XpcConnection::ValueToXpcObject(propertyValue); xpc_dictionary_set_value(xpcObject, *propertyNameString, xpcValue); @@ -158,7 +159,7 @@ xpc_object_t XpcConnection::ArrayToXpcObject(Local array) { xpc_object_t xpcArray = xpc_array_create(NULL, 0); for(uint32_t i = 0; i < array->Length(); i++) { - Local value = array->Get(i); + Local value = Nan::Get(array, i).ToLocalChecked(); xpc_object_t xpcValue = XpcConnection::ValueToXpcObject(value); xpc_array_append_value(xpcArray, xpcValue); @@ -198,7 +199,7 @@ Local XpcConnection::XpcDictionaryToObject(xpc_object_t xpcDictionary) { Local object = Nan::New(); xpc_dictionary_apply(xpcDictionary, ^bool(const char *key, xpc_object_t value) { - object->Set(Nan::New(key).ToLocalChecked(), XpcConnection::XpcObjectToValue(value)); + Nan::Set(object, Nan::New(key).ToLocalChecked(), XpcConnection::XpcObjectToValue(value)); return true; }); @@ -210,7 +211,7 @@ Local XpcConnection::XpcArrayToArray(xpc_object_t xpcArray) { Local array = Nan::New(); xpc_array_apply(xpcArray, ^bool(size_t index, xpc_object_t value) { - array->Set(Nan::New(index), XpcConnection::XpcObjectToValue(value)); + Nan::Set(array, Nan::New(index), XpcConnection::XpcObjectToValue(value)); return true; }); @@ -251,7 +252,7 @@ void XpcConnection::processEventQueue() { Nan::New("error").ToLocalChecked(), Nan::New(message).ToLocalChecked() }; - + this->asyncResource.runInAsyncScope(Nan::New(this->This), Nan::New("emit").ToLocalChecked(), 2, argv); } else if (eventType == XPC_TYPE_DICTIONARY) { Local eventObject = XpcConnection::XpcDictionaryToObject(event);