#[repr(transparent)]pub struct Runtime { /* private fields */ }
Expand description
Quickjs runtime, entry point of the library.
Implementations§
source§impl Runtime
impl Runtime
sourcepub fn new() -> Result<Runtime, Error>
pub fn new() -> Result<Runtime, Error>
Create a new runtime.
Will generally only fail if not enough memory was available.
Features
If the "rust-alloc"
feature is enabled the Rust’s global allocator will be used in favor of libc’s one.
sourcepub fn new_with_alloc<A>(allocator: A) -> Result<Runtime, Error>where
A: Allocator + 'static,
Available on crate feature allocator
only.
pub fn new_with_alloc<A>(allocator: A) -> Result<Runtime, Error>where A: Allocator + 'static,
allocator
only.Create a new runtime using specified allocator
Will generally only fail if not enough memory was available.
sourcepub fn weak(&self) -> WeakRuntime
pub fn weak(&self) -> WeakRuntime
Get weak ref to runtime
sourcepub fn set_interrupt_handler(
&self,
handler: Option<Box<dyn FnMut() -> bool + Send, Global>>
)
pub fn set_interrupt_handler( &self, handler: Option<Box<dyn FnMut() -> bool + Send, Global>> )
Set a closure which is regularly called by the engine when it is executing code.
If the provided closure returns true
the interpreter will raise and uncatchable
exception and return control flow to the caller.
sourcepub fn set_loader<R, L>(&self, resolver: R, loader: L)where
R: Resolver + 'static,
L: RawLoader + 'static,
Available on crate feature loader
only.
pub fn set_loader<R, L>(&self, resolver: R, loader: L)where R: Resolver + 'static, L: RawLoader + 'static,
loader
only.Set the module loader
sourcepub fn set_info<S>(&self, info: S) -> Result<(), Error>where
S: Into<Vec<u8, Global>>,
pub fn set_info<S>(&self, info: S) -> Result<(), Error>where S: Into<Vec<u8, Global>>,
Set the info of the runtime
sourcepub fn set_memory_limit(&self, limit: usize)
pub fn set_memory_limit(&self, limit: usize)
Set a limit on the max amount of memory the runtime will use.
Setting the limit to 0 is equivalent to unlimited memory.
Note that is a Noop when a custom allocator is being used, as is the case for the “rust-alloc” or “allocator” features.
sourcepub fn set_max_stack_size(&self, limit: usize)
pub fn set_max_stack_size(&self, limit: usize)
Set a limit on the max size of stack the runtime will use.
The default values is 256x1024 bytes.
sourcepub fn set_gc_threshold(&self, threshold: usize)
pub fn set_gc_threshold(&self, threshold: usize)
Set a memory threshold for garbage collection.
sourcepub fn run_gc(&self)
pub fn run_gc(&self)
Manually run the garbage collection.
Most of quickjs values are reference counted and will automaticly free themselfs when they have no more references. The garbage collector is only for collecting cyclic references.
sourcepub fn memory_usage(&self) -> JSMemoryUsage
pub fn memory_usage(&self) -> JSMemoryUsage
Get memory usage stats
sourcepub fn is_job_pending(&self) -> bool
pub fn is_job_pending(&self) -> bool
Test for pending jobs
Returns true when at least one job is pending.
sourcepub fn execute_pending_job(&self) -> Result<bool, JobException>
pub fn execute_pending_job(&self) -> Result<bool, JobException>
Execute first pending job
Returns true when job was executed or false when queue is empty or error when exception thrown under execution.