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/convert/traits.rs | |
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/convert/traits.rs')
-rw-r--r-- | vendor/wasm-bindgen/src/convert/traits.rs | 27 |
1 files changed, 27 insertions, 0 deletions
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` |