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
impl JsRuntime
Sourcepub fn set_opaque(&self, opaque: *mut c_void)
pub fn set_opaque(&self, opaque: *mut c_void)
JS_SetRuntimeOpaque.
Sourcepub fn info(&self) -> *const c_char
pub fn info(&self) -> *const c_char
JS_GetRuntimeInfo, which the reference does not export but JS_SetRuntimeInfo sets.
Sourcepub fn set_gc_threshold(&self, threshold: usize)
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].
Sourcepub fn gc_threshold(&self) -> usize
pub fn gc_threshold(&self) -> usize
JS_GetGCThreshold, our addition: the threshold the host set.
Sourcepub fn set_interrupt_handler(
&self,
callback: InterruptHandler,
opaque: *mut c_void,
)
pub fn set_interrupt_handler( &self, callback: InterruptHandler, opaque: *mut c_void, )
JS_SetInterruptHandler.
Sourcepub fn interrupt_handler(
&self,
) -> Option<(unsafe extern "C" fn(*mut JsRuntime, *mut c_void) -> c_int, *mut c_void)>
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.
Sourcepub fn set_can_block(&self, can_block: bool)
pub fn set_can_block(&self, can_block: bool)
JS_SetCanBlock.
Sourcepub fn can_block(&self) -> bool
pub fn can_block(&self) -> bool
Whether a blocking operation is allowed (JS_SetCanBlock’s answer).
Sourcepub fn module_loader_hooks(&self) -> Option<ModuleLoaderHooks>
pub fn module_loader_hooks(&self) -> Option<ModuleLoaderHooks>
JS_SetModuleLoaderFunc/JS_SetModuleLoaderFunc2’s state.
Sourcepub fn set_module_loader_hooks(&self, hooks: ModuleLoaderHooks)
pub fn set_module_loader_hooks(&self, hooks: ModuleLoaderHooks)
Record the module loader hooks.
Sourcepub fn live_contexts(&self) -> Vec<*mut JsContext>
pub fn live_contexts(&self) -> Vec<*mut JsContext>
Every live context, for the API functions that take a JSRuntime *.
Sourcepub fn engine_ptr(&self) -> *const Runtime
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.
Sourcepub fn strip_info(&self) -> c_int
pub fn strip_info(&self) -> c_int
JS_SetStripInfo’s recorded flags.
Sourcepub fn set_strip_info(&self, flags: c_int)
pub fn set_strip_info(&self, flags: c_int)
Record the strip-info flags.
Sourcepub fn define_class(&self, id: ClassId, decl: ClassDecl) -> bool
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.
Sourcepub fn class(&self, id: ClassId) -> Option<Rc<ClassDecl>>
pub fn class(&self, id: ClassId) -> Option<Rc<ClassDecl>>
The class registered under id, if any.
Sourcepub unsafe fn adopt_for_session(&self, context: *mut JsContext)
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.