Struct rquickjs_core::context::Ctx

source ·
pub struct Ctx<'js> { /* private fields */ }
Expand description

Context in use, passed to Context::with.

Implementations§

source§

impl<'js> Ctx<'js>

source

pub unsafe fn from_ptr_invariant( ctx: NonNull<JSContext>, inv: Invariant<'js> ) -> Self

Create a new Ctx from a pointer to the context and a invariant lifetime.

Safety

User must ensure that a lock was acquired over the runtime and that invariant is a unique lifetime which can’t be coerced to a lifetime outside the scope of the lock of to the lifetime of another runtime.

source

pub fn eval<V: FromJs<'js>, S: Into<Vec<u8>>>(self, source: S) -> Result<V>

Evaluate a script in global context.

source

pub fn eval_with_options<V: FromJs<'js>, S: Into<Vec<u8>>>( self, source: S, options: EvalOptions ) -> Result<V>

Evaluate a script with the given options.

source

pub fn eval_file<V: FromJs<'js>, P: AsRef<Path>>(self, path: P) -> Result<V>

Evaluate a script directly from a file.

source

pub fn eval_file_with_options<V: FromJs<'js>, P: AsRef<Path>>( self, path: P, options: EvalOptions ) -> Result<V>

source

pub fn compile<N, S>(self, name: N, source: S) -> Result<Module<'js>>where N: Into<Vec<u8>>, S: Into<Vec<u8>>,

Compile a module for later use.

source

pub fn globals(self) -> Object<'js>

Returns the global object of this context.

source

pub fn catch(self) -> Value<'js>

Returns the last raised javascript exception, if there is no exception the javascript value null is returned.

Usage
if let Err(Error::Exception) = ctx.eval::<(),_>("throw 3"){
    assert_eq!(ctx.catch().as_int(),Some(3));
}
source

pub fn throw(self, value: Value<'js>) -> Error

Throws a javascript value as a new exception. Always returns Error::Exception;

source

pub fn promise(self) -> Result<(Object<'js>, Function<'js>, Function<'js>)>

Creates promise and resolving functions.

source

pub fn spawn<F>(&self, future: F)where F: Future<Output = ()> + 'js,

Available on crate feature futures only.

Spawn future using configured async runtime

Trait Implementations§

source§

impl<'js> Clone for Ctx<'js>

source§

fn clone(&self) -> Ctx<'js>

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<'js> Debug for Ctx<'js>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'js> Copy for Ctx<'js>

source§

impl Send for Ctx<'_>

Auto Trait Implementations§

§

impl<'js> RefUnwindSafe for Ctx<'js>

§

impl<'js> !Sync for Ctx<'js>

§

impl<'js> Unpin for Ctx<'js>

§

impl<'js> !UnwindSafe for Ctx<'js>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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