Skip to content

Commit 4d2f80c

Browse files
GamePad64vados-cosmonic
authored andcommitted
fix(bindgen): treat undefined as none when lowering options
`_lowerFlatOption` mapped only JS `null` to the option `none` case, but jco's own generated TypeScript types model `option<T>` none as `T | undefined`. A value of `undefined` was therefore lowered as `some(undefined)`; when `T` contains an `own<resource>`, `_lowerFlatOwn` then throws `missing resource` and aborts the task. This surfaced with wasi:http p3 `response.consume-body`, whose trailers future is typed `Result<Trailers | undefined, ErrorCode>`: an empty-trailers `Ok(None)` (`{ tag: 'ok', val: undefined }`) crashed lowering at body completion, leaving the enclosing streaming result's `.next()` unresolved. Widen the none check to accept `undefined`, consistent with the generated types. Signed-off-by: Alexander Shishenko <alex@shishenko.com>
1 parent 1f19a07 commit 4d2f80c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • crates/js-component-bindgen/src/intrinsics

crates/js-component-bindgen/src/intrinsics/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ impl LowerIntrinsic {
918918
{debug_log_fn}('[{lower_flat_option_fn}()] args', {{ ctx }});
919919
920920
const v = ctx.vals[0];
921-
if (v === null) {{
921+
if (v === null || v === undefined) {{
922922
ctx.vals[0] = {{ tag: 'none' }};
923923
}} else {{
924924
const isNotOptionObject = typeof v !== 'object'

0 commit comments

Comments
 (0)