Struct rquickjs::Context

source ·
pub struct Context(/* private fields */);
Expand description

A single execution context with its own global variables and stack.

Can share objects with other contexts of the same runtime.

Implementations§

source§

impl Context

source

pub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: Runtime) -> Context

Create a unused context from a raw context pointer.

§Safety

Pointer must point to a context from the given runtime. The context must also have valid reference count, one which can be decremented when this object is dropped without going negative.

source

pub fn as_raw(&self) -> NonNull<JSContext>

source

pub fn base(runtime: &Runtime) -> Result<Context, Error>

Creates a base context with only the required functions registered. If additional functions are required use Context::custom, Context::builder or Context::full.

source

pub fn custom<I>(runtime: &Runtime) -> Result<Context, Error>
where I: Intrinsic,

Creates a context with only the required intrinsics registered. If additional functions are required use Context::custom, Context::builder or Context::full.

source

pub fn full(runtime: &Runtime) -> Result<Context, Error>

Creates a context with all standard available intrinsics registered. If precise control is required of which functions are available use Context::custom or Context::builder.

source

pub fn builder() -> ContextBuilder<()>

Create a context builder for creating a context with a specific set of intrinsics

source

pub fn enable_big_num_ext(&self, enable: bool)

source

pub fn runtime(&self) -> &Runtime

Returns the associated runtime

source

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

source

pub fn with<F, R>(&self, f: F) -> R
where F: FnOnce(Ctx<'_>) -> R,

A entry point for manipulating and using JavaScript objects and scripts. The api is structured this way to avoid repeated locking the runtime when ever any function is called. This way the runtime is locked once before executing the callback. Furthermore, this way it is impossible to use values from different runtimes in this context which would otherwise be undefined behavior.

This is the only way to get a Ctx object.

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for Context

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Context

source§

impl Sync for Context

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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> ParallelSend for T
where T: Send,