@@ -36,34 +36,34 @@ std::unordered_map<node::Environment*, bool>
3636std::set<node::Environment*> uvLoopTask;
3737
3838ll::Expected<> PatchDelayImport (HMODULE hAddon, HMODULE hLibNode) {
39- BYTE* base = ( BYTE*) hAddon;
40- auto dos = ( PIMAGE_DOS_HEADER) base;
39+ BYTE* base = reinterpret_cast < BYTE*>( hAddon) ;
40+ auto dos = reinterpret_cast < PIMAGE_DOS_HEADER>( base) ;
4141 if (dos->e_magic != IMAGE_DOS_SIGNATURE) {
4242 return ll::makeStringError (" Invalid DOS signature." );
4343 }
44- auto nt = ( PIMAGE_NT_HEADERS) (base + dos->e_lfanew );
44+ auto nt = reinterpret_cast < PIMAGE_NT_HEADERS> (base + dos->e_lfanew );
4545 if (nt->Signature != IMAGE_NT_SIGNATURE) {
4646 return ll::makeStringError (" Invalid NT signature." );
4747 }
4848 DWORD rva = nt->OptionalHeader .DataDirectory [IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress ;
4949 if (!rva) {};
50- auto pDesc = ( PIMAGE_DELAYLOAD_DESCRIPTOR) (base + rva);
50+ auto pDesc = reinterpret_cast < PIMAGE_DELAYLOAD_DESCRIPTOR> (base + rva);
5151 for (; pDesc->DllNameRVA ; ++pDesc) {
52- char * szDll = ( char *) (base + pDesc->DllNameRVA );
52+ char * szDll = reinterpret_cast < char *> (base + pDesc->DllNameRVA );
5353 if (_stricmp (szDll, NODE_HOST_BINARY_NAME) != 0 ) continue ;
5454
55- auto pIAT = ( PIMAGE_THUNK_DATA) (base + pDesc->ImportAddressTableRVA );
56- auto pINT = ( PIMAGE_THUNK_DATA) (base + pDesc->ImportNameTableRVA );
55+ auto pIAT = reinterpret_cast < PIMAGE_THUNK_DATA> (base + pDesc->ImportAddressTableRVA );
56+ auto pINT = reinterpret_cast < PIMAGE_THUNK_DATA> (base + pDesc->ImportNameTableRVA );
5757
5858 for (; pIAT->u1 .Function ; ++pIAT, ++pINT) {
59- FARPROC f = nullptr ;
59+ FARPROC f;
6060 if (pINT->u1 .Ordinal & IMAGE_ORDINAL_FLAG) {
6161 // Import by Ordinal
6262 WORD ordinal = IMAGE_ORDINAL (pINT->u1 .Ordinal );
6363 f = GetProcAddress (hLibNode, MAKEINTRESOURCEA (ordinal));
6464 } else {
6565 // Import by name
66- auto name = ( PIMAGE_IMPORT_BY_NAME) (base + pINT->u1 .AddressOfData );
66+ auto name = reinterpret_cast < PIMAGE_IMPORT_BY_NAME> (base + pINT->u1 .AddressOfData );
6767 f = GetProcAddress (hLibNode, name->Name );
6868 }
6969 if (f) {
@@ -112,7 +112,7 @@ bool initNodeJs() {
112112 }
113113 // Init NodeJs
114114 auto path = ll::string_utils::u8str2str (ll::sys_utils::getModulePath (nullptr ).value ().u8string ());
115- char * cPath = ( char *) path.c_str ();
115+ char * cPath = const_cast < char *>( path.c_str () );
116116 uv_setup_args (1 , &cPath);
117117 auto full_args = std::vector<std::string>{path};
118118#if defined(LSE_DEBUG) || defined(LSE_TEST)
@@ -131,15 +131,15 @@ bool initNodeJs() {
131131 );
132132 if (result->exit_code () != 0 ) {
133133 lse::LegacyScriptEngine::getLogger ().error (" Failed to initialize node! NodeJs plugins won't be loaded" );
134- for (const std::string& error : result->errors ()) lse::LegacyScriptEngine::getLogger ().error (error);
134+ for (std::string const & error : result->errors ()) lse::LegacyScriptEngine::getLogger ().error (error);
135135 return false ;
136136 }
137137 args = result->args ();
138138 exec_args = result->exec_args ();
139139
140140 // Init V8
141141 using namespace v8 ;
142- platform = node::MultiIsolatePlatform::Create (( int ) std::thread::hardware_concurrency ());
142+ platform = node::MultiIsolatePlatform::Create (static_cast < int >( std::thread::hardware_concurrency () ));
143143 V8::InitializePlatform (platform.get ());
144144 V8::Initialize ();
145145
@@ -169,7 +169,7 @@ std::shared_ptr<ScriptEngine> newEngine() {
169169 // CHECK_EQ(start_io_thread_async_initialized.exchange(true), false) fail!
170170
171171 if (!setup) {
172- for (const std::string& err : errors)
172+ for (std::string const & err : errors)
173173 lse::LegacyScriptEngine::getLogger ().error (" CommonEnvironmentSetup Error: {}" , err.c_str ());
174174 return nullptr ;
175175 }
@@ -184,7 +184,10 @@ std::shared_ptr<ScriptEngine> newEngine() {
184184 std::shared_ptr<ScriptEngine> engine (new ScriptEngineImpl ({}, isolate, setup->context (), false ), [](ScriptEngine*) {
185185 });
186186
187- lse::LegacyScriptEngine::getLogger ().debug (" Initialize ScriptEngine for node.js [{}]" , (void *)engine.get ());
187+ lse::LegacyScriptEngine::getLogger ().debug (
188+ " Initialize ScriptEngine for node.js [{}]" ,
189+ static_cast <void *>(engine.get ())
190+ );
188191 environments[engine] = env;
189192 setups[engine] = std::move (setup);
190193 isRunning[env] = true ;
@@ -289,7 +292,7 @@ bool loadPluginCode(
289292 }
290293
291294 // Set exit handler
292- node::SetProcessExitHandler (env, [](node::Environment* env_, int exit_code) {
295+ node::SetProcessExitHandler (env, [](node::Environment const * env_, int exit_code) {
293296 auto engine = getEngine (env_);
294297 lse::LegacyScriptEngine::getLogger ().log (
295298 exit_code == 0 ? ll::io::LogLevel::Debug : ll::io::LogLevel::Error,
@@ -342,7 +345,7 @@ bool loadPluginCode(
342345 using namespace ll ::chrono_literals;
343346 while (uvLoopTask.contains (env)) {
344347 co_await 2_tick;
345- if (!( ll::getGamingStatus () != ll::GamingStatus::Running) && (*isRunningMap)[env]) {
348+ if (ll::getGamingStatus () == ll::GamingStatus::Running && (*isRunningMap)[env]) {
346349 EngineScope enter (engine.get ());
347350 // v8::MicrotasksScope microtaskScope(isolate, v8::MicrotasksScope::kRunMicrotasks);
348351 uv_run (eventLoop, UV_RUN_NOWAIT);
@@ -364,13 +367,13 @@ bool loadPluginCode(
364367 }
365368}
366369
367- node::Environment* getEnvironmentOf (std::shared_ptr<ScriptEngine> engine) {
370+ node::Environment* getEnvironmentOf (std::shared_ptr<ScriptEngine> const & engine) {
368371 auto it = environments.find (engine);
369372 if (it == environments.end ()) return nullptr ;
370373 return it->second ;
371374}
372375
373- v8::Isolate* getIsolateOf (std::shared_ptr<ScriptEngine> engine) {
376+ v8::Isolate* getIsolateOf (std::shared_ptr<ScriptEngine> const & engine) {
374377 auto it = setups.find (engine);
375378 if (it == setups.end ()) return nullptr ;
376379 return it->second ->isolate ();
@@ -393,24 +396,24 @@ bool stopEngine(node::Environment* env) {
393396
394397 return true ;
395398 } catch (...) {
396- lse::LegacyScriptEngine::getLogger ().error (" Fail to stop engine {}" , ( void *) env);
399+ lse::LegacyScriptEngine::getLogger ().error (" Fail to stop engine {}" , static_cast < void *>( env) );
397400 ll::error_utils::printCurrentException (lse::LegacyScriptEngine::getLogger ());
398401 return false ;
399402 }
400403}
401404
402- bool stopEngine (std::shared_ptr<ScriptEngine> engine) {
405+ bool stopEngine (std::shared_ptr<ScriptEngine> const & engine) {
403406 auto env = NodeJsHelper::getEnvironmentOf (engine);
404407 return stopEngine (env);
405408}
406409
407- std::shared_ptr<ScriptEngine> getEngine (node::Environment* env) {
410+ std::shared_ptr<ScriptEngine> getEngine (node::Environment const * env) {
408411 for (auto & [engine, environment] : environments)
409412 if (env == environment) return engine;
410413 return nullptr ;
411414}
412415
413- std::string findEntryScript (const std::string& dirPath) {
416+ std::string findEntryScript (std::string const & dirPath) {
414417 auto dirPath_obj = std::filesystem::path (dirPath);
415418
416419 std::filesystem::path packageFilePath = dirPath_obj / " package.json" ;
@@ -432,7 +435,7 @@ std::string findEntryScript(const std::string& dirPath) {
432435 }
433436}
434437
435- std::string getPluginPackageName (const std::string& dirPath) {
438+ std::string getPluginPackageName (std::string const & dirPath) {
436439 auto dirPath_obj = std::filesystem::path (dirPath);
437440
438441 std::filesystem::path packageFilePath = dirPath_obj / std::filesystem::path (" package.json" );
@@ -452,7 +455,7 @@ std::string getPluginPackageName(const std::string& dirPath) {
452455 }
453456}
454457
455- bool doesPluginPackHasDependency (const std::string& dirPath) {
458+ bool doesPluginPackHasDependency (std::string const & dirPath) {
456459 auto dirPath_obj = std::filesystem::path (dirPath);
457460
458461 std::filesystem::path packageFilePath = dirPath_obj / std::filesystem::path (" package.json" );
@@ -471,7 +474,7 @@ bool doesPluginPackHasDependency(const std::string& dirPath) {
471474 }
472475}
473476
474- bool isESModulesSystem (const std::string& dirPath) {
477+ bool isESModulesSystem (std::string const & dirPath) {
475478 auto dirPath_obj = std::filesystem::path (dirPath);
476479
477480 std::filesystem::path packageFilePath = dirPath_obj / std::filesystem::path (" package.json" );
@@ -490,7 +493,7 @@ bool isESModulesSystem(const std::string& dirPath) {
490493 }
491494}
492495
493- bool processConsoleNpmCmd (const std::string& cmd) {
496+ bool processConsoleNpmCmd (std::string const & cmd) {
494497#ifdef LSE_BACKEND_NODEJS
495498 if (cmd.starts_with (" npm " ) || cmd.starts_with (" npx " )) {
496499 executeNpmCommand (SplitCmdLine (cmd));
@@ -537,7 +540,7 @@ int executeNpmCommand(std::vector<std::string> npmArgs, std::string workingDir)
537540 // CHECK_EQ(start_io_thread_async_initialized.exchange(true), false) fail!
538541
539542 if (!setup) {
540- for (const std::string& err : errors)
543+ for (std::string const & err : errors)
541544 lse::LegacyScriptEngine::getLogger ().error (" CommonEnvironmentSetup Error: {}" , err.c_str ());
542545 return -1 ;
543546 }
0 commit comments