Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion odra-wasm-client-builder/src/codegen/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn getter_code(member: &StructMember) -> proc_macro2::TokenStream {
quote::quote! {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Contextual Comment]
This comment refers to code near real line 266. Anchored to nearest_changed(270) line 270.


P1 | Confidence: High

  • This is a potentially breaking change to the public API of generated WebAssembly client code. The method IntoWasmValue::into_odra_value is replaced by IntoWasmValue::to_wasm_value, which likely have different signatures or return types, causing compilation errors or runtime type mismatches for downstream code.
  • Speculative: The change introduces an unnecessary .clone() operation on self.#ident. If the field's type does not implement Copy, this could lead to expensive, avoidable clones, impacting performance.

Code Suggestion:

If a reference-taking method exists (e.g., `fn as_wasm_value(&self) -> #ty`), the code should use it:
odra_wasm_client::types::IntoWasmValue::as_wasm_value(&self.#ident)
Otherwise, the trait should be extended, or the clone may be necessary but should be documented as such.

Evidence: symbol:IntoWasmValue, method:to_wasm_value, method:into_odra_value

#[wasm_bindgen(getter)]
pub fn #ident(&self) -> #ty {
odra_wasm_client::types::IntoWasmValue::into_odra_value(self.#ident.clone())
odra_wasm_client::types::IntoWasmValue::to_wasm_value(self.#ident.clone())
}
}
}
Expand Down Expand Up @@ -314,4 +314,38 @@ mod test {
let expected = parse_quote!(#[wasm_bindgen(js_name = "testFieldRustStyle")] pub test_field_rust_style: String);
pretty_assertions::assert_eq!(tokens, expected);
}

#[test]
fn test_getter_code() {
let field = StructMember {
name: "test".to_string(),
description: None,
ty: Type(NamedCLType::U128)
};
let tokens = getter_code(&field);
let expected = quote::quote!(
#[wasm_bindgen(getter)]
pub fn test(&self) -> odra_wasm_client::types::U128 {
odra_wasm_client::types::IntoWasmValue::to_wasm_value(self.test.clone())
}
);
pretty_assertions::assert_eq!(tokens.to_string(), expected.to_string());
}

#[test]
fn test_setter_code() {
let field = StructMember {
name: "test".to_string(),
description: None,
ty: Type(NamedCLType::U128)
};
let tokens = setter_code(&field);
let expected = quote::quote!(
#[wasm_bindgen(setter)]
pub fn set_test(&mut self, value: odra_wasm_client::types::U128) {
self.test = odra_wasm_client::types::IntoOdraValue::into_odra_value(value).unwrap();
}
);
pretty_assertions::assert_eq!(tokens.to_string(), expected.to_string());
}
}