mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-16 06:21:22 +00:00
Implement readonly struct fields
Add support for `#[wasm_bindgen(readonly)]` which indicates that an exported struct field is readonly and attempting to set it in JS will throw an exception. Closes #151
This commit is contained in:
@ -247,6 +247,18 @@ impl ToTokens for ast::StructField {
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn #desc() {
|
||||
use wasm_bindgen::describe::*;
|
||||
<#ty as WasmDescribe>::describe();
|
||||
}
|
||||
}).to_tokens(tokens);
|
||||
|
||||
if self.opts.readonly() {
|
||||
return
|
||||
}
|
||||
|
||||
(quote! {
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn #setter(
|
||||
js: u32,
|
||||
@ -263,13 +275,6 @@ impl ToTokens for ast::StructField {
|
||||
);
|
||||
(*js).borrow_mut().#name = val;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn #desc() {
|
||||
use wasm_bindgen::describe::*;
|
||||
<#ty as WasmDescribe>::describe();
|
||||
|
||||
}
|
||||
}).to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user