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
thread_safe_handle: Arc<RwLock<Option<*mut JSContext>>>
An Option
that holds the same pointer as cx
.
This is shared with all ThreadSafeJSContext
s, so
they can detect when it’s destroyed on the main thread.
Implementations§
source§impl Runtime
impl Runtime
sourcepub fn thread_safe_js_context(&self) -> ThreadSafeJSContext
pub fn thread_safe_js_context(&self) -> ThreadSafeJSContext
Create a ThreadSafeJSContext
that can detect when this Runtime
is destroyed.
sourcepub fn new(engine: JSEngineHandle) -> Runtime
pub fn new(engine: JSEngineHandle) -> Runtime
Creates a new JSContext
.
sourcepub fn prepare_for_new_child(&self) -> ParentRuntime
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.
sourcepub unsafe fn create_with_parent(parent: ParentRuntime) -> Runtime
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.
unsafe fn create( engine: JSEngineHandle, parent: Option<ParentRuntime>, ) -> Runtime
pub fn evaluate_script( &self, glob: HandleObject<'_>, script: &str, filename: &str, line_num: u32, rval: MutableHandleValue<'_>, ) -> Result<(), ()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl Unpin for Runtime
impl UnwindSafe for Runtime
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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