| 598 | |
| 599 | template <typename... Args> |
| 600 | void V8::getModuleFunctionImpl(std::string_view function_name, |
| 601 | std::function<void(ContextBase *, Args...)> *function) { |
| 602 | auto it = module_functions_.find(std::string(function_name)); |
| 603 | if (it == module_functions_.end()) { |
| 604 | *function = nullptr; |
| 605 | return; |
| 606 | } |
| 607 | const wasm::Func *func = it->second.get(); |
| 608 | auto arg_valtypes = convertArgsTupleToValTypes<std::tuple<Args...>>(); |
| 609 | auto result_valtypes = convertArgsTupleToValTypes<std::tuple<>>(); |
| 610 | if (!equalValTypes(func->type()->params(), arg_valtypes) || |
| 611 | !equalValTypes(func->type()->results(), result_valtypes)) { |
| 612 | fail(FailState::UnableToInitializeCode, |
| 613 | "Bad function signature for: " + std::string(function_name) + |
| 614 | ", want: " + printValTypes(arg_valtypes) + " -> " + printValTypes(result_valtypes) + |
| 615 | ", but the module exports: " + printValTypes(func->type()->params()) + " -> " + |
| 616 | printValTypes(func->type()->results())); |
| 617 | *function = nullptr; |
| 618 | return; |
| 619 | } |
| 620 | *function = [func, function_name, this](ContextBase *context, Args... args) -> void { |
| 621 | const bool log = cmpLogLevel(LogLevel::trace); |
| 622 | SaveRestoreContext saved_context(context); |
| 623 | wasm::own<wasm::Trap> trap = nullptr; |
| 624 | |
| 625 | // Workaround for MSVC++ not supporting zero-sized arrays. |
| 626 | if constexpr (sizeof...(args) > 0) { |
| 627 | wasm::Val params[] = {makeVal(args)...}; |
| 628 | if (log) { |
| 629 | integration()->trace("[host->vm] " + std::string(function_name) + "(" + |
| 630 | printValues(params, sizeof...(Args)) + ")"); |
| 631 | } |
| 632 | trap = func->call(params, nullptr); |
| 633 | } else { |
| 634 | if (log) { |
| 635 | integration()->trace("[host->vm] " + std::string(function_name) + "()"); |
| 636 | } |
| 637 | trap = func->call(nullptr, nullptr); |
| 638 | } |
| 639 | |
| 640 | if (trap) { |
| 641 | fail(FailState::RuntimeError, getFailMessage(std::string(function_name), std::move(trap))); |
| 642 | return; |
| 643 | } |
| 644 | if (log) { |
| 645 | integration()->trace("[host<-vm] " + std::string(function_name) + " return: void"); |
| 646 | } |
| 647 | }; |
| 648 | } |
| 649 | |
| 650 | template <typename R, typename... Args> |
| 651 | void V8::getModuleFunctionImpl(std::string_view function_name, |
nothing calls this directly
no test coverage detected