Struct mozjs::rust::Runtime

source ·
pub struct Runtime {
    cx: *mut JSContext,
    engine: JSEngineHandle,
    _parent_child_count: Option<Arc<()>>,
    outstanding_children: Arc<()>,
    thread_safe_handle: Arc<RwLock<Option<*mut JSContext>>>,
}
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.

§thread_safe_handle: Arc<RwLock<Option<*mut JSContext>>>

An Option that holds the same pointer as cx. This is shared with all ThreadSafeJSContexts, so they can detect when it’s destroyed on the main thread.

Implementations§

source§

impl Runtime

source

pub fn get() -> *mut JSContext

Get the JSContext for this thread.

source

pub fn thread_safe_js_context(&self) -> ThreadSafeJSContext

Create a ThreadSafeJSContext that can detect when this Runtime is destroyed.

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 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> Filterable for T

source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T