Struct rquickjs_core::runtime::Runtime
source · pub struct Runtime { /* private fields */ }
Expand description
QuickJS runtime, entry point of the library.
Implementations§
source§impl Runtime
impl Runtime
sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
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<Self>where
A: Allocator + 'static,
Available on crate feature allocator
only.
pub fn new_with_alloc<A>(allocator: A) -> Result<Self>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<InterruptHandler>)
pub fn set_interrupt_handler(&self, handler: Option<InterruptHandler>)
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)
Available on crate feature loader
only.
pub fn set_loader<R, L>(&self, resolver: R, loader: L)
loader
only.Set the module loader
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 automatically free themselves when they have no more references. The garbage collector is only for collecting cyclic references.
sourcepub fn memory_usage(&self) -> MemoryUsage
pub fn memory_usage(&self) -> MemoryUsage
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) -> StdResult<bool, JobException>
pub fn execute_pending_job(&self) -> StdResult<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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl Unpin for Runtime
impl !UnwindSafe for Runtime
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more