diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/wasm-bindgen/src | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/wasm-bindgen/src')
-rw-r--r-- | vendor/wasm-bindgen/src/closure.rs | 8 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/convert/closures.rs | 8 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/convert/impls.rs | 12 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/convert/slices.rs | 84 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/convert/traits.rs | 27 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/describe.rs | 1 | ||||
-rw-r--r-- | vendor/wasm-bindgen/src/lib.rs | 52 |
7 files changed, 171 insertions, 21 deletions
diff --git a/vendor/wasm-bindgen/src/closure.rs b/vendor/wasm-bindgen/src/closure.rs index 37cef06dc..c8d2ba225 100644 --- a/vendor/wasm-bindgen/src/closure.rs +++ b/vendor/wasm-bindgen/src/closure.rs @@ -571,7 +571,7 @@ macro_rules! doit { $($var: <$var as FromWasmAbi>::Abi),* ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked after being dropped"); } // Make sure all stack variables are converted before we // convert `ret` as it may throw (for `Result`, for @@ -623,7 +623,7 @@ macro_rules! doit { $($var: <$var as FromWasmAbi>::Abi),* ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked recursively or after being dropped"); } // Make sure all stack variables are converted before we // convert `ret` as it may throw (for `Result`, for @@ -759,7 +759,7 @@ where arg: <A as RefFromWasmAbi>::Abi, ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked after being dropped"); } // Make sure all stack variables are converted before we // convert `ret` as it may throw (for `Result`, for @@ -802,7 +802,7 @@ where arg: <A as RefFromWasmAbi>::Abi, ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked recursively or after being dropped"); } // Make sure all stack variables are converted before we // convert `ret` as it may throw (for `Result`, for diff --git a/vendor/wasm-bindgen/src/convert/closures.rs b/vendor/wasm-bindgen/src/convert/closures.rs index 97755b8ee..9137065a2 100644 --- a/vendor/wasm-bindgen/src/convert/closures.rs +++ b/vendor/wasm-bindgen/src/convert/closures.rs @@ -29,7 +29,7 @@ macro_rules! stack_closures { $($var: <$var as FromWasmAbi>::Abi),* ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked after being dropped"); } // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw @@ -78,7 +78,7 @@ macro_rules! stack_closures { $($var: <$var as FromWasmAbi>::Abi),* ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked recursively or after being dropped"); } // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw @@ -145,7 +145,7 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>( arg: <A as RefFromWasmAbi>::Abi, ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked after being dropped"); } // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw @@ -197,7 +197,7 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>( arg: <A as RefFromWasmAbi>::Abi, ) -> <R as ReturnWasmAbi>::Abi { if a == 0 { - throw_str("closure invoked recursively or destroyed already"); + throw_str("closure invoked recursively or after being dropped"); } // Scope all local variables before we call `return_abi` to // ensure they're all destroyed as `return_abi` may throw diff --git a/vendor/wasm-bindgen/src/convert/impls.rs b/vendor/wasm-bindgen/src/convert/impls.rs index 79ccd67af..e8636fe9e 100644 --- a/vendor/wasm-bindgen/src/convert/impls.rs +++ b/vendor/wasm-bindgen/src/convert/impls.rs @@ -2,7 +2,7 @@ use core::char; use core::mem::{self, ManuallyDrop}; use crate::convert::traits::WasmAbi; -use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi}; +use crate::convert::{FromWasmAbi, IntoWasmAbi, LongRefFromWasmAbi, RefFromWasmAbi}; use crate::convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi}; use crate::{Clamped, JsError, JsValue}; @@ -248,6 +248,16 @@ impl RefFromWasmAbi for JsValue { } } +impl LongRefFromWasmAbi for JsValue { + type Abi = u32; + type Anchor = JsValue; + + #[inline] + unsafe fn long_ref_from_abi(js: u32) -> Self::Anchor { + Self::from_abi(js) + } +} + impl<T: OptionIntoWasmAbi> IntoWasmAbi for Option<T> { type Abi = T::Abi; diff --git a/vendor/wasm-bindgen/src/convert/slices.rs b/vendor/wasm-bindgen/src/convert/slices.rs index 9d0970f4e..58608b8c5 100644 --- a/vendor/wasm-bindgen/src/convert/slices.rs +++ b/vendor/wasm-bindgen/src/convert/slices.rs @@ -1,12 +1,15 @@ #[cfg(feature = "std")] use std::prelude::v1::*; -use core::slice; +use core::ops::{Deref, DerefMut}; use core::str; +use crate::__wbindgen_copy_to_typed_array; use crate::cast::JsObject; use crate::convert::OptionIntoWasmAbi; -use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi}; +use crate::convert::{ + FromWasmAbi, IntoWasmAbi, LongRefFromWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi, +}; use cfg_if::cfg_if; if_std! { @@ -27,6 +30,50 @@ fn null_slice() -> WasmSlice { WasmSlice { ptr: 0, len: 0 } } +if_std! { + #[repr(C)] + pub struct WasmMutSlice { + pub slice: WasmSlice, + pub idx: u32, + } + + unsafe impl WasmAbi for WasmMutSlice {} + + /// The representation of a mutable slice passed from JS to Rust. + pub struct MutSlice<T> { + /// A copy of the data in the JS typed array. + contents: Box<[T]>, + /// A reference to the original JS typed array. + js: JsValue, + } + + impl<T> Drop for MutSlice<T> { + fn drop(&mut self) { + unsafe { + __wbindgen_copy_to_typed_array( + self.contents.as_ptr() as *const u8, + self.contents.len() * mem::size_of::<T>(), + self.js.idx + ); + } + } + } + + impl<T> Deref for MutSlice<T> { + type Target = [T]; + + fn deref(&self) -> &[T] { + &self.contents + } + } + + impl<T> DerefMut for MutSlice<T> { + fn deref_mut(&mut self) -> &mut [T] { + &mut self.contents + } + } +} + macro_rules! vectors { ($($t:ident)*) => ($( if_std! { @@ -109,17 +156,24 @@ macro_rules! vectors { } impl RefMutFromWasmAbi for [$t] { + type Abi = WasmMutSlice; + type Anchor = MutSlice<$t>; + + #[inline] + unsafe fn ref_mut_from_abi(js: WasmMutSlice) -> MutSlice<$t> { + let contents = <Box<[$t]>>::from_abi(js.slice); + let js = JsValue::from_abi(js.idx); + MutSlice { contents, js } + } + } + + impl LongRefFromWasmAbi for [$t] { type Abi = WasmSlice; - type Anchor = &'static mut [$t]; + type Anchor = Box<[$t]>; #[inline] - unsafe fn ref_mut_from_abi(js: WasmSlice) - -> &'static mut [$t] - { - slice::from_raw_parts_mut( - <*mut $t>::from_abi(js.ptr), - js.len as usize, - ) + unsafe fn long_ref_from_abi(js: WasmSlice) -> Box<[$t]> { + Self::ref_from_abi(js) } } )*) @@ -233,6 +287,16 @@ impl RefFromWasmAbi for str { } } +impl LongRefFromWasmAbi for str { + type Abi = <[u8] as RefFromWasmAbi>::Abi; + type Anchor = Box<str>; + + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + Self::ref_from_abi(js) + } +} + if_std! { use crate::JsValue; diff --git a/vendor/wasm-bindgen/src/convert/traits.rs b/vendor/wasm-bindgen/src/convert/traits.rs index b9d12b4c8..17b72a837 100644 --- a/vendor/wasm-bindgen/src/convert/traits.rs +++ b/vendor/wasm-bindgen/src/convert/traits.rs @@ -1,3 +1,4 @@ +use core::borrow::Borrow; use core::ops::{Deref, DerefMut}; use crate::describe::*; @@ -58,6 +59,32 @@ pub trait RefFromWasmAbi: WasmDescribe { unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor; } +/// A version of the `RefFromWasmAbi` trait with the additional requirement +/// that the reference must remain valid as long as the anchor isn't dropped. +/// +/// This isn't the case for `JsValue`'s `RefFromWasmAbi` implementation. To +/// avoid having to allocate a spot for the `JsValue` on the `JsValue` heap, +/// the `JsValue` is instead pushed onto the `JsValue` stack, and popped off +/// again after the function that the reference was passed to returns. So, +/// `JsValue` has a different `LongRefFromWasmAbi` implementation that behaves +/// the same as `FromWasmAbi`, putting the value on the heap. +/// +/// This is needed for async functions, where the reference needs to be valid +/// for the whole length of the `Future`, rather than the initial synchronous +/// call. +/// +/// 'long ref' is short for 'long-lived reference'. +pub trait LongRefFromWasmAbi: WasmDescribe { + /// Same as `RefFromWasmAbi::Abi` + type Abi: WasmAbi; + + /// Same as `RefFromWasmAbi::Anchor` + type Anchor: Borrow<Self>; + + /// Same as `RefFromWasmAbi::ref_from_abi` + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor; +} + /// Dual of the `RefFromWasmAbi` trait, except for mutable references. pub trait RefMutFromWasmAbi: WasmDescribe { /// Same as `RefFromWasmAbi::Abi` diff --git a/vendor/wasm-bindgen/src/describe.rs b/vendor/wasm-bindgen/src/describe.rs index 2b7c4b628..be149d7a9 100644 --- a/vendor/wasm-bindgen/src/describe.rs +++ b/vendor/wasm-bindgen/src/describe.rs @@ -34,6 +34,7 @@ tys! { STRING REF REFMUT + LONGREF SLICE VECTOR EXTERNREF diff --git a/vendor/wasm-bindgen/src/lib.rs b/vendor/wasm-bindgen/src/lib.rs index 2ccb284b9..f8576ed4c 100644 --- a/vendor/wasm-bindgen/src/lib.rs +++ b/vendor/wasm-bindgen/src/lib.rs @@ -44,12 +44,13 @@ macro_rules! externs { ) } -/// A module which is typically glob imported from: +/// A module which is typically glob imported. /// /// ``` /// use wasm_bindgen::prelude::*; /// ``` pub mod prelude { + pub use crate::JsCast; pub use crate::JsValue; pub use crate::UnwrapThrowExt; #[doc(hidden)] @@ -63,6 +64,8 @@ pub mod prelude { pub use crate::JsError; } +pub use wasm_bindgen_macro::link_to; + pub mod convert; pub mod describe; @@ -91,7 +94,7 @@ pub struct JsValue { _marker: marker::PhantomData<*mut u8>, // not at all threadsafe } -const JSIDX_OFFSET: u32 = 32; // keep in sync with js/mod.rs +const JSIDX_OFFSET: u32 = 128; // keep in sync with js/mod.rs const JSIDX_UNDEFINED: u32 = JSIDX_OFFSET + 0; const JSIDX_NULL: u32 = JSIDX_OFFSET + 1; const JSIDX_TRUE: u32 = JSIDX_OFFSET + 2; @@ -348,6 +351,12 @@ impl JsValue { unsafe { __wbindgen_is_object(self.idx) == 1 } } + /// Tests whether this JS value is an instance of Array. + #[inline] + pub fn is_array(&self) -> bool { + unsafe { __wbindgen_is_array(self.idx) == 1 } + } + /// Tests whether the type of this JS value is `function`. #[inline] pub fn is_function(&self) -> bool { @@ -779,6 +788,20 @@ impl<'a> From<&'a str> for JsValue { } } +impl<T> From<*mut T> for JsValue { + #[inline] + fn from(s: *mut T) -> JsValue { + JsValue::from(s as usize) + } +} + +impl<T> From<*const T> for JsValue { + #[inline] + fn from(s: *const T) -> JsValue { + JsValue::from(s as usize) + } +} + if_std! { impl<'a> From<&'a String> for JsValue { #[inline] @@ -1003,6 +1026,7 @@ externs! { fn __wbindgen_is_undefined(idx: u32) -> u32; fn __wbindgen_is_symbol(idx: u32) -> u32; fn __wbindgen_is_object(idx: u32) -> u32; + fn __wbindgen_is_array(idx: u32) -> u32; fn __wbindgen_is_function(idx: u32) -> u32; fn __wbindgen_is_string(idx: u32) -> u32; fn __wbindgen_is_bigint(idx: u32) -> u32; @@ -1054,6 +1078,8 @@ externs! { fn __wbindgen_jsval_eq(a: u32, b: u32) -> u32; fn __wbindgen_jsval_loose_eq(a: u32, b: u32) -> u32; + fn __wbindgen_copy_to_typed_array(ptr: *const u8, len: usize, idx: u32) -> (); + fn __wbindgen_not(idx: u32) -> u32; fn __wbindgen_memory() -> u32; @@ -1346,6 +1372,7 @@ pub fn function_table() -> JsValue { #[doc(hidden)] pub mod __rt { use crate::JsValue; + use core::borrow::{Borrow, BorrowMut}; use core::cell::{Cell, UnsafeCell}; use core::ops::{Deref, DerefMut}; @@ -1465,6 +1492,13 @@ pub mod __rt { } } + impl<'b, T: ?Sized> Borrow<T> for Ref<'b, T> { + #[inline] + fn borrow(&self) -> &T { + self.value + } + } + impl<'b, T: ?Sized> Drop for Ref<'b, T> { fn drop(&mut self) { self.borrow.set(self.borrow.get() - 1); @@ -1492,6 +1526,20 @@ pub mod __rt { } } + impl<'b, T: ?Sized> Borrow<T> for RefMut<'b, T> { + #[inline] + fn borrow(&self) -> &T { + self.value + } + } + + impl<'b, T: ?Sized> BorrowMut<T> for RefMut<'b, T> { + #[inline] + fn borrow_mut(&mut self) -> &mut T { + self.value + } + } + impl<'b, T: ?Sized> Drop for RefMut<'b, T> { fn drop(&mut self) { self.borrow.set(0); |