#![no_std]
#[doc(hidden)]
pub extern crate alloc;
#[macro_use]
extern crate std;
pub mod batch;
mod cast;
mod clamped;
pub mod closure;
pub mod convert;
mod encode;
mod erasure;
mod function;
mod function_registry;
mod id_allocator;
mod intern;
pub(crate) mod ipc;
#[macro_use]
mod wire;
#[doc(hidden)]
#[path = "rt.rs"]
pub mod __rt;
mod js_error;
mod js_helpers;
mod lazy;
mod object_store;
mod parent;
mod runtime;
pub mod sys;
mod try_from_js;
mod type_cache;
mod value;
pub mod wry;
pub use intern::*;
pub use crate::__rt::marker::ErasableGeneric;
pub use cast::JsCast;
pub use clamped::Clamped;
pub use closure::{
Closure, IntoWasmClosure, IntoWasmClosureRef, IntoWasmClosureRefMut, MaybeUnwindSafe,
ScopedClosure, WasmClosure, WasmClosureFnOnce, WasmClosureFnOnceAbort, WryWasmClosure,
};
pub use js_error::JsError;
pub use lazy::JsThreadLocal;
pub use value::JsValue;
pub use crate::__rt::{Ref, RefMut};
pub use parent::Parent;
pub use convert::{IntoJsGeneric, JsGeneric};
pub use encode::{BatchableResult, BinaryDecode, BinaryEncode, EncodeTypeDef};
pub use function::JSFunction;
pub use ipc::{DecodeError, DecodedData, EncodedData};
pub use sys::{JsOption, Null, Promising, Undefined};
pub use wry_bindgen_macro::link_to;
pub use wry_bindgen_macro::wasm_bindgen;
#[macro_export]
#[doc(hidden)]
macro_rules! __wry_call_js_function {
($js_code:expr, $fn_type:ty, ($($args:expr),*)) => {{
static __FUNC: $crate::__rt::LazyJsFunction<$fn_type> =
$crate::__wry_submit_js_function!($js_code);
__FUNC.call($($args),*)
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __wry_submit_js_function {
($js_code:expr) => {{
static __SPEC: $crate::__rt::JsFunctionSpec =
$crate::__rt::JsFunctionSpec::new(|| $crate::alloc::format!($js_code));
$crate::__rt::inventory::submit! {
__SPEC
}
__SPEC.resolve_as()
}};
}
pub trait UnwrapThrowExt<T>: Sized {
#[cfg_attr(any(debug_assertions, not(target_family = "wasm")), track_caller)]
fn unwrap_throw(self) -> T {
if cfg!(all(debug_assertions, target_family = "wasm")) {
let loc = core::panic::Location::caller();
let msg = alloc::format!(
"called `{}::unwrap_throw()` ({}:{}:{})",
core::any::type_name::<Self>(),
loc.file(),
loc.line(),
loc.column()
);
self.expect_throw(&msg)
} else {
self.expect_throw("called `unwrap_throw()`")
}
}
fn expect_throw(self, message: &str) -> T;
}
impl<T> UnwrapThrowExt<T> for Option<T> {
fn unwrap_throw(self) -> T {
self.expect("called `Option::unwrap_throw()` on a `None` value")
}
fn expect_throw(self, message: &str) -> T {
self.expect(message)
}
}
impl<T, E> UnwrapThrowExt<T> for Result<T, E>
where
E: core::fmt::Debug,
{
fn unwrap_throw(self) -> T {
self.expect("called `Result::unwrap_throw()` on an `Err` value")
}
fn expect_throw(self, message: &str) -> T {
self.expect(message)
}
}
#[cold]
#[inline(never)]
pub fn throw_val(s: JsValue) -> ! {
panic!("{s:?}");
}
#[cold]
#[inline(never)]
pub fn throw_str(s: &str) -> ! {
panic!("cannot throw JS exception when running outside of wasm: {s}");
}
#[cold]
#[inline(never)]
#[deprecated(note = "renamed to `throw_str`")]
#[doc(hidden)]
pub fn throw(s: &str) -> ! {
throw_str(s)
}
pub fn externref_heap_live_count() -> u32 {
panic!("cannot introspect wasm memory when running outside of wasm")
}
pub fn module() -> JsValue {
panic!("cannot introspect wasm memory when running outside of wasm")
}
pub fn instance() -> JsValue {
panic!("cannot introspect wasm memory when running outside of wasm")
}
pub fn exports() -> JsValue {
panic!("cannot introspect wasm memory when running outside of wasm")
}
pub fn memory() -> JsValue {
panic!("cannot introspect wasm memory when running outside of wasm")
}
pub fn function_table() -> JsValue {
panic!("cannot introspect wasm memory when running outside of wasm")
}
#[deprecated = "use with `#[wasm_bindgen(thread_local_v2)]` instead"]
pub struct JsStatic<T: 'static> {
#[doc(hidden)]
pub __inner: &'static std::thread::LocalKey<T>,
}
#[allow(deprecated)]
impl<T: 'static> core::ops::Deref for JsStatic<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { self.__inner.with(|ptr| &*(ptr as *const T)) }
}
}
pub mod prelude {
pub use crate::Clamped;
pub use crate::JsCast;
pub use crate::JsError;
pub use crate::JsValue;
pub use crate::UnwrapThrowExt;
pub use crate::WasmClosure;
pub use crate::closure::{Closure, ScopedClosure};
pub use crate::convert::Upcast;
pub use crate::convert::{IntoJsGeneric, JsGeneric, UpcastFrom};
pub use crate::wasm_bindgen;
pub use crate::{BatchableResult, BinaryDecode, BinaryEncode, EncodeTypeDef};
pub use crate::{JSFunction, JsThreadLocal};
pub use crate::{JsOption, Null, Promising, Undefined};
}