Struct rquickjs_core::Module
source · pub struct Module<'js, T = Declared> { /* private fields */ }
Expand description
A JavaScript module.
Implementations§
source§impl<'js> Module<'js, Declared>
impl<'js> Module<'js, Declared>
sourcepub fn declare<N, S>(
ctx: Ctx<'js>,
name: N,
source: S
) -> Result<Module<'js, Declared>>
pub fn declare<N, S>( ctx: Ctx<'js>, name: N, source: S ) -> Result<Module<'js, Declared>>
Declare a module but don’t evaluate it.
sourcepub fn declare_def<D, N>(
ctx: Ctx<'js>,
name: N
) -> Result<Module<'js, Declared>>
pub fn declare_def<D, N>( ctx: Ctx<'js>, name: N ) -> Result<Module<'js, Declared>>
Declare a rust native module but don’t evaluate it.
sourcepub fn evaluate<N, S>(ctx: Ctx<'js>, name: N, source: S) -> Result<Promise<'js>>
pub fn evaluate<N, S>(ctx: Ctx<'js>, name: N, source: S) -> Result<Promise<'js>>
Evaluate the source of a module.
This function returns a promise which resolved when the modules was fully compiled and returns undefined.
Since QuickJS doesn’t give us a way to retrieve the module if we immediately evaluate a
modules source this function doesn’t return a module object.
If the module is required, you should first declare it with Module::declare
and then call Module::eval
on the
returned module.
sourcepub fn evaluate_def<D, N>(
ctx: Ctx<'js>,
name: N
) -> Result<(Module<'js, Evaluated>, Promise<'js>)>
pub fn evaluate_def<D, N>( ctx: Ctx<'js>, name: N ) -> Result<(Module<'js, Evaluated>, Promise<'js>)>
Declares a module in the runtime and evaluates it.
sourcepub unsafe fn load(ctx: Ctx<'js>, bytes: &[u8]) -> Result<Module<'js, Declared>>
pub unsafe fn load(ctx: Ctx<'js>, bytes: &[u8]) -> Result<Module<'js, Declared>>
Load a module from quickjs bytecode.
§Safety
User must ensure that bytes handed to this function contain valid bytecode.
sourcepub unsafe fn from_load_fn<N>(
ctx: Ctx<'js>,
name: N,
load_fn: ModuleLoadFn
) -> Result<Module<'js, Declared>>
pub unsafe fn from_load_fn<N>( ctx: Ctx<'js>, name: N, load_fn: ModuleLoadFn ) -> Result<Module<'js, Declared>>
Load a module from a raw module loading function.
§Safety
The soundness of this function depends completely on if load_fn is implemented correctly. THe load_fn function must return a pointer to a valid module loaded with the given context.
sourcepub fn eval(self) -> Result<(Module<'js, Evaluated>, Promise<'js>)>
pub fn eval(self) -> Result<(Module<'js, Evaluated>, Promise<'js>)>
Evaluate the module.
Returns the module as being evaluated and a promise which resolves when the module has finished evaluating. The return value of the promise is the JavaScript value undefined.
source§impl<'js, Evaluated> Module<'js, Evaluated>
impl<'js, Evaluated> Module<'js, Evaluated>
sourcepub fn write_le(&self) -> Result<Vec<u8>>
pub fn write_le(&self) -> Result<Vec<u8>>
Write object bytecode for the module in little endian format.
sourcepub fn write_be(&self) -> Result<Vec<u8>>
pub fn write_be(&self) -> Result<Vec<u8>>
Write object bytecode for the module in big endian format.
sourcepub fn write(&self, swap_endianess: bool) -> Result<Vec<u8>>
pub fn write(&self, swap_endianess: bool) -> Result<Vec<u8>>
Write object bytecode for the module.
swap_endianess
swaps the endianness of the bytecode, if true, from native to the other
kind. Use if the bytecode is meant for a target with a different endianness than the
current.
sourcepub fn namespace(&self) -> Result<Object<'js>>
pub fn namespace(&self) -> Result<Object<'js>>
Returns the module namespace, an object containing all the module exported values.
sourcepub fn into_declared(self) -> Module<'js, Declared>
pub fn into_declared(self) -> Module<'js, Declared>
Change the module back to being only declared.
This is always safe to do since calling eval again on an already evaluated module is safe.
Trait Implementations§
Auto Trait Implementations§
impl<'js, T> Freeze for Module<'js, T>
impl<'js, T> RefUnwindSafe for Module<'js, T>where
T: RefUnwindSafe,
impl<'js, T = Declared> !Send for Module<'js, T>
impl<'js, T = Declared> !Sync for Module<'js, T>
impl<'js, T> Unpin for Module<'js, T>where
T: Unpin,
impl<'js, T = Declared> !UnwindSafe for Module<'js, T>
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