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>
impl<'js> Ctx<'js>
sourcepub unsafe fn from_ptr_invariant(
ctx: NonNull<JSContext>,
inv: Invariant<'js>
) -> Self
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.
sourcepub fn eval<V: FromJs<'js>, S: Into<Vec<u8>>>(self, source: S) -> Result<V>
pub fn eval<V: FromJs<'js>, S: Into<Vec<u8>>>(self, source: S) -> Result<V>
Evaluate a script in global context.
sourcepub fn eval_with_options<V: FromJs<'js>, S: Into<Vec<u8>>>(
self,
source: S,
options: EvalOptions
) -> Result<V>
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.
sourcepub fn eval_file<V: FromJs<'js>, P: AsRef<Path>>(self, path: P) -> Result<V>
pub fn eval_file<V: FromJs<'js>, P: AsRef<Path>>(self, path: P) -> Result<V>
Evaluate a script directly from a file.
pub fn eval_file_with_options<V: FromJs<'js>, P: AsRef<Path>>( self, path: P, options: EvalOptions ) -> Result<V>
sourcepub fn compile<N, S>(self, name: N, source: S) -> Result<Module<'js>>where
N: Into<Vec<u8>>,
S: Into<Vec<u8>>,
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.
sourcepub fn catch(self) -> Value<'js>
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));
}
sourcepub fn throw(self, value: Value<'js>) -> Error
pub fn throw(self, value: Value<'js>) -> Error
Throws a javascript value as a new exception.
Always returns Error::Exception
;
Trait Implementations§
impl<'js> Copy for Ctx<'js>
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> 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
Mutably borrows from an owned value. Read more