mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 05:21:24 +00:00
Communicate exceptions through global memory
Instead of allocating space on the stack and returning a pointer we should be able to use a single global memory location to communicate this error payload information. This shouldn't run into any reentrancy issues since it's only stored just before returning to wasm and it's always read just after returning from wasm.
This commit is contained in:
@ -974,28 +974,12 @@ impl TryToTokens for ast::ImportFunction {
|
||||
}
|
||||
|
||||
let mut exceptional_ret = quote!();
|
||||
let exn_data = if self.catch {
|
||||
let exn_data = Ident::new("exn_data", Span::call_site());
|
||||
let exn_data_ptr = Ident::new("exn_data_ptr", Span::call_site());
|
||||
abi_argument_names.push(exn_data_ptr.clone());
|
||||
abi_arguments.push(quote! { #exn_data_ptr: *mut u32 });
|
||||
if self.catch {
|
||||
convert_ret = quote! { Ok(#convert_ret) };
|
||||
exceptional_ret = quote! {
|
||||
if #exn_data[0] == 1 {
|
||||
return Err(
|
||||
<
|
||||
wasm_bindgen::JsValue as wasm_bindgen::convert::FromWasmAbi
|
||||
>::from_abi(#exn_data[1], &mut wasm_bindgen::convert::GlobalStack::new())
|
||||
)
|
||||
}
|
||||
wasm_bindgen::__rt::take_last_exception()?;
|
||||
};
|
||||
quote! {
|
||||
let mut #exn_data = [0; 2];
|
||||
let #exn_data_ptr = #exn_data.as_mut_ptr();
|
||||
}
|
||||
} else {
|
||||
quote!()
|
||||
};
|
||||
}
|
||||
|
||||
let rust_name = &self.rust_name;
|
||||
let import_name = &self.shim;
|
||||
@ -1055,7 +1039,6 @@ impl TryToTokens for ast::ImportFunction {
|
||||
#extern_fn
|
||||
|
||||
unsafe {
|
||||
#exn_data
|
||||
let #ret_ident = {
|
||||
let mut __stack = wasm_bindgen::convert::GlobalStack::new();
|
||||
#(#arg_conversions)*
|
||||
|
Reference in New Issue
Block a user