Skip to content

Commit 8ef44c0

Browse files
fix(bindgen): list canon lower for special cased list<u8>
1 parent 2be9340 commit 8ef44c0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,13 +1124,17 @@ impl Bindgen for FunctionBindgen<'_> {
11241124
results.push(format!("enum{tmp}"));
11251125
}
11261126

1127-
// The ListCanonLower instruction is called on async function parameter lowers
1127+
// The ListCanonLower instruction is called on async function parameter lowers,
1128+
// which are separated in memory by one pointer follow.
11281129
//
11291130
// We ignore `realloc` in the instruction because it's the name of the *import* from the
11301131
// component's side (i.e. `"cabi_realloc"`). Bindings have already set up the appropriate
11311132
// realloc for the current component (e.g. `realloc0`) and it is available in the bindgen
11321133
// object @ `self.realloc`
11331134
//
1135+
// Note that this can be called *inside* a "regular" ListCanonLower, for example
1136+
// when a list of lists or list of Uint8Arrays is sent.
1137+
//
11341138
Instruction::ListCanonLower { element, .. } => {
11351139
let tmp = self.tmp();
11361140
let memory = self.memory.as_ref().unwrap();
@@ -1143,7 +1147,10 @@ impl Bindgen for FunctionBindgen<'_> {
11431147
// Alias the list to a local variable
11441148
uwriteln!(self.src, "var val{tmp} = {};", operands[0]);
11451149
if matches!(element, Type::U8) {
1146-
uwriteln!(self.src, "var len{tmp} = val{tmp}.byteLength;");
1150+
uwriteln!(
1151+
self.src,
1152+
"var len{tmp} = Array.isArray(val{tmp}) ? val{tmp}.length : val{tmp}.byteLength;"
1153+
);
11471154
} else {
11481155
uwriteln!(self.src, "var len{tmp} = val{tmp}.length;");
11491156
}

0 commit comments

Comments
 (0)