Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

A JavaScript runtime: one heap, one memory limit, one set of host hooks.

Mirrors the role of JSRuntime in the QuickJS C API.

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Runtime

Create a runtime with default limits.

Examples found in repository?
examples/embed.rs (line 5)
4fn main() -> Result<(), quickjs::Error> {
5    let runtime = Runtime::new();
6    let mut context = Context::new(&runtime);
7    context.eval("print([1, 2, 3].map(x => x * 2).join('-'));")?;
8    assert_eq!(context.output(), "2-4-6\n");
9    print!("{}", context.output());
10    Ok(())
11}
Source

pub fn heap(&self) -> &Heap

The runtime’s object heap.

Source

pub fn set_memory_limit(&mut self, limit: Option<usize>)

Equivalent of JS_SetMemoryLimit.

Source

pub fn memory_limit(&self) -> Option<usize>

Configured memory limit, if any.

Source

pub fn set_stack_size(&mut self, limit: Option<usize>)

Equivalent of JS_SetMaxStackSize.

Source

pub fn stack_size(&self) -> Option<usize>

Configured stack size limit, if any.

Source

pub fn run_gc(&self) -> CollectStats

Equivalent of JS_RunGC.

Trait Implementations§

Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.