@@ -176,89 +176,90 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
176
176
177
177
node::Utf8Value filename (env->isolate (), args[1 ]); // Cast
178
178
env->TryLoadAddon (*filename, flags, [&](DLib* dlib) {
179
- const bool is_opened = dlib->Open ();
180
-
181
- // Objects containing v14 or later modules will have registered themselves
182
- // on the pending list. Activate all of them now. At present, only one
183
- // module per object is supported.
184
- node_module* const mp =
185
- static_cast <node_module*>(uv_key_get (&thread_local_modpending));
186
- uv_key_set (&thread_local_modpending, nullptr );
187
-
188
- if (!is_opened) {
189
- Local<String> errmsg = OneByteString (env->isolate (), dlib->errmsg_ .c_str ());
190
- dlib->Close ();
179
+ const bool is_opened = dlib->Open ();
180
+
181
+ // Objects containing v14 or later modules will have registered themselves
182
+ // on the pending list. Activate all of them now. At present, only one
183
+ // module per object is supported.
184
+ node_module* const mp =
185
+ static_cast <node_module*>(uv_key_get (&thread_local_modpending));
186
+ uv_key_set (&thread_local_modpending, nullptr );
187
+
188
+ if (!is_opened) {
189
+ Local<String> errmsg =
190
+ OneByteString (env->isolate (), dlib->errmsg_ .c_str ());
191
+ dlib->Close ();
191
192
#ifdef _WIN32
192
- // Windows needs to add the filename into the error message
193
- errmsg = String::Concat (
194
- env->isolate (), errmsg, args[1 ]->ToString (context).ToLocalChecked ());
193
+ // Windows needs to add the filename into the error message
194
+ errmsg = String::Concat (
195
+ env->isolate (), errmsg, args[1 ]->ToString (context).ToLocalChecked ());
195
196
#endif // _WIN32
196
- env->isolate ()->ThrowException (Exception::Error (errmsg));
197
- return false ;
198
- }
199
-
200
- if (mp == nullptr ) {
201
- if (auto callback = GetInitializerCallback (dlib)) {
202
- callback (exports, module, context);
203
- } else if (auto napi_callback = GetNapiInitializerCallback (dlib)) {
204
- napi_module_register_by_symbol (exports, module, context, napi_callback);
205
- } else {
206
- dlib->Close ();
207
- env->ThrowError (" Module did not self-register." );
197
+ env->isolate ()->ThrowException (Exception::Error (errmsg));
208
198
return false ;
209
199
}
210
- return true ;
211
- }
212
200
213
- // -1 is used for N-API modules
214
- if ((mp->nm_version != -1 ) && (mp->nm_version != NODE_MODULE_VERSION)) {
215
- // Even if the module did self-register, it may have done so with the wrong
216
- // version. We must only give up after having checked to see if it has an
217
- // appropriate initializer callback.
218
- if (auto callback = GetInitializerCallback (dlib)) {
219
- callback (exports, module, context);
201
+ if (mp == nullptr ) {
202
+ if (auto callback = GetInitializerCallback (dlib)) {
203
+ callback (exports, module, context);
204
+ } else if (auto napi_callback = GetNapiInitializerCallback (dlib)) {
205
+ napi_module_register_by_symbol (exports, module, context, napi_callback);
206
+ } else {
207
+ dlib->Close ();
208
+ env->ThrowError (" Module did not self-register." );
209
+ return false ;
210
+ }
220
211
return true ;
221
212
}
222
- char errmsg[1024 ];
223
- snprintf (errmsg,
224
- sizeof (errmsg),
225
- " The module '%s'"
226
- " \n was compiled against a different Node.js version using"
227
- " \n NODE_MODULE_VERSION %d. This version of Node.js requires"
228
- " \n NODE_MODULE_VERSION %d. Please try re-compiling or "
229
- " re-installing\n the module (for instance, using `npm rebuild` "
230
- " or `npm install`)." ,
231
- *filename,
232
- mp->nm_version ,
233
- NODE_MODULE_VERSION);
234
-
235
- // NOTE: `mp` is allocated inside of the shared library's memory, calling
236
- // `dlclose` will deallocate it
237
- dlib->Close ();
238
- env->ThrowError (errmsg);
239
- return false ;
240
- }
241
- if (mp->nm_flags & NM_F_BUILTIN) {
242
- dlib->Close ();
243
- env->ThrowError (" Built-in module self-registered." );
244
- return false ;
245
- }
246
213
247
- mp->nm_dso_handle = dlib->handle_ ;
248
- mp->nm_link = modlist_addon;
249
- modlist_addon = mp;
214
+ // -1 is used for N-API modules
215
+ if ((mp->nm_version != -1 ) && (mp->nm_version != NODE_MODULE_VERSION)) {
216
+ // Even if the module did self-register, it may have done so with the
217
+ // wrong version. We must only give up after having checked to see if it
218
+ // has an appropriate initializer callback.
219
+ if (auto callback = GetInitializerCallback (dlib)) {
220
+ callback (exports, module, context);
221
+ return true ;
222
+ }
223
+ char errmsg[1024 ];
224
+ snprintf (errmsg,
225
+ sizeof (errmsg),
226
+ " The module '%s'"
227
+ " \n was compiled against a different Node.js version using"
228
+ " \n NODE_MODULE_VERSION %d. This version of Node.js requires"
229
+ " \n NODE_MODULE_VERSION %d. Please try re-compiling or "
230
+ " re-installing\n the module (for instance, using `npm rebuild` "
231
+ " or `npm install`)." ,
232
+ *filename,
233
+ mp->nm_version ,
234
+ NODE_MODULE_VERSION);
235
+
236
+ // NOTE: `mp` is allocated inside of the shared library's memory, calling
237
+ // `dlclose` will deallocate it
238
+ dlib->Close ();
239
+ env->ThrowError (errmsg);
240
+ return false ;
241
+ }
242
+ if (mp->nm_flags & NM_F_BUILTIN) {
243
+ dlib->Close ();
244
+ env->ThrowError (" Built-in module self-registered." );
245
+ return false ;
246
+ }
250
247
251
- if (mp->nm_context_register_func != nullptr ) {
252
- mp->nm_context_register_func (exports, module, context, mp->nm_priv );
253
- } else if (mp->nm_register_func != nullptr ) {
254
- mp->nm_register_func (exports, module, mp->nm_priv );
255
- } else {
256
- dlib->Close ();
257
- env->ThrowError (" Module has no declared entry point." );
258
- return false ;
259
- }
248
+ mp->nm_dso_handle = dlib->handle_ ;
249
+ mp->nm_link = modlist_addon;
250
+ modlist_addon = mp;
260
251
261
- return true ;
252
+ if (mp->nm_context_register_func != nullptr ) {
253
+ mp->nm_context_register_func (exports, module, context, mp->nm_priv );
254
+ } else if (mp->nm_register_func != nullptr ) {
255
+ mp->nm_register_func (exports, module, mp->nm_priv );
256
+ } else {
257
+ dlib->Close ();
258
+ env->ThrowError (" Module has no declared entry point." );
259
+ return false ;
260
+ }
261
+
262
+ return true ;
262
263
});
263
264
264
265
// Tell coverity that 'handle' should not be freed when we return.
0 commit comments