@@ -572,14 +572,22 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
572572 return ;
573573 }
574574 *function = [func, function_name, this ](ContextBase *context, Args... args) -> void {
575- wasm::Val params[] = {makeVal (args)...};
576575 const bool log = cmpLogLevel (LogLevel::trace);
577- if (log) {
578- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
579- printValues (params, sizeof ...(Args)) + " )" );
580- }
581576 SaveRestoreContext saved_context (context);
582- auto trap = func->call (params, nullptr );
577+ wasm::own<wasm::Trap> trap = nullptr ;
578+ if constexpr (sizeof ...(args) > 0 ) {
579+ wasm::Val params[] = {makeVal (args)...};
580+ if (log) {
581+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
582+ printValues (params, sizeof ...(Args)) + " )" );
583+ }
584+ trap = func->call (params, nullptr );
585+ } else {
586+ if (log) {
587+ integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
588+ }
589+ trap = func->call (nullptr , nullptr );
590+ }
583591 if (trap) {
584592 fail (FailState::RuntimeError, getFailMessage (std::string (function_name), std::move (trap)));
585593 return ;
@@ -612,15 +620,23 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
612620 return ;
613621 }
614622 *function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
615- wasm::Val params[] = {makeVal (args)...};
616- wasm::Val results[1 ];
617623 const bool log = cmpLogLevel (LogLevel::trace);
618- if (log) {
619- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
620- printValues (params, sizeof ...(Args)) + " )" );
621- }
622624 SaveRestoreContext saved_context (context);
623- auto trap = func->call (params, results);
625+ wasm::Val results[1 ];
626+ wasm::own<wasm::Trap> trap = nullptr ;
627+ if constexpr (sizeof ...(args) > 0 ) {
628+ wasm::Val params[] = {makeVal (args)...};
629+ if (log) {
630+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
631+ printValues (params, sizeof ...(Args)) + " )" );
632+ }
633+ trap = func->call (params, results);
634+ } else {
635+ if (log) {
636+ integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
637+ }
638+ trap = func->call (nullptr , results);
639+ }
624640 if (trap) {
625641 fail (FailState::RuntimeError, getFailMessage (std::string (function_name), std::move (trap)));
626642 return R{};
0 commit comments