chore: narrow wasm backend entrypoint API

This commit is contained in:
udo
2026-06-13 22:32:02 +00:00
parent af6500d134
commit b1856c1725
4 changed files with 22 additions and 63 deletions
+7 -18
View File
@@ -487,43 +487,32 @@ public:
// provided, reports whether the unit actually exports that handler — the
// caller maps a missing render to an empty body (native parity) and a
// missing cli/serve handler to a 404.
String invoke_entry(const String& entry_source_path, int32_t kind, bool* handler_present = 0,
const String& handler_name = "")
String invoke_entry(const String& entry_source_path, int32_t kind, bool* handler_present = 0)
{
entry_dir = dir_of(entry_source_path);
size_t unit_index = 0;
String error = load_unit(entry_source_path, unit_index);
if(error != "")
return(error);
// Base handler export for the kind, plus the named suffix (serve_http /
// render / component can route to a named entry, e.g. __uce_serve_http_x).
String symbol = kind == RESOLVE_CLI ? "__uce_cli"
: kind == RESOLVE_WEBSOCKET ? "__uce_websocket"
: kind == RESOLVE_SERVE_HTTP ? "__uce_serve_http"
: "__uce_render";
if(handler_name != "")
symbol += "_" + sanitize_symbol_suffix(handler_name);
String symbol = kind == RESOLVE_CLI ? "__uce_cli" : "__uce_render";
bool present = (bool)unit_func(unit_index, symbol);
if(handler_present)
*handler_present = present;
if(!present)
return("");
// The core parses a "path:name" target into the named suffix; the bare
// path above loaded the module, this drives the handler resolution.
String target = handler_name == "" ? entry_source_path : entry_source_path + ":" + handler_name;
// Invoke through the core so the entry gets the same ONCE() + dispatch
// path as components (unit is pre-loaded above; resolution is cached).
auto entry = core_func("uce_wasm_invoke_entry");
if(!entry)
return("core does not export uce_wasm_invoke_entry");
int32_t guest_ptr = 0;
error = call_core("uce_alloc", { (int32_t)target.size() }, &guest_ptr);
error = call_core("uce_alloc", { (int32_t)entry_source_path.size() }, &guest_ptr);
if(error != "" || guest_ptr == 0)
return(error == "" ? String("guest uce_alloc failed for entry path") : error);
error = guest_write((u32)guest_ptr, target);
error = guest_write((u32)guest_ptr, entry_source_path);
if(error != "")
return(error);
auto result = entry->call(ctx(), { wasmtime::Val(guest_ptr), wasmtime::Val((int32_t)target.size()), wasmtime::Val(kind) });
auto result = entry->call(ctx(), { wasmtime::Val(guest_ptr), wasmtime::Val((int32_t)entry_source_path.size()), wasmtime::Val(kind) });
call_core("uce_free", { guest_ptr }, 0);
if(!result)
return(trap_text(result.err()));
@@ -1765,7 +1754,7 @@ private:
// ---- public entry: one request through one workspace -----------------------
inline WasmResponse wasm_worker_serve(WasmWorker& worker, const DValue& context_tree, const String& entry_source_path,
int32_t kind = WasmWorkspace::RESOLVE_RENDER, const String& handler_name = "")
int32_t kind = WasmWorkspace::RESOLVE_RENDER)
{
WasmResponse response;
WasmWorkspace workspace(worker);
@@ -1776,7 +1765,7 @@ inline WasmResponse wasm_worker_serve(WasmWorker& worker, const DValue& context_
if(error == "")
error = workspace.apply_context(context_tree);
if(error == "")
error = workspace.invoke_entry(entry_source_path, kind, &response.handler_present, handler_name);
error = workspace.invoke_entry(entry_source_path, kind, &response.handler_present);
if(error == "")
error = workspace.collect(response);
response.workspace_birth_us = workspace.workspace_birth_us;