diff --git a/1_hello_world/nan/hello.cc b/1_hello_world/nan/hello.cc index de1517b1..75c5ada0 100644 --- a/1_hello_world/nan/hello.cc +++ b/1_hello_world/nan/hello.cc @@ -7,7 +7,9 @@ void Method(const Nan::FunctionCallbackInfo& info) { void Init(v8::Local exports) { v8::Local context = exports->CreationContext(); exports->Set(Nan::New("hello").ToLocalChecked(), - Nan::New(Method)->GetFunction(context).ToLocalChecked()); + Nan::New(Method) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(hello, Init) diff --git a/1_hello_world/napi/hello.cc b/1_hello_world/napi/hello.cc index 5d57f027..767cf503 100644 --- a/1_hello_world/napi/hello.cc +++ b/1_hello_world/napi/hello.cc @@ -1,5 +1,5 @@ -#include #include +#include napi_value Method(napi_env env, napi_callback_info info) { napi_status status; @@ -9,7 +9,7 @@ napi_value Method(napi_env env, napi_callback_info info) { return world; } -#define DECLARE_NAPI_METHOD(name, func) \ +#define DECLARE_NAPI_METHOD(name, func) \ { name, 0, func, 0, 0, 0, napi_default, 0 } napi_value Init(napi_env env, napi_value exports) { diff --git a/2_function_arguments/nan/addon.cc b/2_function_arguments/nan/addon.cc index c23c29b4..1a743776 100644 --- a/2_function_arguments/nan/addon.cc +++ b/2_function_arguments/nan/addon.cc @@ -23,7 +23,9 @@ void Add(const Nan::FunctionCallbackInfo& info) { void Init(v8::Local exports) { v8::Local context = exports->CreationContext(); exports->Set(Nan::New("add").ToLocalChecked(), - Nan::New(Add)->GetFunction(context).ToLocalChecked()); + Nan::New(Add) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(addon, Init) diff --git a/2_function_arguments/napi/addon.cc b/2_function_arguments/napi/addon.cc index 5d674b88..f12209ae 100644 --- a/2_function_arguments/napi/addon.cc +++ b/2_function_arguments/napi/addon.cc @@ -1,5 +1,5 @@ -#include #include +#include #include napi_value Add(napi_env env, napi_callback_info info) { napi_status status; @@ -42,7 +42,7 @@ napi_value Add(napi_env env, napi_callback_info info) { return sum; } -#define DECLARE_NAPI_METHOD(name, func) \ +#define DECLARE_NAPI_METHOD(name, func) \ { name, 0, func, 0, 0, 0, napi_default, 0 } napi_value Init(napi_env env, napi_value exports) { diff --git a/2_function_arguments/node-addon-api/addon.cc b/2_function_arguments/node-addon-api/addon.cc index eea378dc..c902bfea 100644 --- a/2_function_arguments/node-addon-api/addon.cc +++ b/2_function_arguments/node-addon-api/addon.cc @@ -4,7 +4,8 @@ Napi::Value Add(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); if (info.Length() < 2) { - Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException(); + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); return env.Null(); } @@ -21,8 +22,7 @@ Napi::Value Add(const Napi::CallbackInfo& info) { } Napi::Object Init(Napi::Env env, Napi::Object exports) { - exports.Set(Napi::String::New(env, "add"), - Napi::Function::New(env, Add)); + exports.Set(Napi::String::New(env, "add"), Napi::Function::New(env, Add)); return exports; } diff --git a/3_callbacks/nan/addon.cc b/3_callbacks/nan/addon.cc index 53bd0649..0d925ad6 100644 --- a/3_callbacks/nan/addon.cc +++ b/3_callbacks/nan/addon.cc @@ -3,7 +3,7 @@ void RunCallback(const Nan::FunctionCallbackInfo& info) { v8::Local cb = info[0].As(); const unsigned argc = 1; - v8::Local argv[argc] = { Nan::New("hello world").ToLocalChecked() }; + v8::Local argv[argc] = {Nan::New("hello world").ToLocalChecked()}; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), cb, argc, argv); } diff --git a/3_callbacks/napi/addon.cc b/3_callbacks/napi/addon.cc index 16dadc6b..55b43930 100644 --- a/3_callbacks/napi/addon.cc +++ b/3_callbacks/napi/addon.cc @@ -1,5 +1,5 @@ -#include #include +#include napi_value RunCallback(napi_env env, const napi_callback_info info) { napi_status status; @@ -28,8 +28,8 @@ napi_value RunCallback(napi_env env, const napi_callback_info info) { napi_value Init(napi_env env, napi_value exports) { napi_value new_exports; - napi_status status = - napi_create_function(env, "", NAPI_AUTO_LENGTH, RunCallback, nullptr, &new_exports); + napi_status status = napi_create_function( + env, "", NAPI_AUTO_LENGTH, RunCallback, nullptr, &new_exports); assert(status == napi_ok); return new_exports; } diff --git a/3_callbacks/node-addon-api/addon.cc b/3_callbacks/node-addon-api/addon.cc index 4b03d09c..129be800 100644 --- a/3_callbacks/node-addon-api/addon.cc +++ b/3_callbacks/node-addon-api/addon.cc @@ -3,7 +3,7 @@ void RunCallback(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::Function cb = info[0].As(); - cb.Call(env.Global(), { Napi::String::New(env, "hello world") }); + cb.Call(env.Global(), {Napi::String::New(env, "hello world")}); } Napi::Object Init(Napi::Env env, Napi::Object exports) { diff --git a/4_object_factory/nan/addon.cc b/4_object_factory/nan/addon.cc index c7392c25..f2f8339b 100644 --- a/4_object_factory/nan/addon.cc +++ b/4_object_factory/nan/addon.cc @@ -3,7 +3,8 @@ void CreateObject(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); v8::Local obj = Nan::New(); - obj->Set(Nan::New("msg").ToLocalChecked(), info[0]->ToString(context).ToLocalChecked()); + obj->Set(Nan::New("msg").ToLocalChecked(), + info[0]->ToString(context).ToLocalChecked()); info.GetReturnValue().Set(obj); } @@ -11,7 +12,9 @@ void CreateObject(const Nan::FunctionCallbackInfo& info) { void Init(v8::Local exports, v8::Local module) { v8::Local context = exports->CreationContext(); module->Set(Nan::New("exports").ToLocalChecked(), - Nan::New(CreateObject)->GetFunction(context).ToLocalChecked()); + Nan::New(CreateObject) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(addon, Init) diff --git a/4_object_factory/napi/addon.cc b/4_object_factory/napi/addon.cc index d215cd36..2c8a9827 100644 --- a/4_object_factory/napi/addon.cc +++ b/4_object_factory/napi/addon.cc @@ -1,5 +1,5 @@ -#include #include +#include napi_value CreateObject(napi_env env, const napi_callback_info info) { napi_status status; @@ -21,8 +21,8 @@ napi_value CreateObject(napi_env env, const napi_callback_info info) { napi_value Init(napi_env env, napi_value exports) { napi_value new_exports; - napi_status status = - napi_create_function(env, "", NAPI_AUTO_LENGTH, CreateObject, nullptr, &new_exports); + napi_status status = napi_create_function( + env, "", NAPI_AUTO_LENGTH, CreateObject, nullptr, &new_exports); assert(status == napi_ok); return new_exports; } diff --git a/5_function_factory/nan/addon.cc b/5_function_factory/nan/addon.cc index 20cb1215..0dfc8767 100644 --- a/5_function_factory/nan/addon.cc +++ b/5_function_factory/nan/addon.cc @@ -6,7 +6,8 @@ void MyFunction(const Nan::FunctionCallbackInfo& info) { void CreateFunction(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); - v8::Local tpl = Nan::New(MyFunction); + v8::Local tpl = + Nan::New(MyFunction); v8::Local fn = tpl->GetFunction(context).ToLocalChecked(); // omit this to make it anonymous diff --git a/5_function_factory/napi/addon.cc b/5_function_factory/napi/addon.cc index 2c0bbfd8..584875b3 100644 --- a/5_function_factory/napi/addon.cc +++ b/5_function_factory/napi/addon.cc @@ -15,7 +15,8 @@ napi_value CreateFunction(napi_env env, napi_callback_info info) { napi_status status; napi_value fn; - status = napi_create_function(env, "theFunction", NAPI_AUTO_LENGTH, MyFunction, nullptr, &fn); + status = napi_create_function( + env, "theFunction", NAPI_AUTO_LENGTH, MyFunction, nullptr, &fn); assert(status == napi_ok); return fn; @@ -23,8 +24,8 @@ napi_value CreateFunction(napi_env env, napi_callback_info info) { napi_value Init(napi_env env, napi_value exports) { napi_value new_exports; - napi_status status = - napi_create_function(env, "", NAPI_AUTO_LENGTH, CreateFunction, nullptr, &new_exports); + napi_status status = napi_create_function( + env, "", NAPI_AUTO_LENGTH, CreateFunction, nullptr, &new_exports); assert(status == napi_ok); return new_exports; } diff --git a/6_object_wrap/nan/myobject.cc b/6_object_wrap/nan/myobject.cc index 66afbc22..593d9ba2 100644 --- a/6_object_wrap/nan/myobject.cc +++ b/6_object_wrap/nan/myobject.cc @@ -2,11 +2,9 @@ Nan::Persistent MyObject::constructor; -MyObject::MyObject(double value) : value_(value) { -} +MyObject::MyObject(double value) : value_(value) {} -MyObject::~MyObject() { -} +MyObject::~MyObject() {} void MyObject::Init(v8::Local exports) { v8::Local context = exports->CreationContext(); @@ -24,21 +22,22 @@ void MyObject::Init(v8::Local exports) { constructor.Reset(tpl->GetFunction(context).ToLocalChecked()); exports->Set(Nan::New("MyObject").ToLocalChecked(), - tpl->GetFunction(context).ToLocalChecked()); + tpl->GetFunction(context).ToLocalChecked()); } void MyObject::New(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); if (info.IsConstructCall()) { // Invoked as constructor: `new MyObject(...)` - double value = info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); + double value = + info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); MyObject* obj = new MyObject(value); obj->Wrap(info.This()); info.GetReturnValue().Set(info.This()); } else { // Invoked as plain function `MyObject(...)`, turn into construct call. const int argc = 1; - v8::Local argv[argc] = { info[0] }; + v8::Local argv[argc] = {info[0]}; v8::Local cons = Nan::New(constructor); info.GetReturnValue().Set( cons->NewInstance(context, argc, argv).ToLocalChecked()); @@ -59,12 +58,13 @@ void MyObject::PlusOne(const Nan::FunctionCallbackInfo& info) { void MyObject::Multiply(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); MyObject* obj = ObjectWrap::Unwrap(info.Holder()); - double multiple = info[0]->IsUndefined() ? 1 : info[0]->NumberValue(context).FromJust(); + double multiple = + info[0]->IsUndefined() ? 1 : info[0]->NumberValue(context).FromJust(); v8::Local cons = Nan::New(constructor); const int argc = 1; - v8::Local argv[argc] = { Nan::New(obj->value_ * multiple) }; + v8::Local argv[argc] = {Nan::New(obj->value_ * multiple)}; info.GetReturnValue().Set( cons->NewInstance(context, argc, argv).ToLocalChecked()); diff --git a/6_object_wrap/napi/myobject.cc b/6_object_wrap/napi/myobject.cc index ef843fb0..bfad7055 100644 --- a/6_object_wrap/napi/myobject.cc +++ b/6_object_wrap/napi/myobject.cc @@ -6,26 +6,30 @@ napi_ref MyObject::constructor; MyObject::MyObject(double value) : value_(value), env_(nullptr), wrapper_(nullptr) {} -MyObject::~MyObject() { napi_delete_reference(env_, wrapper_); } +MyObject::~MyObject() { + napi_delete_reference(env_, wrapper_); +} -void MyObject::Destructor(napi_env env, void* nativeObject, void* /*finalize_hint*/) { +void MyObject::Destructor(napi_env env, + void* nativeObject, + void* /*finalize_hint*/) { reinterpret_cast(nativeObject)->~MyObject(); } -#define DECLARE_NAPI_METHOD(name, func) \ +#define DECLARE_NAPI_METHOD(name, func) \ { name, 0, func, 0, 0, 0, napi_default, 0 } napi_value MyObject::Init(napi_env env, napi_value exports) { napi_status status; napi_property_descriptor properties[] = { - { "value", 0, 0, GetValue, SetValue, 0, napi_default, 0 }, + {"value", 0, 0, GetValue, SetValue, 0, napi_default, 0}, DECLARE_NAPI_METHOD("plusOne", PlusOne), DECLARE_NAPI_METHOD("multiply", Multiply), }; napi_value cons; - status = - napi_define_class(env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 3, properties, &cons); + status = napi_define_class( + env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 3, properties, &cons); assert(status == napi_ok); status = napi_create_reference(env, cons, 1, &constructor); @@ -124,7 +128,6 @@ napi_value MyObject::SetValue(napi_env env, napi_callback_info info) { status = napi_get_cb_info(env, info, &argc, &value, &jsthis, nullptr); assert(status == napi_ok); - MyObject* obj; status = napi_unwrap(env, jsthis, reinterpret_cast(&obj)); assert(status == napi_ok); diff --git a/6_object_wrap/node-addon-api/myobject.cc b/6_object_wrap/node-addon-api/myobject.cc index 6d0f3972..2885040e 100644 --- a/6_object_wrap/node-addon-api/myobject.cc +++ b/6_object_wrap/node-addon-api/myobject.cc @@ -5,11 +5,12 @@ Napi::FunctionReference MyObject::constructor; Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); - Napi::Function func = DefineClass(env, "MyObject", { - InstanceMethod("plusOne", &MyObject::PlusOne), - InstanceMethod("value", &MyObject::GetValue), - InstanceMethod("multiply", &MyObject::Multiply) - }); + Napi::Function func = + DefineClass(env, + "MyObject", + {InstanceMethod("plusOne", &MyObject::PlusOne), + InstanceMethod("value", &MyObject::GetValue), + InstanceMethod("multiply", &MyObject::Multiply)}); constructor = Napi::Persistent(func); constructor.SuppressDestruct(); @@ -18,7 +19,8 @@ Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { return exports; } -MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { +MyObject::MyObject(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); @@ -52,7 +54,8 @@ Napi::Value MyObject::Multiply(const Napi::CallbackInfo& info) { multiple = info[0].As(); } - Napi::Object obj = constructor.New({ Napi::Number::New(info.Env(), this->value_ * multiple.DoubleValue()) }); + Napi::Object obj = constructor.New( + {Napi::Number::New(info.Env(), this->value_ * multiple.DoubleValue())}); return obj; } diff --git a/6_object_wrap/node-addon-api/myobject.h b/6_object_wrap/node-addon-api/myobject.h index e143b97c..fbd30588 100644 --- a/6_object_wrap/node-addon-api/myobject.h +++ b/6_object_wrap/node-addon-api/myobject.h @@ -16,7 +16,6 @@ class MyObject : public Napi::ObjectWrap { Napi::Value Multiply(const Napi::CallbackInfo& info); double value_; - }; #endif diff --git a/7_factory_wrap/nan/addon.cc b/7_factory_wrap/nan/addon.cc index 3c3556c7..1a33fdb6 100644 --- a/7_factory_wrap/nan/addon.cc +++ b/7_factory_wrap/nan/addon.cc @@ -13,7 +13,9 @@ void InitAll(v8::Local exports, v8::Local module) { MyObject::Init(); module->Set(Nan::New("exports").ToLocalChecked(), - Nan::New(CreateObject)->GetFunction(context).ToLocalChecked()); + Nan::New(CreateObject) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(addon, InitAll) diff --git a/7_factory_wrap/nan/myobject.cc b/7_factory_wrap/nan/myobject.cc index 1317616b..baf342c3 100644 --- a/7_factory_wrap/nan/myobject.cc +++ b/7_factory_wrap/nan/myobject.cc @@ -1,10 +1,10 @@ -#include #include "myobject.h" +#include using namespace v8; -MyObject::MyObject() {}; -MyObject::~MyObject() {}; +MyObject::MyObject(){}; +MyObject::~MyObject(){}; Nan::Persistent MyObject::constructor; @@ -17,27 +17,28 @@ void MyObject::Init() { tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype tpl->PrototypeTemplate()->Set(Nan::New("plusOne").ToLocalChecked(), - Nan::New(PlusOne)); + Nan::New(PlusOne)); - constructor.Reset(tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); + constructor.Reset( + tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); } void MyObject::New(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); MyObject* obj = new MyObject(); - obj->counter_ = info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); + obj->counter_ = + info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); obj->Wrap(info.This()); info.GetReturnValue().Set(info.This()); } - v8::Local MyObject::NewInstance(v8::Local arg) { Nan::EscapableHandleScope scope; const unsigned argc = 1; - v8::Local argv[argc] = { arg }; + v8::Local argv[argc] = {arg}; v8::Local cons = Nan::New(constructor); v8::Local context = v8::Isolate::GetCurrent()->GetCurrentContext(); diff --git a/7_factory_wrap/napi/addon.cc b/7_factory_wrap/napi/addon.cc index 7db16ecc..80a78c7a 100644 --- a/7_factory_wrap/napi/addon.cc +++ b/7_factory_wrap/napi/addon.cc @@ -1,5 +1,5 @@ -#include "myobject.h" #include +#include "myobject.h" napi_value CreateObject(napi_env env, napi_callback_info info) { napi_status status; @@ -21,8 +21,8 @@ napi_value Init(napi_env env, napi_value exports) { assert(status == napi_ok); napi_value new_exports; - status = - napi_create_function(env, "", NAPI_AUTO_LENGTH, CreateObject, nullptr, &new_exports); + status = napi_create_function( + env, "", NAPI_AUTO_LENGTH, CreateObject, nullptr, &new_exports); assert(status == napi_ok); return new_exports; } diff --git a/7_factory_wrap/napi/myobject.cc b/7_factory_wrap/napi/myobject.cc index c11d1ccb..bd1a8fb7 100644 --- a/7_factory_wrap/napi/myobject.cc +++ b/7_factory_wrap/napi/myobject.cc @@ -3,13 +3,17 @@ MyObject::MyObject() : env_(nullptr), wrapper_(nullptr) {} -MyObject::~MyObject() { napi_delete_reference(env_, wrapper_); } +MyObject::~MyObject() { + napi_delete_reference(env_, wrapper_); +} -void MyObject::Destructor(napi_env env, void* nativeObject, void* /*finalize_hint*/) { +void MyObject::Destructor(napi_env env, + void* nativeObject, + void* /*finalize_hint*/) { reinterpret_cast(nativeObject)->~MyObject(); } -#define DECLARE_NAPI_METHOD(name, func) \ +#define DECLARE_NAPI_METHOD(name, func) \ { name, 0, func, 0, 0, 0, napi_default, 0 } napi_ref MyObject::constructor; @@ -21,8 +25,8 @@ napi_status MyObject::Init(napi_env env) { }; napi_value cons; - status = - napi_define_class(env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 1, properties, &cons); + status = napi_define_class( + env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 1, properties, &cons); if (status != napi_ok) return status; status = napi_create_reference(env, cons, 1, &constructor); diff --git a/7_factory_wrap/node-addon-api/addon.cc b/7_factory_wrap/node-addon-api/addon.cc index 9e5ae694..9f90488e 100644 --- a/7_factory_wrap/node-addon-api/addon.cc +++ b/7_factory_wrap/node-addon-api/addon.cc @@ -6,7 +6,8 @@ Napi::Object CreateObject(const Napi::CallbackInfo& info) { } Napi::Object InitAll(Napi::Env env, Napi::Object exports) { - Napi::Object new_exports = Napi::Function::New(env, CreateObject, "CreateObject"); + Napi::Object new_exports = + Napi::Function::New(env, CreateObject, "CreateObject"); return MyObject::Init(env, new_exports); } diff --git a/7_factory_wrap/node-addon-api/myobject.cc b/7_factory_wrap/node-addon-api/myobject.cc index f7944605..1f9c9e53 100644 --- a/7_factory_wrap/node-addon-api/myobject.cc +++ b/7_factory_wrap/node-addon-api/myobject.cc @@ -1,6 +1,6 @@ +#include "myobject.h" #include #include -#include "myobject.h" using namespace Napi; @@ -9,9 +9,8 @@ Napi::FunctionReference MyObject::constructor; Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); - Napi::Function func = DefineClass(env, "MyObject", { - InstanceMethod("plusOne", &MyObject::PlusOne) - }); + Napi::Function func = DefineClass( + env, "MyObject", {InstanceMethod("plusOne", &MyObject::PlusOne)}); constructor = Napi::Persistent(func); constructor.SuppressDestruct(); @@ -20,7 +19,8 @@ Napi::Object MyObject::Init(Napi::Env env, Napi::Object exports) { return exports; } -MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { +MyObject::MyObject(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); @@ -29,7 +29,7 @@ MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap( Napi::Object MyObject::NewInstance(Napi::Env env, Napi::Value arg) { Napi::EscapableHandleScope scope(env); - Napi::Object obj = constructor.New({ arg }); + Napi::Object obj = constructor.New({arg}); return scope.Escape(napi_value(obj)).ToObject(); } diff --git a/8_passing_wrapped/nan/addon.cc b/8_passing_wrapped/nan/addon.cc index e1b30f21..95b8bb96 100644 --- a/8_passing_wrapped/nan/addon.cc +++ b/8_passing_wrapped/nan/addon.cc @@ -10,8 +10,10 @@ void CreateObject(const Nan::FunctionCallbackInfo& info) { void Add(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); - MyObject* obj1 = Nan::ObjectWrap::Unwrap(info[0]->ToObject(context).ToLocalChecked()); - MyObject* obj2 = Nan::ObjectWrap::Unwrap(info[1]->ToObject(context).ToLocalChecked()); + MyObject* obj1 = Nan::ObjectWrap::Unwrap( + info[0]->ToObject(context).ToLocalChecked()); + MyObject* obj2 = Nan::ObjectWrap::Unwrap( + info[1]->ToObject(context).ToLocalChecked()); double sum = obj1->Val() + obj2->Val(); info.GetReturnValue().Set(Nan::New(sum)); } @@ -22,10 +24,14 @@ void InitAll(v8::Local exports) { MyObject::Init(); exports->Set(Nan::New("createObject").ToLocalChecked(), - Nan::New(CreateObject)->GetFunction(context).ToLocalChecked()); + Nan::New(CreateObject) + ->GetFunction(context) + .ToLocalChecked()); exports->Set(Nan::New("add").ToLocalChecked(), - Nan::New(Add)->GetFunction(context).ToLocalChecked()); + Nan::New(Add) + ->GetFunction(context) + .ToLocalChecked()); } NODE_MODULE(addon, InitAll) diff --git a/8_passing_wrapped/nan/myobject.cc b/8_passing_wrapped/nan/myobject.cc index bfbe9da4..244dd749 100644 --- a/8_passing_wrapped/nan/myobject.cc +++ b/8_passing_wrapped/nan/myobject.cc @@ -1,8 +1,8 @@ -#include #include "myobject.h" +#include -MyObject::MyObject() {}; -MyObject::~MyObject() {}; +MyObject::MyObject(){}; +MyObject::~MyObject(){}; Nan::Persistent MyObject::constructor; @@ -14,13 +14,15 @@ void MyObject::Init() { tpl->SetClassName(Nan::New("MyObject").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); - constructor.Reset(tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); + constructor.Reset( + tpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); } void MyObject::New(const Nan::FunctionCallbackInfo& info) { v8::Local context = info.GetIsolate()->GetCurrentContext(); MyObject* obj = new MyObject(); - obj->val_ = info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); + obj->val_ = + info[0]->IsUndefined() ? 0 : info[0]->NumberValue(context).FromJust(); obj->Wrap(info.This()); info.GetReturnValue().Set(info.This()); @@ -30,7 +32,7 @@ v8::Local MyObject::NewInstance(v8::Local arg) { Nan::EscapableHandleScope scope; const unsigned argc = 1; - v8::Local argv[argc] = { arg }; + v8::Local argv[argc] = {arg}; v8::Local cons = Nan::New(constructor); v8::Local context = v8::Isolate::GetCurrent()->GetCurrentContext(); diff --git a/8_passing_wrapped/napi/addon.cc b/8_passing_wrapped/napi/addon.cc index 63464d50..a49f5213 100644 --- a/8_passing_wrapped/napi/addon.cc +++ b/8_passing_wrapped/napi/addon.cc @@ -1,5 +1,5 @@ -#include "myobject.h" #include +#include "myobject.h" napi_value CreateObject(napi_env env, napi_callback_info info) { napi_status status; @@ -38,7 +38,7 @@ napi_value Add(napi_env env, napi_callback_info info) { return sum; } -#define DECLARE_NAPI_METHOD(name, func) \ +#define DECLARE_NAPI_METHOD(name, func) \ { name, 0, func, 0, 0, 0, napi_default, 0 } napi_value Init(napi_env env, napi_value exports) { diff --git a/8_passing_wrapped/napi/myobject.cc b/8_passing_wrapped/napi/myobject.cc index d2984925..ab75a25c 100644 --- a/8_passing_wrapped/napi/myobject.cc +++ b/8_passing_wrapped/napi/myobject.cc @@ -3,9 +3,13 @@ MyObject::MyObject() : env_(nullptr), wrapper_(nullptr) {} -MyObject::~MyObject() { napi_delete_reference(env_, wrapper_); } +MyObject::~MyObject() { + napi_delete_reference(env_, wrapper_); +} -void MyObject::Destructor(napi_env env, void* nativeObject, void* /*finalize_hint*/) { +void MyObject::Destructor(napi_env env, + void* nativeObject, + void* /*finalize_hint*/) { reinterpret_cast(nativeObject)->~MyObject(); } @@ -15,7 +19,8 @@ napi_status MyObject::Init(napi_env env) { napi_status status; napi_value cons; - status = napi_define_class(env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 0, nullptr, &cons); + status = napi_define_class( + env, "MyObject", NAPI_AUTO_LENGTH, New, nullptr, 0, nullptr, &cons); if (status != napi_ok) return status; status = napi_create_reference(env, cons, 1, &constructor); diff --git a/8_passing_wrapped/node-addon-api/addon.cc b/8_passing_wrapped/node-addon-api/addon.cc index d7426870..c348e79e 100644 --- a/8_passing_wrapped/node-addon-api/addon.cc +++ b/8_passing_wrapped/node-addon-api/addon.cc @@ -9,21 +9,21 @@ Napi::Object CreateObject(const Napi::CallbackInfo& info) { Napi::Number Add(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - MyObject* obj1 = Napi::ObjectWrap::Unwrap(info[0].As()); - MyObject* obj2 = Napi::ObjectWrap::Unwrap(info[1].As()); + MyObject* obj1 = + Napi::ObjectWrap::Unwrap(info[0].As()); + MyObject* obj2 = + Napi::ObjectWrap::Unwrap(info[1].As()); double sum = obj1->Val() + obj2->Val(); return Napi::Number::New(env, sum); } - Napi::Object InitAll(Napi::Env env, Napi::Object exports) { MyObject::Init(env, exports); exports.Set(Napi::String::New(env, "createObject"), - Napi::Function::New(env, CreateObject)); + Napi::Function::New(env, CreateObject)); - exports.Set(Napi::String::New(env, "add"), - Napi::Function::New(env, Add)); + exports.Set(Napi::String::New(env, "add"), Napi::Function::New(env, Add)); return exports; } diff --git a/8_passing_wrapped/node-addon-api/myobject.cc b/8_passing_wrapped/node-addon-api/myobject.cc index b1cd2f14..f2669849 100644 --- a/8_passing_wrapped/node-addon-api/myobject.cc +++ b/8_passing_wrapped/node-addon-api/myobject.cc @@ -1,8 +1,9 @@ +#include "myobject.h" #include #include -#include "myobject.h" -MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { +MyObject::MyObject(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); @@ -23,6 +24,6 @@ void MyObject::Init(Napi::Env env, Napi::Object exports) { } Napi::Object MyObject::NewInstance(Napi::Value arg) { - Napi::Object obj = constructor.New({ arg }); + Napi::Object obj = constructor.New({arg}); return obj; } diff --git a/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc b/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc index 35236162..30e7e996 100644 --- a/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc +++ b/array_buffer_to_native/node-addon-api/array_buffer_to_native.cc @@ -1,5 +1,5 @@ -#include #include +#include static void ArrayConsumer(const int32_t* array, size_t length) { for (size_t index = 0; index < length; index++) { @@ -10,19 +10,19 @@ static void ArrayConsumer(const int32_t* array, size_t length) { static Napi::Value AcceptArrayBuffer(const Napi::CallbackInfo& info) { if (info.Length() != 1) { Napi::Error::New(info.Env(), "Expected exactly one argument") - .ThrowAsJavaScriptException(); + .ThrowAsJavaScriptException(); return info.Env().Undefined(); } if (!info[0].IsArrayBuffer()) { Napi::Error::New(info.Env(), "Expected an ArrayBuffer") - .ThrowAsJavaScriptException(); + .ThrowAsJavaScriptException(); return info.Env().Undefined(); } Napi::ArrayBuffer buf = info[0].As(); ArrayConsumer(reinterpret_cast(buf.Data()), - buf.ByteLength()/sizeof(int32_t)); + buf.ByteLength() / sizeof(int32_t)); return info.Env().Undefined(); } diff --git a/async_pi_estimate/nan/addon.cc b/async_pi_estimate/nan/addon.cc index 3cda98c6..170a7b43 100755 --- a/async_pi_estimate/nan/addon.cc +++ b/async_pi_estimate/nan/addon.cc @@ -1,22 +1,24 @@ #include -#include "sync.h" // NOLINT(build/include) #include "async.h" // NOLINT(build/include) +#include "sync.h" // NOLINT(build/include) -using v8::FunctionTemplate; -using v8::Object; -using v8::String; using Nan::GetFunction; using Nan::New; using Nan::Set; +using v8::FunctionTemplate; +using v8::Object; +using v8::String; // Expose synchronous and asynchronous access to our // Estimate() function NAN_MODULE_INIT(InitAll) { - Set(target, New("calculateSync").ToLocalChecked(), - GetFunction(New(CalculateSync)).ToLocalChecked()); + Set(target, + New("calculateSync").ToLocalChecked(), + GetFunction(New(CalculateSync)).ToLocalChecked()); - Set(target, New("calculateAsync").ToLocalChecked(), - GetFunction(New(CalculateAsync)).ToLocalChecked()); + Set(target, + New("calculateAsync").ToLocalChecked(), + GetFunction(New(CalculateAsync)).ToLocalChecked()); } NODE_MODULE(addon, InitAll) diff --git a/async_pi_estimate/nan/async.cc b/async_pi_estimate/nan/async.cc index cd76c257..3db56f42 100755 --- a/async_pi_estimate/nan/async.cc +++ b/async_pi_estimate/nan/async.cc @@ -1,11 +1,7 @@ +#include "async.h" // NOLINT(build/include) #include #include "pi_est.h" // NOLINT(build/include) -#include "async.h" // NOLINT(build/include) -using v8::Function; -using v8::Local; -using v8::Number; -using v8::Value; using Nan::AsyncQueueWorker; using Nan::AsyncWorker; using Nan::Callback; @@ -13,31 +9,30 @@ using Nan::HandleScope; using Nan::New; using Nan::Null; using Nan::To; +using v8::Function; +using v8::Local; +using v8::Number; +using v8::Value; class PiWorker : public AsyncWorker { public: - PiWorker(Callback *callback, int points) - : AsyncWorker(callback), points(points), estimate(0) {} + PiWorker(Callback* callback, int points) + : AsyncWorker(callback), points(points), estimate(0) {} ~PiWorker() {} // Executed inside the worker-thread. // It is not safe to access V8, or V8 data structures // here, so everything we need for input and output // should go on `this`. - void Execute () { - estimate = Estimate(points); - } + void Execute() { estimate = Estimate(points); } // Executed when the async work is complete // this function will be run inside the main event loop // so it is safe to use V8 again - void HandleOKCallback () { + void HandleOKCallback() { HandleScope scope; - Local argv[] = { - Null() - , New(estimate) - }; + Local argv[] = {Null(), New(estimate)}; callback->Call(2, argv, async_resource); } @@ -50,7 +45,7 @@ class PiWorker : public AsyncWorker { // Asynchronous access to the `Estimate()` function NAN_METHOD(CalculateAsync) { int points = To(info[0]).FromJust(); - Callback *callback = new Callback(To(info[1]).ToLocalChecked()); + Callback* callback = new Callback(To(info[1]).ToLocalChecked()); AsyncQueueWorker(new PiWorker(callback, points)); } diff --git a/async_pi_estimate/nan/pi_est.cc b/async_pi_estimate/nan/pi_est.cc index ac46d53d..2448abc4 100755 --- a/async_pi_estimate/nan/pi_est.cc +++ b/async_pi_estimate/nan/pi_est.cc @@ -1,5 +1,5 @@ -#include #include "pi_est.h" // NOLINT(build/include) +#include /* Estimate the value of π by using a Monte Carlo method. @@ -14,7 +14,7 @@ See https://en.wikipedia.org/wiki/File:Pi_30K.gif for a visualization of how this works. */ -inline int randall(unsigned int *p_seed) { +inline int randall(unsigned int* p_seed) { // windows has thread safe rand() #ifdef _WIN32 return rand(); // NOLINT(runtime/threadsafe_fn) @@ -23,7 +23,7 @@ inline int randall(unsigned int *p_seed) { #endif } -double Estimate (int points) { +double Estimate(int points) { int i = points; int inside = 0; unsigned int randseed = 1; @@ -46,8 +46,7 @@ double Estimate (int points) { // x & y and now values between 0 and 1 // now do a pythagorean diagonal calculation // `1` represents our 1/4 circle - if ((x * x) + (y * y) <= 1) - inside++; + if ((x * x) + (y * y) <= 1) inside++; } // calculate ratio and multiply by 4 for π diff --git a/async_pi_estimate/nan/sync.cc b/async_pi_estimate/nan/sync.cc index b04b2fc3..aefbeef9 100755 --- a/async_pi_estimate/nan/sync.cc +++ b/async_pi_estimate/nan/sync.cc @@ -1,6 +1,6 @@ +#include "sync.h" // NOLINT(build/include) #include #include "pi_est.h" // NOLINT(build/include) -#include "sync.h" // NOLINT(build/include) // Simple synchronous access to the `Estimate()` function NAN_METHOD(CalculateSync) { diff --git a/async_pi_estimate/node-addon-api/addon.cc b/async_pi_estimate/node-addon-api/addon.cc index 3038a2b0..0c597696 100755 --- a/async_pi_estimate/node-addon-api/addon.cc +++ b/async_pi_estimate/node-addon-api/addon.cc @@ -1,12 +1,14 @@ #include -#include "sync.h" // NOLINT(build/include) #include "async.h" // NOLINT(build/include) +#include "sync.h" // NOLINT(build/include) // Expose synchronous and asynchronous access to our // Estimate() function Napi::Object Init(Napi::Env env, Napi::Object exports) { - exports.Set(Napi::String::New(env, "calculateSync"), Napi::Function::New(env, CalculateSync)); - exports.Set(Napi::String::New(env, "calculateAsync"), Napi::Function::New(env, CalculateAsync)); + exports.Set(Napi::String::New(env, "calculateSync"), + Napi::Function::New(env, CalculateSync)); + exports.Set(Napi::String::New(env, "calculateAsync"), + Napi::Function::New(env, CalculateAsync)); return exports; } diff --git a/async_pi_estimate/node-addon-api/async.cc b/async_pi_estimate/node-addon-api/async.cc index accca0ca..ad312c86 100755 --- a/async_pi_estimate/node-addon-api/async.cc +++ b/async_pi_estimate/node-addon-api/async.cc @@ -1,20 +1,18 @@ +#include "async.h" // NOLINT(build/include) #include #include "pi_est.h" // NOLINT(build/include) -#include "async.h" // NOLINT(build/include) class PiWorker : public Napi::AsyncWorker { public: PiWorker(Napi::Function& callback, int points) - : Napi::AsyncWorker(callback), points(points), estimate(0) {} + : Napi::AsyncWorker(callback), points(points), estimate(0) {} ~PiWorker() {} // Executed inside the worker-thread. // It is not safe to access JS engine data structure // here, so everything we need for input and output // should go on `this`. - void Execute () { - estimate = Estimate(points); - } + void Execute() { estimate = Estimate(points); } // Executed when the async work is complete // this function will be run inside the main event loop diff --git a/async_pi_estimate/node-addon-api/pi_est.cc b/async_pi_estimate/node-addon-api/pi_est.cc index ac46d53d..2448abc4 100755 --- a/async_pi_estimate/node-addon-api/pi_est.cc +++ b/async_pi_estimate/node-addon-api/pi_est.cc @@ -1,5 +1,5 @@ -#include #include "pi_est.h" // NOLINT(build/include) +#include /* Estimate the value of π by using a Monte Carlo method. @@ -14,7 +14,7 @@ See https://en.wikipedia.org/wiki/File:Pi_30K.gif for a visualization of how this works. */ -inline int randall(unsigned int *p_seed) { +inline int randall(unsigned int* p_seed) { // windows has thread safe rand() #ifdef _WIN32 return rand(); // NOLINT(runtime/threadsafe_fn) @@ -23,7 +23,7 @@ inline int randall(unsigned int *p_seed) { #endif } -double Estimate (int points) { +double Estimate(int points) { int i = points; int inside = 0; unsigned int randseed = 1; @@ -46,8 +46,7 @@ double Estimate (int points) { // x & y and now values between 0 and 1 // now do a pythagorean diagonal calculation // `1` represents our 1/4 circle - if ((x * x) + (y * y) <= 1) - inside++; + if ((x * x) + (y * y) <= 1) inside++; } // calculate ratio and multiply by 4 for π diff --git a/async_pi_estimate/node-addon-api/sync.cc b/async_pi_estimate/node-addon-api/sync.cc index 4dabedf7..cc08b926 100755 --- a/async_pi_estimate/node-addon-api/sync.cc +++ b/async_pi_estimate/node-addon-api/sync.cc @@ -1,9 +1,9 @@ +#include "sync.h" // NOLINT(build/include) #include #include "pi_est.h" // NOLINT(build/include) -#include "sync.h" // NOLINT(build/include) // Simple synchronous access to the `Estimate()` function - Napi::Value CalculateSync(const Napi::CallbackInfo& info) { +Napi::Value CalculateSync(const Napi::CallbackInfo& info) { // expect a number as the first argument int points = info[0].As().Uint32Value(); double est = Estimate(points); diff --git a/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc b/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc index ab2474b4..f96bdad4 100644 --- a/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc +++ b/emit_event_from_cpp/node-addon-api/src/emit-from-cpp.cc @@ -1,27 +1,27 @@ -#include +#include #include -#include #include +#include Napi::Value CallEmit(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::Function emit = info[0].As(); - emit.Call({Napi::String::New(env, "start")}); - for(int i = 0; i < 3; i++) { - std::this_thread::sleep_for(std::chrono::seconds(3)); - emit.Call({Napi::String::New(env, "data"), - Napi::String::New(env, "data ...")}); - } - emit.Call({Napi::String::New(env, "end")}); - return Napi::String::New(env, "OK"); + Napi::Env env = info.Env(); + Napi::Function emit = info[0].As(); + emit.Call({Napi::String::New(env, "start")}); + for (int i = 0; i < 3; i++) { + std::this_thread::sleep_for(std::chrono::seconds(3)); + emit.Call( + {Napi::String::New(env, "data"), Napi::String::New(env, "data ...")}); + } + emit.Call({Napi::String::New(env, "end")}); + return Napi::String::New(env, "OK"); } // Init Napi::Object Init(Napi::Env env, Napi::Object exports) { - exports.Set(Napi::String::New(env, "callEmit"), - Napi::Function::New(env, CallEmit)); - return exports; + exports.Set(Napi::String::New(env, "callEmit"), + Napi::Function::New(env, CallEmit)); + return exports; } NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init); diff --git a/inherits_from_event_emitter/node-addon-api/src/binding.cc b/inherits_from_event_emitter/node-addon-api/src/binding.cc index 03c366ca..fb5fa9dd 100644 --- a/inherits_from_event_emitter/node-addon-api/src/binding.cc +++ b/inherits_from_event_emitter/node-addon-api/src/binding.cc @@ -2,8 +2,8 @@ #include "native-emitter.h" Napi::Object Init(Napi::Env env, Napi::Object exports) { - NativeEmitter::Init(env, exports); - return exports; + NativeEmitter::Init(env, exports); + return exports; } NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc b/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc index bc5c8185..2c90bf0c 100644 --- a/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc +++ b/inherits_from_event_emitter/node-addon-api/src/native-emitter.cc @@ -1,6 +1,6 @@ #include -#include #include +#include #include "native-emitter.h" @@ -9,9 +9,10 @@ Napi::FunctionReference NativeEmitter::constructor; Napi::Object NativeEmitter::Init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); - Napi::Function func = DefineClass(env, "NativeEmitter", { - InstanceMethod("callAndEmit", &NativeEmitter::CallAndEmit) - }); + Napi::Function func = + DefineClass(env, + "NativeEmitter", + {InstanceMethod("callAndEmit", &NativeEmitter::CallAndEmit)}); constructor = Napi::Persistent(func); constructor.SuppressDestruct(); @@ -21,20 +22,21 @@ Napi::Object NativeEmitter::Init(Napi::Env env, Napi::Object exports) { } NativeEmitter::NativeEmitter(const Napi::CallbackInfo& info) -: Napi::ObjectWrap(info) { + : Napi::ObjectWrap(info) { // NOOP } Napi::Value NativeEmitter::CallAndEmit(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - Napi::Function emit = info.This().As() - .Get("emit").As(); - emit.Call(info.This(), { Napi::String::New(env, "start") }); - for(int i = 0; i < 3; i++) { - std::this_thread::sleep_for(std::chrono::seconds(1)); - emit.Call(info.This(), { Napi::String::New(env, "data"), - Napi::String::New(env, "data ...") }); - } - emit.Call(info.This(), { Napi::String::New(env, "end") }); - return Napi::String::New(env, "OK"); + Napi::Env env = info.Env(); + Napi::Function emit = + info.This().As().Get("emit").As(); + emit.Call(info.This(), {Napi::String::New(env, "start")}); + for (int i = 0; i < 3; i++) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + emit.Call( + info.This(), + {Napi::String::New(env, "data"), Napi::String::New(env, "data ...")}); + } + emit.Call(info.This(), {Napi::String::New(env, "end")}); + return Napi::String::New(env, "OK"); } diff --git a/inherits_from_event_emitter/node-addon-api/src/native-emitter.h b/inherits_from_event_emitter/node-addon-api/src/native-emitter.h index c1942c59..56cdc405 100644 --- a/inherits_from_event_emitter/node-addon-api/src/native-emitter.h +++ b/inherits_from_event_emitter/node-addon-api/src/native-emitter.h @@ -1,12 +1,12 @@ #include class NativeEmitter : public Napi::ObjectWrap { - public: - static Napi::Object Init(Napi::Env env, Napi::Object exports); - NativeEmitter(const Napi::CallbackInfo& info); + public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + NativeEmitter(const Napi::CallbackInfo& info); - private: - static Napi::FunctionReference constructor; + private: + static Napi::FunctionReference constructor; - Napi::Value CallAndEmit(const Napi::CallbackInfo& info); + Napi::Value CallAndEmit(const Napi::CallbackInfo& info); }; diff --git a/multiple_load/node_10/multiple_load.cc b/multiple_load/node_10/multiple_load.cc index afeb5a42..447ec920 100644 --- a/multiple_load/node_10/multiple_load.cc +++ b/multiple_load/node_10/multiple_load.cc @@ -1,5 +1,5 @@ -#include #include +#include using namespace v8; @@ -41,11 +41,11 @@ class AddonData { // call from JavaScript. double value; - explicit AddonData(Isolate* isolate, Local exports): - // The payload is initialized here. The rest of the constructor is - // boilerplate that ensures that the instance of this addon data is - // destroyed along with the instance of this addon (`exports`). - value(0.0) { + explicit AddonData(Isolate* isolate, Local exports) + : // The payload is initialized here. The rest of the constructor is + // boilerplate that ensures that the instance of this addon data is + // destroyed along with the instance of this addon (`exports`). + value(0.0) { exports_persistent.Reset(isolate, exports); exports_persistent.SetWeak(this, DeleteMe, WeakCallbackType::kParameter); } @@ -54,9 +54,7 @@ class AddonData { // The persistent reference must be reset before the instance of this class is // destroyed, otherwise memory will leak on the V8 side. - ~AddonData() { - exports_persistent.Reset(); - } + ~AddonData() { exports_persistent.Reset(); } // This static function will be called when the addon instance is unloaded. It // merely destroys the per-addon-instance data. @@ -73,8 +71,8 @@ void Increment(const FunctionCallbackInfo& info) { AddonData* addon_data = static_cast(info.Data().As()->Value()); - info.GetReturnValue() - .Set(Number::New(info.GetIsolate(), addon_data->GetNewValue(1.0))); + info.GetReturnValue().Set( + Number::New(info.GetIsolate(), addon_data->GetNewValue(1.0))); } // Function called from JavaScript to decrement the value stored in this addon. @@ -83,8 +81,8 @@ void Decrement(const FunctionCallbackInfo& info) { AddonData* addon_data = static_cast(info.Data().As()->Value()); - info.GetReturnValue() - .Set(Number::New(info.GetIsolate(), addon_data->GetNewValue(-1.0))); + info.GetReturnValue().Set( + Number::New(info.GetIsolate(), addon_data->GetNewValue(-1.0))); } // Initialize the addon in such a way that it may be initialized multiple times @@ -103,15 +101,21 @@ NODE_MODULE_INIT(/*exports, module, context*/) { // Export the functions we wish to make available to JavaScript. - exports->Set(context, - String::NewFromUtf8(isolate, "increment", NewStringType::kNormal) - .ToLocalChecked(), - FunctionTemplate::New(isolate, Increment, addon_data) - ->GetFunction(context).ToLocalChecked()).FromJust(); - - exports->Set(context, - String::NewFromUtf8(isolate, "decrement", NewStringType::kNormal) - .ToLocalChecked(), - FunctionTemplate::New(isolate, Decrement, addon_data) - ->GetFunction(context).ToLocalChecked()).FromJust(); + exports + ->Set(context, + String::NewFromUtf8(isolate, "increment", NewStringType::kNormal) + .ToLocalChecked(), + FunctionTemplate::New(isolate, Increment, addon_data) + ->GetFunction(context) + .ToLocalChecked()) + .FromJust(); + + exports + ->Set(context, + String::NewFromUtf8(isolate, "decrement", NewStringType::kNormal) + .ToLocalChecked(), + FunctionTemplate::New(isolate, Decrement, addon_data) + ->GetFunction(context) + .ToLocalChecked()) + .FromJust(); } diff --git a/package.json b/package.json index cdf1d737..76aee681 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "description": "Node.js Addon Examples", "main": "test_all.js", "scripts": { + "format": "clang-format -i --glob=*/**/*.{h,cpp,cc}", "test": "node test_all.js" }, "dependencies": { "chalk": "^2.4.2", + "clang-format": "^1.2.4", "semver": "^6.3.0" } }