Skip to content

Commit

Permalink
fix(test): correct expand tests for LongRefFromWasmAbi
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantamis committed Apr 25, 2024
1 parent e5ef4d5 commit 6d4dd09
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
21 changes: 20 additions & 1 deletion tests/expand/borrow.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const _: () = {
use wasm_bindgen::{
convert::{
FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi,
RefFromWasmAbi,
RefFromWasmAbi, LongRefFromWasmAbi,
},
describe::WasmDescribe, prelude::*,
};
Expand Down Expand Up @@ -243,6 +243,11 @@ const _: () = {
&self.0
}
}
impl<T> ::core::borrow::Borrow<T> for SelfOwner<T> {
fn borrow(&self) -> &T {
&self.0
}
}
impl<'a> RefFromWasmAbi for Borrow<'a>
where
Self: _serde::de::DeserializeOwned,
Expand All @@ -257,4 +262,18 @@ const _: () = {
SelfOwner(result.unwrap_throw())
}
}
impl<'a> LongRefFromWasmAbi for Borrow<'a>
where
Self: _serde::de::DeserializeOwned,
{
type Abi = <JsType as LongRefFromWasmAbi>::Abi;
type Anchor = SelfOwner<Self>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
let result = Self::from_js(&JsType::from_abi(js));
if let Err(err) = result {
wasm_bindgen::throw_str(err.to_string().as_ref());
}
SelfOwner(result.unwrap_throw())
}
}
};
21 changes: 20 additions & 1 deletion tests/expand/generic_enum.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const _: () = {
use wasm_bindgen::{
convert::{
FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi,
RefFromWasmAbi,
RefFromWasmAbi, LongRefFromWasmAbi,
},
describe::WasmDescribe, prelude::*,
};
Expand Down Expand Up @@ -249,6 +249,11 @@ const _: () = {
&self.0
}
}
impl<T> ::core::borrow::Borrow<T> for SelfOwner<T> {
fn borrow(&self) -> &T {
&self.0
}
}
impl<T, U> RefFromWasmAbi for GenericEnum<T, U>
where
Self: _serde::de::DeserializeOwned,
Expand All @@ -263,4 +268,18 @@ const _: () = {
SelfOwner(result.unwrap_throw())
}
}
impl<T, U> LongRefFromWasmAbi for GenericEnum<T, U>
where
Self: _serde::de::DeserializeOwned,
{
type Abi = <JsType as LongRefFromWasmAbi>::Abi;
type Anchor = SelfOwner<Self>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
let result = Self::from_js(&JsType::from_abi(js));
if let Err(err) = result {
wasm_bindgen::throw_str(err.to_string().as_ref());
}
SelfOwner(result.unwrap_throw())
}
}
};
42 changes: 40 additions & 2 deletions tests/expand/generic_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const _: () = {
use wasm_bindgen::{
convert::{
FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi,
RefFromWasmAbi,
RefFromWasmAbi, LongRefFromWasmAbi,
},
describe::WasmDescribe, prelude::*,
};
Expand Down Expand Up @@ -248,6 +248,11 @@ const _: () = {
&self.0
}
}
impl<T> ::core::borrow::Borrow<T> for SelfOwner<T> {
fn borrow(&self) -> &T {
&self.0
}
}
impl<T> RefFromWasmAbi for GenericStruct<T>
where
Self: _serde::de::DeserializeOwned,
Expand All @@ -262,6 +267,20 @@ const _: () = {
SelfOwner(result.unwrap_throw())
}
}
impl<T> LongRefFromWasmAbi for GenericStruct<T>
where
Self: _serde::de::DeserializeOwned,
{
type Abi = <JsType as LongRefFromWasmAbi>::Abi;
type Anchor = SelfOwner<Self>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
let result = Self::from_js(&JsType::from_abi(js));
if let Err(err) = result {
wasm_bindgen::throw_str(err.to_string().as_ref());
}
SelfOwner(result.unwrap_throw())
}
}
};
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct GenericNewtype<T>(T);
Expand All @@ -272,7 +291,7 @@ const _: () = {
use wasm_bindgen::{
convert::{
FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi,
RefFromWasmAbi,
RefFromWasmAbi, LongRefFromWasmAbi,
},
describe::WasmDescribe, prelude::*,
};
Expand Down Expand Up @@ -511,6 +530,11 @@ const _: () = {
&self.0
}
}
impl<T> ::core::borrow::Borrow<T> for SelfOwner<T> {
fn borrow(&self) -> &T {
&self.0
}
}
impl<T> RefFromWasmAbi for GenericNewtype<T>
where
Self: _serde::de::DeserializeOwned,
Expand All @@ -525,4 +549,18 @@ const _: () = {
SelfOwner(result.unwrap_throw())
}
}
impl<T> LongRefFromWasmAbi for GenericNewtype<T>
where
Self: _serde::de::DeserializeOwned,
{
type Abi = <JsType as LongRefFromWasmAbi>::Abi;
type Anchor = SelfOwner<Self>;
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor {
let result = Self::from_js(&JsType::from_abi(js));
if let Err(err) = result {
wasm_bindgen::throw_str(err.to_string().as_ref());
}
SelfOwner(result.unwrap_throw())
}
}
};

0 comments on commit 6d4dd09

Please sign in to comment.