Skip to content

Commit cbaf7e7

Browse files
fix(bindgen): add remaining stream lift tests
1 parent 4ac95ac commit cbaf7e7

7 files changed

Lines changed: 365 additions & 138 deletions

File tree

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,10 +963,25 @@ impl LiftIntrinsic {
963963
Self::LiftFlatOwn => {
964964
let debug_log_fn = Intrinsic::DebugLog.name();
965965
let lift_flat_own_fn = self.name();
966-
output.push_str(&format!(r#"
967-
function {lift_flat_own_fn}(componentTableIdx, size, memory, vals, storagePtr, storageLen) {{
968-
{debug_log_fn}('[{lift_flat_own_fn}()] args', {{ size, memory, vals, storagePtr, storageLen }});
969-
throw new Error('flat lift for owned resources not yet implemented!');
966+
let lift_flat_u32_fn = Self::LiftFlatU32.name();
967+
968+
output.push_str(&format!(
969+
r#"
970+
function {lift_flat_own_fn}(meta) {{
971+
const {{ className, createResourceFn, componentIdx }} = meta;
972+
973+
return function {lift_flat_own_fn}Inner(ctx) {{
974+
{debug_log_fn}('[{lift_flat_own_fn}()] args', {{ ctx, className }});
975+
976+
if (ctx.componentIdx !== componentIdx) {{
977+
throw new Error('invalid component for resource lift');
978+
}}
979+
980+
const [handle, newCtx] = {lift_flat_u32_fn}(ctx);
981+
const resource = createResourceFn(handle);
982+
983+
return [resource, newCtx];
984+
}}
970985
}}
971986
"#
972987
));
@@ -978,7 +993,7 @@ impl LiftIntrinsic {
978993
output.push_str(&format!("
979994
function {lift_flat_borrow_fn}(componentTableIdx, size, memory, vals, storagePtr, storageLen) {{
980995
{debug_log_fn}('[{lift_flat_borrow_fn}()] args', {{ size, memory, vals, storagePtr, storageLen }});
981-
throw new Error('flat lift for borrowed resources not yet implemented!');
996+
throw new Error('flat lift for borrowed resources is not supported!');
982997
}}
983998
"));
984999
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,11 @@ impl Intrinsic {
563563
}} else {{
564564
let currentCount = count;
565565
let startPtr = this.#ptr;
566-
let liftCtx = {{ storagePtr: startPtr, memory: this.#memory }};
566+
let liftCtx = {{
567+
storagePtr: startPtr,
568+
memory: this.#memory,
569+
componentIdx: this.#componentIdx,
570+
}};
567571
if (currentCount < 0) {{ throw new Error('unexpectedly invalid count'); }}
568572
while (currentCount > 0) {{
569573
const [value, _ctx] = this.#elemMeta.liftFn(liftCtx);
@@ -600,6 +604,7 @@ impl Intrinsic {
600604
startPtr += this.#elemMeta.lowerFn({{
601605
memory: this.#memory,
602606
storagePtr: startPtr,
607+
componentIdx: this.#componentIdx,
603608
vals: [v],
604609
}});
605610
}}

crates/js-component-bindgen/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
21
use std::collections::HashSet;
32

43
use anyhow::{Context as _, Result, anyhow, bail, ensure};

0 commit comments

Comments
 (0)