rquickjs_core/
runtime.rs

1//! QuickJS runtime related types.
2
3mod base;
4pub(crate) mod opaque;
5pub(crate) mod raw;
6mod userdata;
7
8#[cfg(feature = "futures")]
9mod r#async;
10#[cfg(feature = "futures")]
11pub(crate) mod schedular;
12#[cfg(feature = "futures")]
13mod spawner;
14#[cfg(feature = "futures")]
15pub use spawner::DriveFuture;
16
17use alloc::boxed::Box;
18pub use base::{Runtime, WeakRuntime};
19pub use userdata::{UserDataError, UserDataGuard};
20
21#[cfg(feature = "futures")]
22pub(crate) use r#async::InnerRuntime;
23#[cfg(feature = "futures")]
24pub use r#async::{AsyncRuntime, AsyncWeakRuntime};
25
26use crate::value::promise::PromiseHookType;
27use crate::{Ctx, Value};
28
29/// The type of the promise hook.
30#[cfg(not(feature = "parallel"))]
31pub type PromiseHook =
32    Box<dyn for<'a> Fn(Ctx<'a>, PromiseHookType, Value<'a>, Value<'a>) + 'static>;
33/// The type of the promise hook.
34#[cfg(feature = "parallel")]
35pub type PromiseHook =
36    Box<dyn for<'a> Fn(Ctx<'a>, PromiseHookType, Value<'a>, Value<'a>) + Send + 'static>;
37
38/// The type of the promise rejection tracker.
39#[cfg(not(feature = "parallel"))]
40pub type RejectionTracker = Box<dyn for<'a> Fn(Ctx<'a>, Value<'a>, Value<'a>, bool) + 'static>;
41/// The type of the promise rejection tracker.
42#[cfg(feature = "parallel")]
43pub type RejectionTracker =
44    Box<dyn for<'a> Fn(Ctx<'a>, Value<'a>, Value<'a>, bool) + Send + 'static>;
45
46/// The type of the interrupt handler.
47#[cfg(not(feature = "parallel"))]
48pub type InterruptHandler = Box<dyn FnMut() -> bool + 'static>;
49/// The type of the interrupt handler.
50#[cfg(feature = "parallel")]
51pub type InterruptHandler = Box<dyn FnMut() -> bool + Send + 'static>;
52
53/// A struct with information about the runtimes memory usage.
54pub type MemoryUsage = crate::qjs::JSMemoryUsage;