Struct mozjs::rust::Runtime

source ·
pub struct Runtime {
    cx: *mut JSContext,
    engine: JSEngineHandle,
    _parent_child_count: Option<Arc<()>>,
    outstanding_children: Arc<()>,
}
Expand description

A wrapper for the JSContext structure in SpiderMonkey.

Fields§

§cx: *mut JSContext

Raw pointer to the underlying SpiderMonkey context.

§engine: JSEngineHandle

The engine that this runtime is associated with.

§_parent_child_count: Option<Arc<()>>

If this Runtime was created with a parent, this member exists to ensure that that parent’s count of outstanding children (see [outstanding_children]) remains accurate and will be automatically decreased when this Runtime value is dropped.

§outstanding_children: Arc<()>

The strong references to this value represent the number of child runtimes that have been created using this Runtime as a parent. Since Runtime values must be associated with a particular thread, we cannot simply use Arc to represent the resulting ownership graph and risk destroying a Runtime on the wrong thread.

Implementations§

source§

impl Runtime

source

pub fn get() -> *mut JSContext

Get the JSContext for this thread.

source

pub fn new(engine: JSEngineHandle) -> Runtime

Creates a new JSContext.

source

pub fn prepare_for_new_child(&self) -> ParentRuntime

Signal that a new child runtime will be created in the future, and ensure that this runtime will not allow itself to be destroyed before the new child runtime. Returns a handle that can be passed to create_with_parent in order to create a new runtime on another thread that is associated with this runtime.

source

pub unsafe fn create_with_parent(parent: ParentRuntime) -> Runtime

Creates a new JSContext with a parent runtime. If the parent does not outlive the new runtime, its destructor will assert.

Unsafety: If panicking does not abort the program, any threads with child runtimes will continue executing after the thread with the parent runtime panics, but they will be in an invalid and undefined state.

source

unsafe fn create( engine: JSEngineHandle, parent: Option<ParentRuntime> ) -> Runtime

source

pub fn rt(&self) -> *mut JSRuntime

Returns the JSRuntime object.

source

pub fn cx(&self) -> *mut JSContext

Returns the JSContext object.

source

pub fn evaluate_script( &self, glob: HandleObject<'_>, script: &str, filename: &str, line_num: u32, rval: MutableHandleValue<'_> ) -> Result<(), ()>

Trait Implementations§

source§

impl Drop for Runtime

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Traceable for Runtime

source§

unsafe fn trace(&self, _: *mut JSTracer)

Trace self.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.