mod bridge;
pub mod code_cache;
mod convert;
mod engine;
mod host;
mod isolate;
mod loader;
mod scheduler;
mod watchdog;
mod worker;
pub use bridge::EngineHooks;
pub use bridge::RpcHandler;
pub use code_cache::engine_abi_key;
pub use deno_napi::addons_pending_unsafe_reregistration;
pub use deno_napi::addons_with_live_registrations;
pub use engine::EngineRegistry;
pub use engine::JsEngine;
pub use host::HostModule;
pub use host::HostModuleType;
pub use host::HostRequest;
pub use host::HostRequests;
pub use host::HostResolved;
pub use host::ModuleHost;
use std::path::PathBuf;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct EngineConfig {
pub root: PathBuf,
pub memory_limit_bytes: Option<usize>,
pub default_deadline: Option<Duration>,
pub code_cache_dir: Option<PathBuf>,
pub registry: Option<EngineRegistry>,
}
impl EngineConfig {
pub fn new(root: impl Into<PathBuf>) -> Self {
Self {
root: root.into(),
memory_limit_bytes: None,
default_deadline: None,
code_cache_dir: None,
registry: None,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum EngineError {
#[error("failed to boot JS engine: {0}")]
Boot(String),
#[error("{0}")]
Js(String),
#[error("JS execution exceeded the memory limit")]
MemoryLimit,
#[error("JS execution exceeded the deadline")]
Deadline,
#[error("the JS engine is shut down")]
Closed,
}
#[derive(Debug)]
pub enum EvalInput {
Source(String),
Path(PathBuf),
}
pub(crate) fn lock<T>(mutex: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
mutex
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
}