Skip to content

Commit 3d36b47

Browse files
authored
Merge pull request #39 from BuddhiLW/t300/cljw-component-invoke-handle
t300/cljw-component-invoke-handle
2 parents d4dae80 + 6086f2a commit 3d36b47

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/runtime/cljw/wasm/component.zig‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,11 @@ pub fn resourceDropFn(rt: *Runtime, env: *Env, args: []const Value, loc: SourceL
575575
/// holds a resource handle the component outlives the call, because the handle
576576
/// names something inside it. See the branch in the body.
577577
pub fn componentInvokeFn(rt: *Runtime, env: *Env, args: []const Value, loc: SourceLocation) anyerror!Value {
578-
_ = env;
579578
try error_catalog.checkArityMin("wasm/component-invoke", args, 2, loc);
579+
// A handle from `wasm/load-component` (or a resource handle from one) is
580+
// already open: invoke on it instead of refusing it as "not a path". Only
581+
// a path string takes the one-shot open-and-teardown route below.
582+
if (!args[0].isString()) return componentCallFn(rt, env, args, loc);
580583
if (!args[1].isString())
581584
return error_catalog.raise(.wasm_export_name_invalid, loc, .{});
582585
const bytes = try readComponentBytes(rt, args[0], loc);

‎test/e2e/fixtures/wasm/README_echo.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ Note the checked-in `echo.component.wasm` in ClojureWit is **older than its own
2323
`echo.wat`** (838 bytes, scalars only, built 2026-07-30 01:30 against a WAT last
2424
touched 05:12). Rebuild rather than copy.
2525

26-
## Why it does not run yet
26+
## Status: it loads and runs
2727

28-
cljw cannot load it, and neither can zwasm's own CLI — so the gap is
28+
The gap recorded below is FIXED. Measured 2026-10-08 on cljw v1.14.11: the
29+
16-export component loads with `wasm/load-component`, and `component-call`
30+
round-trips `echo-f64` (1.5 -> 1.5) and `echo-list-u32` ([1 2 3] -> [1 2 3]).
31+
The section below is kept as history, with its root cause.
32+
33+
## History: why it did not run (the >= 2-export InvalidSort gap, fixed)
34+
35+
cljw could not load it, and neither could zwasm's own CLI — so the gap is
2936
engine-side, not cljw-side. **`zwasm` rejects any component with two or more
3037
exports** with `InvalidSort`. Minimal reproduction, `two_export_component.wasm`
3138
in this directory: two scalar `s32`/`bool` echoes, nothing else.

‎test/e2e/fixtures/wasm_component_probe.clj‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,10 @@
102102
(catch Throwable _ "CAUGHT")))
103103

104104
(println "DONE")
105+
106+
;; --- happy: component-invoke also takes a load-component handle (it used to
107+
;; refuse it as "the module path must be a string") and reuses it ---
108+
(let [c (wasm/load-component greet)
109+
r (wasm/component-invoke c "greet" "handle")]
110+
(assert (= "Hello, handle!" r) (pr-str r))
111+
(println "PASS component-invoke-accepts-handle"))

‎test/e2e/phase16_wasm_component.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ for marker in \
2828
"PASS component-invoke-greet" \
2929
"PASS component-exports" \
3030
"PASS load-component-handle-reuse" \
31+
"PASS component-invoke-accepts-handle" \
3132
"PASS resource-chain" \
3233
"PASS one-shot-resource-outlives-call" \
3334
"PASS resource-handle-is-bound-to-its-component"; do

0 commit comments

Comments
 (0)