Struct boa_engine::module::Module
source · pub struct Module { /* private fields */ }
Expand description
ECMAScript’s Abstract module record.
Implementations§
source§impl Module
impl Module
sourcepub fn parse<R: ReadChar>(
src: Source<'_, R>,
realm: Option<Realm>,
context: &mut Context
) -> JsResult<Self>
pub fn parse<R: ReadChar>( src: Source<'_, R>, realm: Option<Realm>, context: &mut Context ) -> JsResult<Self>
Abstract operation ParseModule ( sourceText, realm, hostDefined )
.
Parses the provided src
as an ECMAScript module, returning an error if parsing fails.
sourcepub fn synthetic(
export_names: &[JsString],
evaluation_steps: SyntheticModuleInitializer,
realm: Option<Realm>,
context: &mut Context
) -> Self
pub fn synthetic( export_names: &[JsString], evaluation_steps: SyntheticModuleInitializer, realm: Option<Realm>, context: &mut Context ) -> Self
Abstract operation CreateSyntheticModule ( exportNames, evaluationSteps, realm )
.
Creates a new Synthetic Module from its list of exported names, its evaluation steps and optionally a root realm.
sourcepub fn host_defined(&self) -> &HostDefined
pub fn host_defined(&self) -> &HostDefined
Returns the ECMAScript specification
defined \[\[HostDefined\]\]
field of the Module
.
sourcepub fn load(&self, context: &mut Context) -> JsPromise
pub fn load(&self, context: &mut Context) -> JsPromise
Abstract method LoadRequestedModules ( [ hostDefined ] )
.
Prepares the module for linking by loading all its module dependencies. Returns a JsPromise
that will resolve when the loading process either completes or fails.
sourcepub fn link(&self, context: &mut Context) -> JsResult<()>
pub fn link(&self, context: &mut Context) -> JsResult<()>
Abstract method Link()
.
Prepares this module for evaluation by resolving all its module dependencies and initializing its environment.
§Note
This must only be called if the JsPromise
returned by Module::load
has fulfilled.
sourcepub fn evaluate(&self, context: &mut Context) -> JsPromise
pub fn evaluate(&self, context: &mut Context) -> JsPromise
Abstract method Evaluate()
.
Evaluates this module, returning a promise for the result of the evaluation of this module and its dependencies. If the promise is rejected, hosts are expected to handle the promise rejection and rethrow the evaluation error.
§Note
This must only be called if the Module::link
method finished successfully.
sourcepub fn load_link_evaluate(&self, context: &mut Context) -> JsPromise
pub fn load_link_evaluate(&self, context: &mut Context) -> JsPromise
Loads, links and evaluates this module, returning a promise that will resolve after the module finishes its lifecycle.
§Examples
let loader = Rc::new(SimpleModuleLoader::new(Path::new(".")).unwrap());
let mut context = &mut Context::builder()
.module_loader(loader.clone())
.build()
.unwrap();
let source = Source::from_bytes("1 + 3");
let module = Module::parse(source, None, context).unwrap();
loader.insert(Path::new("main.mjs").to_path_buf(), module.clone());
let promise = module.load_link_evaluate(context);
context.run_jobs();
assert_eq!(
promise.state(),
PromiseState::Fulfilled(JsValue::undefined())
);
sourcepub fn namespace(&self, context: &mut Context) -> JsObject
pub fn namespace(&self, context: &mut Context) -> JsObject
Abstract operation GetModuleNamespace ( module )
.
Gets the Module Namespace Object that represents this module’s exports.
Trait Implementations§
source§impl PartialEq for Module
impl PartialEq for Module
source§impl Trace for Module
impl Trace for Module
source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize
on this object and all
contained subobjects.impl Eq for Module
Auto Trait Implementations§
impl !RefUnwindSafe for Module
impl !Send for Module
impl !Sync for Module
impl Unpin for Module
impl !UnwindSafe for Module
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.