test unsafe-single-threaded-traits

This commit is contained in:
Guy Bedford 2025-10-30 14:20:35 -07:00
parent 8401dcc881
commit cc3090cbb0
7 changed files with 14 additions and 18 deletions

View File

@ -24,9 +24,9 @@ js-sys = { version = "0.3.82", path = "./wasm-bindgen/crates/js-sys" }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.140"
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = { version = "0.2.105", path = "./wasm-bindgen" }
wasm-bindgen = { version = "0.2.105", path = "./wasm-bindgen", features = ["unsafe-single-threaded-traits"] }
wasm-bindgen-cli-support = { version = "0.2.105", path = "./wasm-bindgen/crates/cli-support" }
wasm-bindgen-futures = { version = "0.4.54", path = "./wasm-bindgen/crates/futures" }
wasm-bindgen-futures = { version = "0.4.54", path = "./wasm-bindgen/crates/futures", features = ["unsafe-single-threaded-traits"] }
wasm-bindgen-macro-support = { version = "0.2.105", path = "./wasm-bindgen/crates/macro-support" }
wasm-bindgen-shared = { version = "0.2.105", path = "./wasm-bindgen/crates/shared" }
wasm-bindgen-test = { version = "0.3.50", path = "./wasm-bindgen/crates/test" }

View File

@ -22,20 +22,18 @@ mod sys {
pub trait Calculator {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u64>;
}
pub struct CalculatorService(::worker::send::SendWrapper<sys::CalculatorSys>);
pub struct CalculatorService(sys::CalculatorSys);
#[async_trait::async_trait]
impl Calculator for CalculatorService {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u32> {
let promise = self.0.add(a, b)?;
let fut = ::worker::send::SendFuture::new(
::worker::wasm_bindgen_futures::JsFuture::from(promise),
);
let fut = ::worker::wasm_bindgen_futures::JsFuture::from(promise);
let output = fut.await?;
Ok(::serde_wasm_bindgen::from_value(output)?)
}
}
impl From<::worker::Fetcher> for CalculatorService {
fn from(fetcher: ::worker::Fetcher) -> Self {
Self(::worker::send::SendWrapper::new(fetcher.into_rpc()))
Self(fetcher.into_rpc())
}
}

View File

@ -30,5 +30,5 @@ pub async fn handle_analytics_event(
.add_double(200)
.write_to(&dataset)?;
return Response::ok("Events sent");
Response::ok("Events sent")
}

View File

@ -11,11 +11,9 @@ pub async fn handle_socket_failed(
let socket = ConnectionBuilder::new().connect("127.0.0.1", 25000)?;
match socket.opened().await {
Ok(_) => {
return Err(Error::RustError(
"Socket should have failed to open.".to_owned(),
))
}
Ok(_) => Err(Error::RustError(
"Socket should have failed to open.".to_owned(),
)),
Err(e) => Response::ok(format!("{e:?}")),
}
}

@ -1 +1 @@
Subproject commit f72a9d68d90cd75513e18859403f0139cc6913a1
Subproject commit 6c77f4b85e3fde87b04189ac724ef130da4bdd05

View File

@ -85,7 +85,7 @@ fn expand_trait(interface: &Interface, interface_name: &Ident) -> anyhow::Result
fn expand_struct(struct_name: &Ident, sys_name: &Ident) -> anyhow::Result<syn::ItemStruct> {
let struct_raw = quote!(
pub struct #struct_name(::worker::send::SendWrapper<sys::#sys_name>);
pub struct #struct_name(sys::#sys_name);
);
let struct_item: syn::ItemStruct = syn::parse2(struct_raw)?;
Ok(struct_item)
@ -95,7 +95,7 @@ fn expand_from_impl(struct_name: &Ident, from_type: &syn::Type) -> anyhow::Resul
let impl_raw = quote!(
impl From<#from_type> for #struct_name {
fn from(fetcher: #from_type) -> Self {
Self(::worker::send::SendWrapper::new(fetcher.into_rpc()))
Self(fetcher.into_rpc())
}
}
);
@ -144,7 +144,7 @@ fn expand_rpc_impl(
let method_raw = quote!(
async fn #ident(&self) -> ::worker::Result<#ret_type> {
let promise = #invocation_item?;
let fut = ::worker::send::SendFuture::new(::worker::wasm_bindgen_futures::JsFuture::from(promise));
let fut = ::worker::wasm_bindgen_futures::JsFuture::from(promise);
let output = fut.await?;
Ok(::serde_wasm_bindgen::from_value(output)?)
}

View File

@ -462,7 +462,7 @@ async fn fetch_with_request_raw(request: crate::Request) -> Result<web_sys::Resp
let req = request.inner();
let fut = {
let worker: web_sys::WorkerGlobalScope = js_sys::global().unchecked_into();
crate::send::SendFuture::new(JsFuture::from(worker.fetch_with_request(req)))
JsFuture::from(worker.fetch_with_request(req))
};
let resp = fut.await?;
Ok(resp.dyn_into()?)