Skip to main content

JsRuntime

Struct JsRuntime 

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

The engine runtime plus the tables whose lifetime is the runtime’s, not a context’s.

Implementations§

Source§

impl JsRuntime

Source

pub fn new() -> Box<JsRuntime>

JS_NewRuntime.

Source

pub fn opaque(&self) -> *mut c_void

JS_GetRuntimeOpaque.

Source

pub fn set_opaque(&self, opaque: *mut c_void)

JS_SetRuntimeOpaque.

Source

pub fn info(&self) -> *const c_char

JS_GetRuntimeInfo, which the reference does not export but JS_SetRuntimeInfo sets.

Source

pub fn set_info(&self, info: *const c_char)

JS_SetRuntimeInfo.

Source

pub fn set_gc_threshold(&self, threshold: usize)

JS_SetGCThreshold. A threshold of 0 means “collect on every allocation”, which is not worth reproducing; the value is kept and used by [JsRuntime::maybe_collect].

Source

pub fn gc_threshold(&self) -> usize

JS_GetGCThreshold, our addition: the threshold the host set.

Source

pub fn set_interrupt_handler( &self, callback: InterruptHandler, opaque: *mut c_void, )

JS_SetInterruptHandler.

Source

pub fn interrupt_handler( &self, ) -> Option<(unsafe extern "C" fn(*mut JsRuntime, *mut c_void) -> c_int, *mut c_void)>

The installed interrupt handler, if any.

Source

pub fn set_can_block(&self, can_block: bool)

JS_SetCanBlock.

Source

pub fn can_block(&self) -> bool

Whether a blocking operation is allowed (JS_SetCanBlock’s answer).

Source

pub fn module_loader_hooks(&self) -> Option<ModuleLoaderHooks>

JS_SetModuleLoaderFunc/JS_SetModuleLoaderFunc2’s state.

Source

pub fn set_module_loader_hooks(&self, hooks: ModuleLoaderHooks)

Record the module loader hooks.

Source

pub fn live_contexts(&self) -> Vec<*mut JsContext>

Every live context, for the API functions that take a JSRuntime *.

Source

pub fn engine_ptr(&self) -> *const Runtime

The engine runtime as a raw pointer, for the API functions that need &mut.

A *mut rather than a reference because JS_SetMemoryLimit takes a JSRuntime * and has no borrow to hand out; the caller forms the &mut under the single-threaded-per- runtime contract the C API states.

Source

pub fn strip_info(&self) -> c_int

JS_SetStripInfo’s recorded flags.

Source

pub fn set_strip_info(&self, flags: c_int)

Record the strip-info flags.

Source

pub fn define_class(&self, id: ClassId, decl: ClassDecl) -> bool

JS_NewClass: register (or replace) the class under id.

Answers false for JS_INVALID_CLASS_ID, which the C API reports as -1.

Source

pub fn class(&self, id: ClassId) -> Option<Rc<ClassDecl>>

The class registered under id, if any.

Source

pub fn has_class(&self, id: ClassId) -> bool

Whether id names a registered class.

Source

pub unsafe fn adopt_for_session(&self, context: *mut JsContext)

Track a context the host owns, for as long as a script runs.

The context is not dropped with the runtime: the host session owns it, and the runtime only borrows it to reach the interpreter class registration has to write to. JS_FreeRuntime therefore skips it, which is why this is a separate entry point from JsRuntime::adopt.

§Safety

context must stay alive until JsRuntime::disown is called with it.

Source

pub unsafe fn disown(&self, context: *mut JsContext)

Forget a context from JsRuntime::adopt_for_session.

§Safety

context must have been adopted by adopt_for_session and not disowned since.

Source

pub unsafe fn free(runtime: *mut JsRuntime)

JS_FreeRuntime: drop every context, then the runtime.

§Safety

runtime must come from JsRuntime::new via Box::into_raw, and no context or class handle may be used afterwards.

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.