pub(crate) mod quickjs_ng;
use std::fmt;
use std::time::Instant;
use crate::limits::Limits;
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum Completion {
String(String),
NonString(&'static str),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum EngineError {
Exception { message: String, stack: String },
Internal(String),
}
impl fmt::Display for EngineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
EngineError::Exception { message, .. } => f.write_str(message),
EngineError::Internal(message) => f.write_str(message),
}
}
}
pub(crate) trait JsEngine {
fn new(limits: &Limits) -> Result<Self, EngineError>
where
Self: Sized;
fn install_console(&mut self) -> Result<(), EngineError>;
fn evaluate(&mut self, source: &str, filename: &str) -> Result<Completion, EngineError>;
fn set_interrupt_deadline(&mut self, deadline: Option<Instant>);
fn console_output(&self) -> &[String];
}