@@ -13,17 +13,21 @@ Context::Context(const Napi::CallbackInfo& info)
1313 /* If this module has no global context, then create one with a process
1414 wide context pointer that is shared between threads/agents. */
1515 if (module .GlobalContext .IsEmpty ()) {
16- if (Arg::Validator{}.ThrowIfInvalid (info)) return ;
16+ if (Arg::Validator{}.ThrowIfInvalid (info)) {
17+ return ;
18+ }
1719
1820 /* Just use the same shared global context pointer. Contexts are
1921 threadsafe anyway. */
2022 context = module .Global ().SharedContext ;
2123 } else {
22- Arg::Validator args{
24+ Arg::Validator const args{
2325 Arg::Optional<Arg::Object>(" Options must be an object" ),
2426 };
2527
26- if (args.ThrowIfInvalid (info)) return ;
28+ if (args.ThrowIfInvalid (info)) {
29+ return ;
30+ }
2731
2832 context = zmq_ctx_new ();
2933 }
@@ -62,7 +66,7 @@ void Context::Close() {
6266 termination may block depending on ZMQ_BLOCKY/ZMQ_LINGER. This
6367 should definitely be avoided during GC and may only be acceptable
6468 at process exit. */
65- auto err = zmq_ctx_shutdown (context);
69+ [[maybe_unused]] auto err = zmq_ctx_shutdown (context);
6670 assert (err == 0 );
6771
6872 /* Pass the ZMQ context on to terminator for cleanup at exit. */
@@ -76,35 +80,39 @@ void Context::Close() {
7680
7781template <>
7882Napi::Value Context::GetCtxOpt<bool >(const Napi::CallbackInfo& info) {
79- Arg::Validator args{
83+ Arg::Validator const args{
8084 Arg::Required<Arg::Number>(" Identifier must be a number" ),
8185 };
8286
83- if (args.ThrowIfInvalid (info)) return Env ().Undefined ();
87+ if (args.ThrowIfInvalid (info)) {
88+ return Env ().Undefined ();
89+ }
8490
85- uint32_t option = info[0 ].As <Napi::Number>();
91+ const auto option = info[0 ].As <Napi::Number>();
8692
87- int32_t value = zmq_ctx_get (context, option);
93+ int32_t const value = zmq_ctx_get (context, option);
8894 if (value < 0 ) {
8995 ErrnoException (Env (), zmq_errno ()).ThrowAsJavaScriptException ();
9096 return Env ().Undefined ();
9197 }
9298
93- return Napi::Boolean::New (Env (), value);
99+ return Napi::Boolean::New (Env (), value != 0 );
94100}
95101
96102template <>
97103void Context::SetCtxOpt<bool >(const Napi::CallbackInfo& info) {
98- Arg::Validator args{
104+ Arg::Validator const args{
99105 Arg::Required<Arg::Number>(" Identifier must be a number" ),
100106 Arg::Required<Arg::Boolean>(" Option value must be a boolean" ),
101107 };
102108
103- if (args.ThrowIfInvalid (info)) return ;
109+ if (args.ThrowIfInvalid (info)) {
110+ return ;
111+ }
104112
105- uint32_t option = info[0 ].As <Napi::Number>();
113+ const auto option = info[0 ].As <Napi::Number>();
106114
107- int32_t value = info[1 ].As <Napi::Boolean>();
115+ int32_t const value = static_cast < int32_t >( info[1 ].As <Napi::Boolean>() );
108116 if (zmq_ctx_set (context, option, value) < 0 ) {
109117 ErrnoException (Env (), zmq_errno ()).ThrowAsJavaScriptException ();
110118 return ;
@@ -113,13 +121,15 @@ void Context::SetCtxOpt<bool>(const Napi::CallbackInfo& info) {
113121
114122template <typename T>
115123Napi::Value Context::GetCtxOpt (const Napi::CallbackInfo& info) {
116- Arg::Validator args{
124+ Arg::Validator const args{
117125 Arg::Required<Arg::Number>(" Identifier must be a number" ),
118126 };
119127
120- if (args.ThrowIfInvalid (info)) return Env ().Undefined ();
128+ if (args.ThrowIfInvalid (info)) {
129+ return Env ().Undefined ();
130+ }
121131
122- uint32_t option = info[0 ].As <Napi::Number>();
132+ const auto option = info[0 ].As <Napi::Number>();
123133
124134 T value = zmq_ctx_get (context, option);
125135 if (value < 0 ) {
@@ -132,14 +142,16 @@ Napi::Value Context::GetCtxOpt(const Napi::CallbackInfo& info) {
132142
133143template <typename T>
134144void Context::SetCtxOpt (const Napi::CallbackInfo& info) {
135- Arg::Validator args{
145+ Arg::Validator const args{
136146 Arg::Required<Arg::Number>(" Identifier must be a number" ),
137147 Arg::Required<Arg::Number>(" Option value must be a number" ),
138148 };
139149
140- if (args.ThrowIfInvalid (info)) return ;
150+ if (args.ThrowIfInvalid (info)) {
151+ return ;
152+ }
141153
142- uint32_t option = info[0 ].As <Napi::Number>();
154+ const auto option = info[0 ].As <Napi::Number>();
143155
144156 T value = info[1 ].As <Napi::Number>();
145157 if (zmq_ctx_set (context, option, value) < 0 ) {
@@ -166,4 +178,4 @@ void Context::Initialize(Module& module, Napi::Object& exports) {
166178 module .Context = Napi::Persistent (constructor);
167179 exports.Set (" Context" , constructor);
168180}
169- }
181+ } // namespace zmq
0 commit comments