6
6
#include " node_native_module_env.h"
7
7
#include " util.h"
8
8
9
+ #include < string>
10
+
9
11
#if HAVE_OPENSSL
10
12
#define NODE_BUILTIN_OPENSSL_MODULES (V ) V(crypto) V(tls_wrap)
11
13
#else
@@ -424,13 +426,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
424
426
CHECK_NULL (thread_local_modpending);
425
427
426
428
if (args.Length () < 2 ) {
427
- env-> ThrowError ( " process.dlopen needs at least 2 arguments. " );
428
- return ;
429
+ return THROW_ERR_MISSING_ARGS (
430
+ env, " process.dlopen needs at least 2 arguments " ) ;
429
431
}
430
432
431
433
int32_t flags = DLib::kDefaultFlags ;
432
434
if (args.Length () > 2 && !args[2 ]->Int32Value (context).To (&flags)) {
433
- return env-> ThrowTypeError ( " flag argument must be an integer." );
435
+ return THROW_ERR_INVALID_ARG_TYPE (env, " flag argument must be an integer." );
434
436
}
435
437
436
438
Local<Object> module;
@@ -456,15 +458,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
456
458
thread_local_modpending = nullptr ;
457
459
458
460
if (!is_opened) {
459
- Local<String> errmsg =
460
- OneByteString (env->isolate (), dlib->errmsg_ .c_str ());
461
+ std::string errmsg = dlib->errmsg_ .c_str ();
461
462
dlib->Close ();
462
463
#ifdef _WIN32
463
464
// Windows needs to add the filename into the error message
464
- errmsg = String::Concat (
465
- env->isolate (), errmsg, args[1 ]->ToString (context).ToLocalChecked ());
465
+ errmsg += *filename;
466
466
#endif // _WIN32
467
- env-> isolate ()-> ThrowException ( Exception::Error ( errmsg));
467
+ THROW_ERR_DLOPEN_FAILED (env, errmsg. c_str ( ));
468
468
return false ;
469
469
}
470
470
@@ -494,7 +494,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
494
494
sizeof (errmsg),
495
495
" Module did not self-register: '%s'." ,
496
496
*filename);
497
- env-> ThrowError ( errmsg);
497
+ THROW_ERR_DLOPEN_FAILED (env, errmsg);
498
498
return false ;
499
499
}
500
500
}
@@ -525,7 +525,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
525
525
// NOTE: `mp` is allocated inside of the shared library's memory, calling
526
526
// `dlclose` will deallocate it
527
527
dlib->Close ();
528
- env-> ThrowError ( errmsg);
528
+ THROW_ERR_DLOPEN_FAILED (env, errmsg);
529
529
return false ;
530
530
}
531
531
CHECK_EQ (mp->nm_flags & NM_F_BUILTIN, 0 );
@@ -538,7 +538,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
538
538
mp->nm_register_func (exports, module, mp->nm_priv );
539
539
} else {
540
540
dlib->Close ();
541
- env-> ThrowError ( " Module has no declared entry point." );
541
+ THROW_ERR_DLOPEN_FAILED (env, " Module has no declared entry point." );
542
542
return false ;
543
543
}
544
544
@@ -577,12 +577,6 @@ static Local<Object> InitModule(Environment* env,
577
577
return exports;
578
578
}
579
579
580
- static void ThrowIfNoSuchModule (Environment* env, const char * module_v) {
581
- char errmsg[1024 ];
582
- snprintf (errmsg, sizeof (errmsg), " No such module: %s" , module_v);
583
- env->ThrowError (errmsg);
584
- }
585
-
586
580
void GetInternalBinding (const FunctionCallbackInfo<Value>& args) {
587
581
Environment* env = Environment::GetCurrent (args);
588
582
@@ -611,7 +605,9 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
611
605
env->isolate ()))
612
606
.FromJust ());
613
607
} else {
614
- return ThrowIfNoSuchModule (env, *module_v);
608
+ char errmsg[1024 ];
609
+ snprintf (errmsg, sizeof (errmsg), " No such module: %s" , *module_v);
610
+ return THROW_ERR_INVALID_MODULE (env, errmsg);
615
611
}
616
612
617
613
args.GetReturnValue ().Set (exports);
@@ -646,7 +642,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
646
642
sizeof (errmsg),
647
643
" No such module was linked: %s" ,
648
644
*module_name_v);
649
- return env-> ThrowError ( errmsg);
645
+ return THROW_ERR_INVALID_MODULE (env, errmsg);
650
646
}
651
647
652
648
Local<Object> module = Object::New (env->isolate ());
@@ -661,7 +657,9 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
661
657
} else if (mod->nm_register_func != nullptr ) {
662
658
mod->nm_register_func (exports, module, mod->nm_priv );
663
659
} else {
664
- return env->ThrowError (" Linked module has no declared entry point." );
660
+ return THROW_ERR_INVALID_MODULE (
661
+ env,
662
+ " Linked moduled has no declared entry point." );
665
663
}
666
664
667
665
auto effective_exports =
0 commit comments