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

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 be downcast to a type that exposes additional information about the V8 exception. By default this type is JsError, however it may be a different type if RuntimeOptions::js_error_create_fn has been set.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.