API exported to guest WebAssembly code.
| 189 | |
| 190 | /// API exported to guest WebAssembly code. |
| 191 | WasmHostFunction getHostFunction(std::string_view function_name) |
| 192 | { |
| 193 | static const std::array exported_functions{ |
| 194 | makeHostFunction("clickhouse_server_version", wasmExportServerVer), |
| 195 | makeHostFunction("clickhouse_throw", wasmExportThrow), |
| 196 | makeHostFunction("clickhouse_log", wasmExportLog), |
| 197 | makeHostFunction("clickhouse_random", wasmExportRandom), |
| 198 | /// Mandatory import for any AssemblyScript module that uses runtime checks |
| 199 | /// (memory allocation, bounds checks, etc). Linked only when the module |
| 200 | /// declares `(import "env" "abort" (func ...))`, so non-AS modules are unaffected. |
| 201 | makeHostFunction("abort", wasmExportAssemblyScriptAbort), |
| 202 | }; |
| 203 | |
| 204 | for (const auto & function : exported_functions) |
| 205 | { |
| 206 | if (function.getFunctionDeclaration().getName() == function_name) |
| 207 | return function; |
| 208 | } |
| 209 | |
| 210 | throw Exception(ErrorCodes::RESOURCE_NOT_FOUND, "Unknown WebAssembly host function '{}'", function_name); |
| 211 | } |
| 212 | |
| 213 | } |
no test coverage detected