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 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_promise<S: Into<Vec<u8>>>(&self, source: S) -> Result<Promise<'js>>
pub fn eval_promise<S: Into<Vec<u8>>>(&self, source: S) -> Result<Promise<'js>>
Evaluate a script in global context with top level await support.
This function always returns a promise which resolves to the result of the evaluated expression.
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 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;
sourcepub fn json_parse<S>(&self, json: S) -> Result<Value<'js>>
pub fn json_parse<S>(&self, json: S) -> Result<Value<'js>>
Parse json into a JavaScript value.
sourcepub fn json_parse_ext<S>(
&self,
json: S,
allow_extensions: bool
) -> Result<Value<'js>>
pub fn json_parse_ext<S>( &self, json: S, allow_extensions: bool ) -> Result<Value<'js>>
Parse json into a JavaScript value, possibly allowing extended syntax support.
If allow_extensions is true, this function will allow extended json syntax.
Extended syntax allows comments, single quoted strings, non string property names, trailing
comma’s and hex, oct and binary numbers.
sourcepub fn json_stringify<V>(&self, value: V) -> Result<Option<String<'js>>>where
V: IntoJs<'js>,
pub fn json_stringify<V>(&self, value: V) -> Result<Option<String<'js>>>where
V: IntoJs<'js>,
Stringify a JavaScript value into its JSON representation
sourcepub fn json_stringify_replacer<V, R>(
&self,
value: V,
replacer: R
) -> Result<Option<String<'js>>>
pub fn json_stringify_replacer<V, R>( &self, value: V, replacer: R ) -> Result<Option<String<'js>>>
Stringify a JavaScript value into its JSON representation with a possible replacer.
The replacer is the same as the replacer argument for JSON.stringify.
It is is a function that alters the behavior of the stringification process.
sourcepub fn json_stringify_replacer_space<V, R, S>(
&self,
value: V,
replacer: R,
space: S
) -> Result<Option<String<'js>>>
pub fn json_stringify_replacer_space<V, R, S>( &self, value: V, replacer: R, space: S ) -> Result<Option<String<'js>>>
Stringify a JavaScript value into its JSON representation with a possible replacer and spaces
The replacer is the same as the replacer argument for JSON.stringify.
It is is a function that alters the behavior of the stringification process.
Space is either a number or a string which is used to insert whitespace into the output
string for readability purposes. This behaves the same as the space argument for
JSON.stringify.
sourcepub fn promise(&self) -> Result<(Promise<'js>, Function<'js>, Function<'js>)>
pub fn promise(&self) -> Result<(Promise<'js>, Function<'js>, Function<'js>)>
Creates javascipt promise along with its reject and resolve functions.
sourcepub fn execute_pending_job(&self) -> bool
pub fn execute_pending_job(&self) -> bool
Executes a quickjs job.
Returns wether a job was actually executed. If this function returned false, no job was pending.
sourcepub fn spawn<F>(&self, future: F)
Available on crate feature futures only.
pub fn spawn<F>(&self, future: F)
futures only.Spawn future using configured async runtime
sourcepub unsafe fn from_raw_invariant(
ctx: NonNull<JSContext>,
inv: Invariant<'js>
) -> Self
pub unsafe fn from_raw_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 unsafe fn from_raw(ctx: NonNull<JSContext>) -> Self
pub unsafe fn from_raw(ctx: NonNull<JSContext>) -> 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.
pub fn script_or_module_name(&self, stack_level: isize) -> Option<Atom<'js>>
pub fn run_gc(&self)
Trait Implementations§
source§impl<'js> FromParam<'js> for Ctx<'js>
impl<'js> FromParam<'js> for Ctx<'js>
source§fn param_requirement() -> ParamRequirement
fn param_requirement() -> ParamRequirement
source§fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<Self>
fn from_param<'a>(params: &mut ParamsAccessor<'a, 'js>) -> Result<Self>
impl Send for Ctx<'_>
Auto Trait Implementations§
impl<'js> Freeze for Ctx<'js>
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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