Remove the long-defunkt Stack trait

This was used oh-so-long ago but hasn't been used in a very long time
since then. It's served no purpose for a very long time now and I don't
think we have a plan for giving it a purpose any time soon, so let's
remove it.
This commit is contained in:
Alex Crichton 2019-06-25 05:08:50 -07:00
parent d9e53ac2f6
commit a021a967b2
7 changed files with 138 additions and 226 deletions

View File

@ -166,9 +166,7 @@ impl ToTokens for ast::Struct {
impl wasm_bindgen::convert::IntoWasmAbi for #name { impl wasm_bindgen::convert::IntoWasmAbi for #name {
type Abi = u32; type Abi = u32;
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) fn into_abi(self) -> u32 {
-> u32
{
use wasm_bindgen::__rt::std::boxed::Box; use wasm_bindgen::__rt::std::boxed::Box;
use wasm_bindgen::__rt::WasmRefCell; use wasm_bindgen::__rt::WasmRefCell;
Box::into_raw(Box::new(WasmRefCell::new(self))) as u32 Box::into_raw(Box::new(WasmRefCell::new(self))) as u32
@ -179,9 +177,7 @@ impl ToTokens for ast::Struct {
impl wasm_bindgen::convert::FromWasmAbi for #name { impl wasm_bindgen::convert::FromWasmAbi for #name {
type Abi = u32; type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut dyn wasm_bindgen::convert::Stack) unsafe fn from_abi(js: u32) -> Self {
-> Self
{
use wasm_bindgen::__rt::std::boxed::Box; use wasm_bindgen::__rt::std::boxed::Box;
use wasm_bindgen::__rt::{assert_not_null, WasmRefCell}; use wasm_bindgen::__rt::{assert_not_null, WasmRefCell};
@ -198,10 +194,7 @@ impl ToTokens for ast::Struct {
wasm_bindgen::JsValue wasm_bindgen::JsValue
{ {
fn from(value: #name) -> Self { fn from(value: #name) -> Self {
let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi( let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi(value);
value,
unsafe { &mut wasm_bindgen::convert::GlobalStack::new() },
);
#[link(wasm_import_module = "__wbindgen_placeholder__")] #[link(wasm_import_module = "__wbindgen_placeholder__")]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
@ -216,10 +209,7 @@ impl ToTokens for ast::Struct {
unsafe { unsafe {
<wasm_bindgen::JsValue as wasm_bindgen::convert::FromWasmAbi> <wasm_bindgen::JsValue as wasm_bindgen::convert::FromWasmAbi>
::from_abi( ::from_abi(#new_fn(ptr))
#new_fn(ptr),
&mut wasm_bindgen::convert::GlobalStack::new(),
)
} }
} }
} }
@ -229,10 +219,7 @@ impl ToTokens for ast::Struct {
#[doc(hidden)] #[doc(hidden)]
#[allow(clippy::all)] #[allow(clippy::all)]
pub unsafe extern "C" fn #free_fn(ptr: u32) { pub unsafe extern "C" fn #free_fn(ptr: u32) {
<#name as wasm_bindgen::convert::FromWasmAbi>::from_abi( <#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr);
ptr,
&mut wasm_bindgen::convert::GlobalStack::new(),
);
} }
#[allow(clippy::all)] #[allow(clippy::all)]
@ -240,10 +227,7 @@ impl ToTokens for ast::Struct {
type Abi = u32; type Abi = u32;
type Anchor = wasm_bindgen::__rt::Ref<'static, #name>; type Anchor = wasm_bindgen::__rt::Ref<'static, #name>;
unsafe fn ref_from_abi( unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
js: Self::Abi,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
wasm_bindgen::__rt::assert_not_null(js); wasm_bindgen::__rt::assert_not_null(js);
(*js).borrow() (*js).borrow()
@ -255,10 +239,7 @@ impl ToTokens for ast::Struct {
type Abi = u32; type Abi = u32;
type Anchor = wasm_bindgen::__rt::RefMut<'static, #name>; type Anchor = wasm_bindgen::__rt::RefMut<'static, #name>;
unsafe fn ref_mut_from_abi( unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor {
js: Self::Abi,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self::Anchor {
let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>;
wasm_bindgen::__rt::assert_not_null(js); wasm_bindgen::__rt::assert_not_null(js);
(*js).borrow_mut() (*js).borrow_mut()
@ -302,7 +283,7 @@ impl ToTokens for ast::StructField {
-> <#ty as wasm_bindgen::convert::IntoWasmAbi>::Abi -> <#ty as wasm_bindgen::convert::IntoWasmAbi>::Abi
{ {
use wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; use wasm_bindgen::__rt::{WasmRefCell, assert_not_null};
use wasm_bindgen::convert::{GlobalStack, IntoWasmAbi}; use wasm_bindgen::convert::IntoWasmAbi;
fn assert_copy<T: Copy>(){} fn assert_copy<T: Copy>(){}
#assert_copy; #assert_copy;
@ -310,10 +291,7 @@ impl ToTokens for ast::StructField {
let js = js as *mut WasmRefCell<#struct_name>; let js = js as *mut WasmRefCell<#struct_name>;
assert_not_null(js); assert_not_null(js);
let val = (*js).borrow().#name; let val = (*js).borrow().#name;
<#ty as IntoWasmAbi>::into_abi( <#ty as IntoWasmAbi>::into_abi(val)
val,
&mut GlobalStack::new(),
)
} }
}) })
.to_tokens(tokens); .to_tokens(tokens);
@ -340,14 +318,11 @@ impl ToTokens for ast::StructField {
val: <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi, val: <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi,
) { ) {
use wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; use wasm_bindgen::__rt::{WasmRefCell, assert_not_null};
use wasm_bindgen::convert::{GlobalStack, FromWasmAbi}; use wasm_bindgen::convert::FromWasmAbi;
let js = js as *mut WasmRefCell<#struct_name>; let js = js as *mut WasmRefCell<#struct_name>;
assert_not_null(js); assert_not_null(js);
let val = <#ty as FromWasmAbi>::from_abi( let val = <#ty as FromWasmAbi>::from_abi(val);
val,
&mut GlobalStack::new(),
);
(*js).borrow_mut().#name = val; (*js).borrow_mut().#name = val;
} }
}) })
@ -377,10 +352,7 @@ impl TryToTokens for ast::Export {
let class = self.rust_class.as_ref().unwrap(); let class = self.rust_class.as_ref().unwrap();
arg_conversions.push(quote! { arg_conversions.push(quote! {
let me = unsafe { let me = unsafe {
<#class as wasm_bindgen::convert::FromWasmAbi>::from_abi( <#class as wasm_bindgen::convert::FromWasmAbi>::from_abi(me)
me,
&mut wasm_bindgen::convert::GlobalStack::new(),
)
}; };
}); });
quote! { me.#name } quote! { me.#name }
@ -390,10 +362,7 @@ impl TryToTokens for ast::Export {
arg_conversions.push(quote! { arg_conversions.push(quote! {
let mut me = unsafe { let mut me = unsafe {
<#class as wasm_bindgen::convert::RefMutFromWasmAbi> <#class as wasm_bindgen::convert::RefMutFromWasmAbi>
::ref_mut_from_abi( ::ref_mut_from_abi(me)
me,
&mut wasm_bindgen::convert::GlobalStack::new(),
)
}; };
let me = &mut *me; let me = &mut *me;
}); });
@ -404,10 +373,7 @@ impl TryToTokens for ast::Export {
arg_conversions.push(quote! { arg_conversions.push(quote! {
let me = unsafe { let me = unsafe {
<#class as wasm_bindgen::convert::RefFromWasmAbi> <#class as wasm_bindgen::convert::RefFromWasmAbi>
::ref_from_abi( ::ref_from_abi(me)
me,
&mut wasm_bindgen::convert::GlobalStack::new(),
)
}; };
let me = &*me; let me = &*me;
}); });
@ -434,7 +400,7 @@ impl TryToTokens for ast::Export {
arg_conversions.push(quote! { arg_conversions.push(quote! {
let mut #ident = unsafe { let mut #ident = unsafe {
<#elem as wasm_bindgen::convert::RefMutFromWasmAbi> <#elem as wasm_bindgen::convert::RefMutFromWasmAbi>
::ref_mut_from_abi(#ident, &mut __stack) ::ref_mut_from_abi(#ident)
}; };
let #ident = &mut *#ident; let #ident = &mut *#ident;
}); });
@ -446,7 +412,7 @@ impl TryToTokens for ast::Export {
arg_conversions.push(quote! { arg_conversions.push(quote! {
let #ident = unsafe { let #ident = unsafe {
<#elem as wasm_bindgen::convert::RefFromWasmAbi> <#elem as wasm_bindgen::convert::RefFromWasmAbi>
::ref_from_abi(#ident, &mut __stack) ::ref_from_abi(#ident)
}; };
let #ident = &*#ident; let #ident = &*#ident;
}); });
@ -458,7 +424,7 @@ impl TryToTokens for ast::Export {
arg_conversions.push(quote! { arg_conversions.push(quote! {
let #ident = unsafe { let #ident = unsafe {
<#ty as wasm_bindgen::convert::FromWasmAbi> <#ty as wasm_bindgen::convert::FromWasmAbi>
::from_abi(#ident, &mut __stack) ::from_abi(#ident)
}; };
}); });
} }
@ -478,9 +444,7 @@ impl TryToTokens for ast::Export {
}; };
let convert_ret = quote! { let convert_ret = quote! {
<#syn_ret as wasm_bindgen::convert::ReturnWasmAbi> <#syn_ret as wasm_bindgen::convert::ReturnWasmAbi>
::return_abi(#ret, &mut unsafe { ::return_abi(#ret)
wasm_bindgen::convert::GlobalStack::new()
})
}; };
let describe_ret = quote! { let describe_ret = quote! {
<#syn_ret as WasmDescribe>::describe(); <#syn_ret as WasmDescribe>::describe();
@ -509,9 +473,6 @@ impl TryToTokens for ast::Export {
// function to ensure that `#convert_ret`, if it panics, doesn't // function to ensure that `#convert_ret`, if it panics, doesn't
// leak anything. // leak anything.
let #ret = { let #ret = {
let mut __stack = unsafe {
wasm_bindgen::convert::GlobalStack::new()
};
#(#arg_conversions)* #(#arg_conversions)*
#receiver(#(#converted_arguments),*) #receiver(#(#converted_arguments),*)
}; };
@ -611,7 +572,7 @@ impl ToTokens for ast::ImportType {
#[allow(bad_style)] #[allow(bad_style)]
#[allow(clippy::all)] #[allow(clippy::all)]
const #const_name: () = { const #const_name: () = {
use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi, Stack}; use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi};
use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi};
use wasm_bindgen::convert::RefFromWasmAbi; use wasm_bindgen::convert::RefFromWasmAbi;
use wasm_bindgen::describe::WasmDescribe; use wasm_bindgen::describe::WasmDescribe;
@ -637,8 +598,8 @@ impl ToTokens for ast::ImportType {
type Abi = <JsValue as IntoWasmAbi>::Abi; type Abi = <JsValue as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.obj.into_abi(extra) self.obj.into_abi()
} }
} }
@ -656,9 +617,9 @@ impl ToTokens for ast::ImportType {
type Abi = <JsValue as FromWasmAbi>::Abi; type Abi = <JsValue as FromWasmAbi>::Abi;
#[inline] #[inline]
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: Self::Abi) -> Self {
#rust_name { #rust_name {
obj: JsValue::from_abi(js, extra).into(), obj: JsValue::from_abi(js).into(),
} }
} }
} }
@ -672,8 +633,8 @@ impl ToTokens for ast::ImportType {
type Abi = <&'a JsValue as IntoWasmAbi>::Abi; type Abi = <&'a JsValue as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
(&self.obj).into_abi(extra) (&self.obj).into_abi()
} }
} }
@ -682,8 +643,8 @@ impl ToTokens for ast::ImportType {
type Anchor = core::mem::ManuallyDrop<#rust_name>; type Anchor = core::mem::ManuallyDrop<#rust_name>;
#[inline] #[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra); let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js);
core::mem::ManuallyDrop::new(#rust_name { core::mem::ManuallyDrop::new(#rust_name {
obj: core::mem::ManuallyDrop::into_inner(tmp).into(), obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
}) })
@ -728,7 +689,7 @@ impl ToTokens for ast::ImportType {
panic!("cannot check instanceof on non-wasm targets"); panic!("cannot check instanceof on non-wasm targets");
} }
unsafe { unsafe {
let idx = val.into_abi(&mut wasm_bindgen::convert::GlobalStack::new()); let idx = val.into_abi();
#instanceof_shim(idx) != 0 #instanceof_shim(idx) != 0
} }
} }
@ -843,8 +804,8 @@ impl ToTokens for ast::ImportEnum {
wasm_bindgen::convert::IntoWasmAbi>::Abi; wasm_bindgen::convert::IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn wasm_bindgen::convert::Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
wasm_bindgen::JsValue::from(self).into_abi(extra) wasm_bindgen::JsValue::from(self).into_abi()
} }
} }
@ -853,11 +814,8 @@ impl ToTokens for ast::ImportEnum {
type Abi = <wasm_bindgen::JsValue as type Abi = <wasm_bindgen::JsValue as
wasm_bindgen::convert::FromWasmAbi>::Abi; wasm_bindgen::convert::FromWasmAbi>::Abi;
unsafe fn from_abi( unsafe fn from_abi(js: Self::Abi) -> Self {
js: Self::Abi, #name::from_js_value(&wasm_bindgen::JsValue::from_abi(js)).unwrap_or(#name::__Nonexhaustive)
extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self {
#name::from_js_value(&wasm_bindgen::JsValue::from_abi(js, extra)).unwrap_or(#name::__Nonexhaustive)
} }
} }
@ -943,7 +901,7 @@ impl TryToTokens for ast::ImportFunction {
}; };
arg_conversions.push(quote! { arg_conversions.push(quote! {
let #name = <#ty as wasm_bindgen::convert::IntoWasmAbi> let #name = <#ty as wasm_bindgen::convert::IntoWasmAbi>
::into_abi(#var, &mut __stack); ::into_abi(#var);
}); });
} }
let abi_ret; let abi_ret;
@ -961,10 +919,7 @@ impl TryToTokens for ast::ImportFunction {
}; };
convert_ret = quote! { convert_ret = quote! {
<#ty as wasm_bindgen::convert::FromWasmAbi> <#ty as wasm_bindgen::convert::FromWasmAbi>
::from_abi( ::from_abi(#ret_ident)
#ret_ident,
&mut wasm_bindgen::convert::GlobalStack::new(),
)
}; };
} }
None => { None => {
@ -1040,7 +995,6 @@ impl TryToTokens for ast::ImportFunction {
unsafe { unsafe {
let #ret_ident = { let #ret_ident = {
let mut __stack = wasm_bindgen::convert::GlobalStack::new();
#(#arg_conversions)* #(#arg_conversions)*
#import_name(#(#abi_argument_names),*) #import_name(#(#abi_argument_names),*)
}; };
@ -1115,7 +1069,7 @@ impl ToTokens for ast::Enum {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 { fn into_abi(self) -> u32 {
self as u32 self as u32
} }
} }
@ -1125,10 +1079,7 @@ impl ToTokens for ast::Enum {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
unsafe fn from_abi( unsafe fn from_abi(js: u32) -> Self {
js: u32,
_extra: &mut dyn wasm_bindgen::convert::Stack,
) -> Self {
#(#cast_clauses else)* { #(#cast_clauses else)* {
wasm_bindgen::throw_str("invalid enum value passed") wasm_bindgen::throw_str("invalid enum value passed")
} }
@ -1182,11 +1133,7 @@ impl ToTokens for ast::ImportStatic {
} }
unsafe { unsafe {
<#ty as wasm_bindgen::convert::FromWasmAbi>::from_abi( <#ty as wasm_bindgen::convert::FromWasmAbi>::from_abi(#shim_name())
#shim_name(),
&mut wasm_bindgen::convert::GlobalStack::new(),
)
} }
} }
thread_local!(static _VAL: #ty = init();); thread_local!(static _VAL: #ty = init(););
@ -1338,24 +1285,24 @@ impl ToTokens for ast::Dictionary {
impl IntoWasmAbi for #name { impl IntoWasmAbi for #name {
type Abi = <Object as IntoWasmAbi>::Abi; type Abi = <Object as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.obj.into_abi(extra) self.obj.into_abi()
} }
} }
impl<'a> IntoWasmAbi for &'a #name { impl<'a> IntoWasmAbi for &'a #name {
type Abi = <&'a Object as IntoWasmAbi>::Abi; type Abi = <&'a Object as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
(&self.obj).into_abi(extra) (&self.obj).into_abi()
} }
} }
impl FromWasmAbi for #name { impl FromWasmAbi for #name {
type Abi = <Object as FromWasmAbi>::Abi; type Abi = <Object as FromWasmAbi>::Abi;
#[inline] #[inline]
unsafe fn from_abi(abi: Self::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(abi: Self::Abi) -> Self {
#name { obj: Object::from_abi(abi, extra) } #name { obj: Object::from_abi(abi) }
} }
} }
@ -1377,8 +1324,8 @@ impl ToTokens for ast::Dictionary {
type Anchor = ManuallyDrop<#name>; type Anchor = ManuallyDrop<#name>;
#[inline] #[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
let tmp = <Object as RefFromWasmAbi>::ref_from_abi(js, extra); let tmp = <Object as RefFromWasmAbi>::ref_from_abi(js);
ManuallyDrop::new(#name { ManuallyDrop::new(#name {
obj: ManuallyDrop::into_inner(tmp), obj: ManuallyDrop::into_inner(tmp),
}) })

View File

@ -475,8 +475,8 @@ where
{ {
type Abi = u32; type Abi = u32;
fn into_abi(self, extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
(&*self.js).into_abi(extra) (&*self.js).into_abi()
} }
} }
@ -561,13 +561,12 @@ macro_rules! doit {
let ret = { let ret = {
let f: *const dyn Fn($($var),*) -> R = let f: *const dyn Fn($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr; FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new();
$( $(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); let $var = <$var as FromWasmAbi>::from_abi($var);
)* )*
(*f)($($var),*) (*f)($($var),*)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
inform(invoke::<$($var,)* R> as u32); inform(invoke::<$($var,)* R> as u32);
@ -615,13 +614,12 @@ macro_rules! doit {
let f: *const dyn FnMut($($var),*) -> R = let f: *const dyn FnMut($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr; FatPtr { fields: (a, b) }.ptr;
let f = f as *mut dyn FnMut($($var),*) -> R; let f = f as *mut dyn FnMut($($var),*) -> R;
let mut _stack = GlobalStack::new();
$( $(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); let $var = <$var as FromWasmAbi>::from_abi($var);
)* )*
(*f)($($var),*) (*f)($($var),*)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
inform(invoke::<$($var,)* R> as u32); inform(invoke::<$($var,)* R> as u32);
@ -734,11 +732,10 @@ unsafe impl<A, R> WasmClosure for dyn Fn(&A) -> R
let ret = { let ret = {
let f: *const dyn Fn(&A) -> R = let f: *const dyn Fn(&A) -> R =
FatPtr { fields: (a, b) }.ptr; FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new(); let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
(*f)(&*arg) (*f)(&*arg)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
inform(invoke::<A, R> as u32); inform(invoke::<A, R> as u32);
@ -782,11 +779,10 @@ unsafe impl<A, R> WasmClosure for dyn FnMut(&A) -> R
let f: *const dyn FnMut(&A) -> R = let f: *const dyn FnMut(&A) -> R =
FatPtr { fields: (a, b) }.ptr; FatPtr { fields: (a, b) }.ptr;
let f = f as *mut dyn FnMut(&A) -> R; let f = f as *mut dyn FnMut(&A) -> R;
let mut _stack = GlobalStack::new(); let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
(*f)(&*arg) (*f)(&*arg)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
inform(invoke::<A, R> as u32); inform(invoke::<A, R> as u32);

View File

@ -2,7 +2,7 @@ use core::mem;
use crate::convert::slices::WasmSlice; use crate::convert::slices::WasmSlice;
use crate::convert::RefFromWasmAbi; use crate::convert::RefFromWasmAbi;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack}; use crate::convert::{FromWasmAbi, IntoWasmAbi, ReturnWasmAbi};
use crate::describe::{inform, WasmDescribe, FUNCTION}; use crate::describe::{inform, WasmDescribe, FUNCTION};
use crate::throw_str; use crate::throw_str;
@ -14,7 +14,7 @@ macro_rules! stack_closures {
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 } WasmSlice { ptr: a as u32, len: b as u32 }
@ -35,13 +35,12 @@ macro_rules! stack_closures {
// ensure they're all destroyed as `return_abi` may throw // ensure they're all destroyed as `return_abi` may throw
let ret = { let ret = {
let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b)); let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$( $(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); let $var = <$var as FromWasmAbi>::from_abi($var);
)* )*
f($($var),*) f($($var),*)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a
@ -63,7 +62,7 @@ macro_rules! stack_closures {
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 } WasmSlice { ptr: a as u32, len: b as u32 }
@ -84,13 +83,12 @@ macro_rules! stack_closures {
// ensure they're all destroyed as `return_abi` may throw // ensure they're all destroyed as `return_abi` may throw
let ret = { let ret = {
let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b)); let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$( $(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); let $var = <$var as FromWasmAbi>::from_abi($var);
)* )*
f($($var),*) f($($var),*)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a
@ -127,7 +125,7 @@ where
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { WasmSlice {
@ -151,11 +149,10 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// ensure they're all destroyed as `return_abi` may throw // ensure they're all destroyed as `return_abi` may throw
let ret = { let ret = {
let f: &dyn Fn(&A) -> R = mem::transmute((a, b)); let f: &dyn Fn(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new(); let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
f(&*arg) f(&*arg)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a
@ -179,7 +176,7 @@ where
{ {
type Abi = WasmSlice; type Abi = WasmSlice;
fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
unsafe { unsafe {
let (a, b): (usize, usize) = mem::transmute(self); let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { WasmSlice {
@ -203,11 +200,10 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// ensure they're all destroyed as `return_abi` may throw // ensure they're all destroyed as `return_abi` may throw
let ret = { let ret = {
let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b)); let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new(); let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
f(&*arg) f(&*arg)
}; };
ret.return_abi(&mut GlobalStack::new()) ret.return_abi()
} }
impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a

View File

@ -2,7 +2,7 @@ use core::char;
use core::mem::{self, ManuallyDrop}; use core::mem::{self, ManuallyDrop};
use crate::convert::traits::WasmAbi; use crate::convert::traits::WasmAbi;
use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, Stack}; use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi};
use crate::convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi}; use crate::convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi};
use crate::{Clamped, JsValue}; use crate::{Clamped, JsValue};
@ -64,21 +64,21 @@ macro_rules! type_wasm_native {
type Abi = $c; type Abi = $c;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> $c { self as $c } fn into_abi(self) -> $c { self as $c }
} }
impl FromWasmAbi for $t { impl FromWasmAbi for $t {
type Abi = $c; type Abi = $c;
#[inline] #[inline]
unsafe fn from_abi(js: $c, _extra: &mut dyn Stack) -> Self { js as $t } unsafe fn from_abi(js: $c) -> Self { js as $t }
} }
impl IntoWasmAbi for Option<$t> { impl IntoWasmAbi for Option<$t> {
type Abi = $r; type Abi = $r;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> $r { fn into_abi(self) -> $r {
match self { match self {
None => $r { None => $r {
present: 0, present: 0,
@ -96,7 +96,7 @@ macro_rules! type_wasm_native {
type Abi = $r; type Abi = $r;
#[inline] #[inline]
unsafe fn from_abi(js: $r, _extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: $r) -> Self {
if js.present == 0 { if js.present == 0 {
None None
} else { } else {
@ -122,14 +122,14 @@ macro_rules! type_abi_as_u32 {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } fn into_abi(self) -> u32 { self as u32 }
} }
impl FromWasmAbi for $t { impl FromWasmAbi for $t {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> Self { js as $t } unsafe fn from_abi(js: u32) -> Self { js as $t }
} }
impl OptionIntoWasmAbi for $t { impl OptionIntoWasmAbi for $t {
@ -152,7 +152,7 @@ macro_rules! type_64 {
type Abi = Wasm64; type Abi = Wasm64;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> Wasm64 { fn into_abi(self) -> Wasm64 {
Wasm64 { Wasm64 {
low: self as u32, low: self as u32,
high: (self >> 32) as u32, high: (self >> 32) as u32,
@ -164,7 +164,7 @@ macro_rules! type_64 {
type Abi = Wasm64; type Abi = Wasm64;
#[inline] #[inline]
unsafe fn from_abi(js: Wasm64, _extra: &mut dyn Stack) -> $t { unsafe fn from_abi(js: Wasm64) -> $t {
$t::from(js.low) | ($t::from(js.high) << 32) $t::from(js.low) | ($t::from(js.high) << 32)
} }
} }
@ -173,7 +173,7 @@ macro_rules! type_64 {
type Abi = WasmOptional64; type Abi = WasmOptional64;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> WasmOptional64 { fn into_abi(self) -> WasmOptional64 {
match self { match self {
None => WasmOptional64 { None => WasmOptional64 {
present: 0, present: 0,
@ -195,7 +195,7 @@ macro_rules! type_64 {
type Abi = WasmOptional64; type Abi = WasmOptional64;
#[inline] #[inline]
unsafe fn from_abi(js: WasmOptional64, _extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: WasmOptional64) -> Self {
if js.present == 0 { if js.present == 0 {
None None
} else { } else {
@ -212,7 +212,7 @@ impl IntoWasmAbi for bool {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
self as u32 self as u32
} }
} }
@ -221,7 +221,7 @@ impl FromWasmAbi for bool {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> bool { unsafe fn from_abi(js: u32) -> bool {
js != 0 js != 0
} }
} }
@ -244,7 +244,7 @@ impl IntoWasmAbi for char {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
self as u32 self as u32
} }
} }
@ -253,7 +253,7 @@ impl FromWasmAbi for char {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> char { unsafe fn from_abi(js: u32) -> char {
char::from_u32_unchecked(js) char::from_u32_unchecked(js)
} }
} }
@ -275,7 +275,7 @@ impl OptionFromWasmAbi for char {
impl<T> IntoWasmAbi for *const T { impl<T> IntoWasmAbi for *const T {
type Abi = u32; type Abi = u32;
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
self as u32 self as u32
} }
} }
@ -283,7 +283,7 @@ impl<T> IntoWasmAbi for *const T {
impl<T> FromWasmAbi for *const T { impl<T> FromWasmAbi for *const T {
type Abi = u32; type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *const T { unsafe fn from_abi(js: u32) -> *const T {
js as *const T js as *const T
} }
} }
@ -291,7 +291,7 @@ impl<T> FromWasmAbi for *const T {
impl<T> IntoWasmAbi for *mut T { impl<T> IntoWasmAbi for *mut T {
type Abi = u32; type Abi = u32;
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
self as u32 self as u32
} }
} }
@ -299,7 +299,7 @@ impl<T> IntoWasmAbi for *mut T {
impl<T> FromWasmAbi for *mut T { impl<T> FromWasmAbi for *mut T {
type Abi = u32; type Abi = u32;
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *mut T { unsafe fn from_abi(js: u32) -> *mut T {
js as *mut T js as *mut T
} }
} }
@ -308,7 +308,7 @@ impl IntoWasmAbi for JsValue {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
let ret = self.idx; let ret = self.idx;
mem::forget(self); mem::forget(self);
ret ret
@ -319,7 +319,7 @@ impl FromWasmAbi for JsValue {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> JsValue { unsafe fn from_abi(js: u32) -> JsValue {
JsValue::_new(js) JsValue::_new(js)
} }
} }
@ -328,7 +328,7 @@ impl<'a> IntoWasmAbi for &'a JsValue {
type Abi = u32; type Abi = u32;
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) -> u32 { fn into_abi(self) -> u32 {
self.idx self.idx
} }
} }
@ -338,7 +338,7 @@ impl RefFromWasmAbi for JsValue {
type Anchor = ManuallyDrop<JsValue>; type Anchor = ManuallyDrop<JsValue>;
#[inline] #[inline]
unsafe fn ref_from_abi(js: u32, _extra: &mut dyn Stack) -> Self::Anchor { unsafe fn ref_from_abi(js: u32) -> Self::Anchor {
ManuallyDrop::new(JsValue::_new(js)) ManuallyDrop::new(JsValue::_new(js))
} }
} }
@ -346,10 +346,10 @@ impl RefFromWasmAbi for JsValue {
impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> { impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
type Abi = T::Abi; type Abi = T::Abi;
fn into_abi(self, extra: &mut dyn Stack) -> T::Abi { fn into_abi(self) -> T::Abi {
match self { match self {
None => T::none(), None => T::none(),
Some(me) => me.into_abi(extra), Some(me) => me.into_abi(),
} }
} }
} }
@ -357,11 +357,11 @@ impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> {
impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> { impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
type Abi = T::Abi; type Abi = T::Abi;
unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: T::Abi) -> Self {
if T::is_none(&js) { if T::is_none(&js) {
None None
} else { } else {
Some(T::from_abi(js, extra)) Some(T::from_abi(js))
} }
} }
} }
@ -369,16 +369,16 @@ impl<T: OptionFromWasmAbi> FromWasmAbi for Option<T> {
impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> { impl<T: IntoWasmAbi> IntoWasmAbi for Clamped<T> {
type Abi = T::Abi; type Abi = T::Abi;
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.0.into_abi(extra) self.0.into_abi()
} }
} }
impl<T: FromWasmAbi> FromWasmAbi for Clamped<T> { impl<T: FromWasmAbi> FromWasmAbi for Clamped<T> {
type Abi = T::Abi; type Abi = T::Abi;
unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: T::Abi) -> Self {
Clamped(T::from_abi(js, extra)) Clamped(T::from_abi(js))
} }
} }
@ -386,7 +386,7 @@ impl IntoWasmAbi for () {
type Abi = (); type Abi = ();
#[inline] #[inline]
fn into_abi(self, _extra: &mut dyn Stack) { fn into_abi(self) {
self self
} }
} }
@ -394,9 +394,9 @@ impl IntoWasmAbi for () {
impl<T: IntoWasmAbi> ReturnWasmAbi for Result<T, JsValue> { impl<T: IntoWasmAbi> ReturnWasmAbi for Result<T, JsValue> {
type Abi = T::Abi; type Abi = T::Abi;
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn return_abi(self) -> Self::Abi {
match self { match self {
Ok(v) => v.into_abi(extra), Ok(v) => v.into_abi(),
Err(e) => crate::throw_val(e), Err(e) => crate::throw_val(e),
} }
} }

View File

@ -8,26 +8,3 @@ mod traits;
pub use self::slices::WasmSlice; pub use self::slices::WasmSlice;
pub use self::traits::*; pub use self::traits::*;
pub struct GlobalStack {
next: usize,
}
impl GlobalStack {
#[inline]
pub unsafe fn new() -> GlobalStack {
GlobalStack { next: 0 }
}
}
impl Stack for GlobalStack {
#[inline]
fn push(&mut self, val: u32) {
use crate::__rt::{__wbindgen_global_argument_ptr as global_ptr, GLOBAL_STACK_CAP};
unsafe {
assert!(self.next < GLOBAL_STACK_CAP);
*global_ptr().offset(self.next as isize) = val;
self.next += 1;
}
}
}

View File

@ -5,7 +5,7 @@ use core::slice;
use core::str; use core::str;
use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi}; use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi};
use crate::convert::{OptionIntoWasmAbi, Stack}; use crate::convert::OptionIntoWasmAbi;
if_std! { if_std! {
use core::mem; use core::mem;
@ -32,12 +32,12 @@ macro_rules! vectors {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
let ptr = self.as_ptr(); let ptr = self.as_ptr();
let len = self.len(); let len = self.len();
mem::forget(self); mem::forget(self);
WasmSlice { WasmSlice {
ptr: ptr.into_abi(extra), ptr: ptr.into_abi(),
len: len as u32, len: len as u32,
} }
} }
@ -51,8 +51,8 @@ macro_rules! vectors {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: WasmSlice) -> Self {
let ptr = <*mut $t>::from_abi(js.ptr, extra); let ptr = <*mut $t>::from_abi(js.ptr);
let len = js.len as usize; let len = js.len as usize;
Vec::from_raw_parts(ptr, len, len).into_boxed_slice() Vec::from_raw_parts(ptr, len, len).into_boxed_slice()
} }
@ -67,9 +67,9 @@ macro_rules! vectors {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
WasmSlice { WasmSlice {
ptr: self.as_ptr().into_abi(extra), ptr: self.as_ptr().into_abi(),
len: self.len() as u32, len: self.len() as u32,
} }
} }
@ -83,8 +83,8 @@ macro_rules! vectors {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
(&*self).into_abi(extra) (&*self).into_abi()
} }
} }
@ -97,9 +97,9 @@ macro_rules! vectors {
type Anchor = &'static [$t]; type Anchor = &'static [$t];
#[inline] #[inline]
unsafe fn ref_from_abi(js: WasmSlice, extra: &mut dyn Stack) -> &'static [$t] { unsafe fn ref_from_abi(js: WasmSlice) -> &'static [$t] {
slice::from_raw_parts( slice::from_raw_parts(
<*const $t>::from_abi(js.ptr, extra), <*const $t>::from_abi(js.ptr),
js.len as usize, js.len as usize,
) )
} }
@ -110,11 +110,11 @@ macro_rules! vectors {
type Anchor = &'static mut [$t]; type Anchor = &'static mut [$t];
#[inline] #[inline]
unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut dyn Stack) unsafe fn ref_mut_from_abi(js: WasmSlice)
-> &'static mut [$t] -> &'static mut [$t]
{ {
slice::from_raw_parts_mut( slice::from_raw_parts_mut(
<*mut $t>::from_abi(js.ptr, extra), <*mut $t>::from_abi(js.ptr),
js.len as usize, js.len as usize,
) )
} }
@ -130,8 +130,8 @@ if_std! {
impl<T> IntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> { impl<T> IntoWasmAbi for Vec<T> where Box<[T]>: IntoWasmAbi<Abi = WasmSlice> {
type Abi = <Box<[T]> as IntoWasmAbi>::Abi; type Abi = <Box<[T]> as IntoWasmAbi>::Abi;
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.into_boxed_slice().into_abi(extra) self.into_boxed_slice().into_abi()
} }
} }
@ -142,8 +142,8 @@ if_std! {
impl<T> FromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> { impl<T> FromWasmAbi for Vec<T> where Box<[T]>: FromWasmAbi<Abi = WasmSlice> {
type Abi = <Box<[T]> as FromWasmAbi>::Abi; type Abi = <Box<[T]> as FromWasmAbi>::Abi;
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: Self::Abi) -> Self {
<Box<[T]>>::from_abi(js, extra).into() <Box<[T]>>::from_abi(js).into()
} }
} }
@ -155,8 +155,8 @@ if_std! {
type Abi = <Vec<u8> as IntoWasmAbi>::Abi; type Abi = <Vec<u8> as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.into_bytes().into_abi(extra) self.into_bytes().into_abi()
} }
} }
@ -168,8 +168,8 @@ if_std! {
type Abi = <Vec<u8> as FromWasmAbi>::Abi; type Abi = <Vec<u8> as FromWasmAbi>::Abi;
#[inline] #[inline]
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: Self::Abi) -> Self {
String::from_utf8_unchecked(<Vec<u8>>::from_abi(js, extra)) String::from_utf8_unchecked(<Vec<u8>>::from_abi(js))
} }
} }
@ -182,8 +182,8 @@ impl<'a> IntoWasmAbi for &'a str {
type Abi = <&'a [u8] as IntoWasmAbi>::Abi; type Abi = <&'a [u8] as IntoWasmAbi>::Abi;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn into_abi(self) -> Self::Abi {
self.as_bytes().into_abi(extra) self.as_bytes().into_abi()
} }
} }
@ -198,8 +198,8 @@ impl RefFromWasmAbi for str {
type Anchor = &'static str; type Anchor = &'static str;
#[inline] #[inline]
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor {
str::from_utf8_unchecked(<[u8]>::ref_from_abi(js, extra)) str::from_utf8_unchecked(<[u8]>::ref_from_abi(js))
} }
} }
@ -210,12 +210,12 @@ if_std! {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { fn into_abi(self) -> WasmSlice {
let ptr = self.as_ptr(); let ptr = self.as_ptr();
let len = self.len(); let len = self.len();
mem::forget(self); mem::forget(self);
WasmSlice { WasmSlice {
ptr: ptr.into_abi(extra), ptr: ptr.into_abi(),
len: len as u32, len: len as u32,
} }
} }
@ -229,8 +229,8 @@ if_std! {
type Abi = WasmSlice; type Abi = WasmSlice;
#[inline] #[inline]
unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { unsafe fn from_abi(js: WasmSlice) -> Self {
let ptr = <*mut JsValue>::from_abi(js.ptr, extra); let ptr = <*mut JsValue>::from_abi(js.ptr);
let len = js.len as usize; let len = js.len as usize;
Vec::from_raw_parts(ptr, len, len).into_boxed_slice() Vec::from_raw_parts(ptr, len, len).into_boxed_slice()
} }

View File

@ -13,7 +13,7 @@ pub trait IntoWasmAbi: WasmDescribe {
/// Convert `self` into `Self::Abi` so that it can be sent across the wasm /// Convert `self` into `Self::Abi` so that it can be sent across the wasm
/// ABI boundary. /// ABI boundary.
fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi; fn into_abi(self) -> Self::Abi;
} }
/// A trait for anything that can be recovered by-value from the wasm ABI /// A trait for anything that can be recovered by-value from the wasm ABI
@ -32,7 +32,7 @@ pub trait FromWasmAbi: WasmDescribe {
/// This is only safe to call when -- and implementations may assume that -- /// This is only safe to call when -- and implementations may assume that --
/// the supplied `Self::Abi` was previously generated by a call to `<Self as /// the supplied `Self::Abi` was previously generated by a call to `<Self as
/// IntoWasmAbi>::into_abi()` or the moral equivalent in JS. /// IntoWasmAbi>::into_abi()` or the moral equivalent in JS.
unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self; unsafe fn from_abi(js: Self::Abi) -> Self;
} }
/// A trait for anything that can be recovered as some sort of shared reference /// A trait for anything that can be recovered as some sort of shared reference
@ -55,7 +55,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
/// # Safety /// # Safety
/// ///
/// Same as `FromWasmAbi::from_abi`. /// Same as `FromWasmAbi::from_abi`.
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor;
} }
/// Dual of the `RefFromWasmAbi` trait, except for mutable references. /// Dual of the `RefFromWasmAbi` trait, except for mutable references.
@ -65,7 +65,7 @@ pub trait RefMutFromWasmAbi: WasmDescribe {
/// Same as `RefFromWasmAbi::Anchor` /// Same as `RefFromWasmAbi::Anchor`
type Anchor: DerefMut<Target = Self>; type Anchor: DerefMut<Target = Self>;
/// Same as `RefFromWasmAbi::ref_from_abi` /// Same as `RefFromWasmAbi::ref_from_abi`
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor;
} }
/// Indicates that this type can be passed to JS as `Option<Self>`. /// Indicates that this type can be passed to JS as `Option<Self>`.
@ -90,10 +90,6 @@ pub trait OptionFromWasmAbi: FromWasmAbi {
fn is_none(abi: &Self::Abi) -> bool; fn is_none(abi: &Self::Abi) -> bool;
} }
pub trait Stack {
fn push(&mut self, bits: u32);
}
/// An unsafe trait which represents types that are ABI-safe to pass via wasm /// An unsafe trait which represents types that are ABI-safe to pass via wasm
/// arguments. /// arguments.
/// ///
@ -120,12 +116,12 @@ pub trait ReturnWasmAbi: WasmDescribe {
/// Same as `IntoWasmAbi::into_abi`, except that it may throw and never /// Same as `IntoWasmAbi::into_abi`, except that it may throw and never
/// return in the case of `Err`. /// return in the case of `Err`.
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi; fn return_abi(self) -> Self::Abi;
} }
impl<T: IntoWasmAbi> ReturnWasmAbi for T { impl<T: IntoWasmAbi> ReturnWasmAbi for T {
type Abi = T::Abi; type Abi = T::Abi;
fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { fn return_abi(self) -> Self::Abi {
self.into_abi(extra) self.into_abi()
} }
} }