MCPcopy Create free account
hub / github.com/apache/trafficserver / getModuleFunctionImpl

Method getModuleFunctionImpl

plugins/experimental/wasm/lib/src/v8/v8.cc:600–648  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

598
599template <typename... Args>
600void 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
650template <typename R, typename... Args>
651void V8::getModuleFunctionImpl(std::string_view function_name,

Callers

nothing calls this directly

Calls 13

stringClass · 0.85
getFailMessageFunction · 0.85
traceMethod · 0.80
equalValTypesFunction · 0.70
printValTypesFunction · 0.70
makeValFunction · 0.70
printValuesFunction · 0.70
to_stringClass · 0.50
findMethod · 0.45
endMethod · 0.45
getMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected