pub struct JsRealm(_);
Expand description
A representation of a JavaScript realm tied to a JsRuntime
, that allows
execution in the realm’s context.
A JsRealm
instance does not hold ownership of its corresponding realm,
so they can be created and dropped as needed. And since every operation on
them requires passing a mutable reference to the JsRuntime
, multiple
JsRealm
instances won’t overlap.
Panics
Every method of JsRealm
will panic if you call if with a reference to a
JsRuntime
other than the one that corresponds to the current context.
Lifetime of the realm
A JsRealm
instance will keep the underlying V8 context alive even if it
would have otherwise been garbage collected.
Implementations
sourceimpl JsRealm
impl JsRealm
pub fn new(context: Global<Context>) -> Self
pub fn context(&self) -> &Global<Context>
pub fn handle_scope<'s>(&self, runtime: &'s mut JsRuntime) -> HandleScope<'s>
pub fn global_object<'s>(&self, runtime: &'s mut JsRuntime) -> Local<'s, Object>
sourcepub fn execute_script(
&self,
runtime: &mut JsRuntime,
name: &str,
source_code: &str
) -> Result<Global<Value>, Error>
pub fn execute_script(
&self,
runtime: &mut JsRuntime,
name: &str,
source_code: &str
) -> Result<Global<Value>, Error>
Executes traditional JavaScript code (traditional = not ES modules) in the realm’s context.
name
can be a filepath or any other string, eg.
- “/some/file/path.js”
- “
” - “[native code]”
The same name
value can be used for multiple executions.
Error
can usually be downcast to JsError
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for JsRealm
impl !Send for JsRealm
impl !Sync for JsRealm
impl Unpin for JsRealm
impl !UnwindSafe for JsRealm
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more