pub struct Module(/* private fields */);Expand description
A compiled JavaScript module.
Implementations§
Source§impl Module
impl Module
Sourcepub fn get_status(&self) -> ModuleStatus
pub fn get_status(&self) -> ModuleStatus
Returns the module’s current status.
Sourcepub fn get_exception<'o>(&self) -> Local<'o, Value>
pub fn get_exception<'o>(&self) -> Local<'o, Value>
For a module in kErrored status, this returns the corresponding exception.
Sourcepub fn get_module_requests<'o>(&self) -> Local<'o, FixedArray>
pub fn get_module_requests<'o>(&self) -> Local<'o, FixedArray>
Returns the ModuleRequests for this module.
Sourcepub fn source_offset_to_location(&self, offset: int) -> Location
pub fn source_offset_to_location(&self, offset: int) -> Location
For the given source text offset in this module, returns the corresponding Location with line and column numbers.
Sourcepub fn get_identity_hash(&self) -> NonZeroI32
pub fn get_identity_hash(&self) -> NonZeroI32
Returns the V8 hash value for this value. The current implementation uses a hidden property to store the identity hash.
The return value will never be 0. Also, it is not guaranteed to be unique.
Sourcepub fn script_id(&self) -> Option<int>
pub fn script_id(&self) -> Option<int>
Returns the underlying script’s id.
The module must be a SourceTextModule and must not have an Errored status.
Sourcepub fn get_module_namespace<'o>(&self) -> Local<'o, Value>
pub fn get_module_namespace<'o>(&self) -> Local<'o, Value>
Returns the namespace object of this module.
The module’s status must be at least kInstantiated.
Sourcepub fn get_module_namespace_with_phase<'o>(
&self,
phase: ModuleImportPhase,
) -> Local<'o, Value>
pub fn get_module_namespace_with_phase<'o>( &self, phase: ModuleImportPhase, ) -> Local<'o, Value>
Returns the namespace object of this module for the given import phase.
For ModuleImportPhase::kDefer, returns a deferred namespace object that
triggers module evaluation on first property access.
The module’s status must be at least kInstantiated.
Sourcepub fn evaluate_for_import_defer<'s>(
&self,
scope: &PinScope<'s, '_>,
) -> Option<Local<'s, Value>>
pub fn evaluate_for_import_defer<'s>( &self, scope: &PinScope<'s, '_>, ) -> Option<Local<'s, Value>>
Evaluates the module for deferred import, gathering async transitive dependencies eagerly so that deferred namespace access can be synchronous.
Returns a Promise that resolves when all async transitive dependencies have been evaluated. The module itself is NOT evaluated until its deferred namespace is first accessed.
This is used to implement import.defer() dynamic imports.
Sourcepub fn instantiate_module<'s, 'i>(
&self,
scope: &PinScope<'s, 'i>,
callback: impl MapFnTo<ResolveModuleCallback<'s>>,
) -> Option<bool>
pub fn instantiate_module<'s, 'i>( &self, scope: &PinScope<'s, 'i>, callback: impl MapFnTo<ResolveModuleCallback<'s>>, ) -> Option<bool>
Instantiates the module and its dependencies.
Returns an empty Maybe
Sourcepub fn instantiate_module2<'s, 'i>(
&self,
scope: &PinScope<'s, 'i>,
callback: impl MapFnTo<ResolveModuleCallback<'s>>,
source_callback: impl MapFnTo<ResolveSourceCallback<'s>>,
) -> Option<bool>
pub fn instantiate_module2<'s, 'i>( &self, scope: &PinScope<'s, 'i>, callback: impl MapFnTo<ResolveModuleCallback<'s>>, source_callback: impl MapFnTo<ResolveSourceCallback<'s>>, ) -> Option<bool>
Instantiates the module and its dependencies.
Returns an empty Maybe
Sourcepub fn evaluate<'s>(&self, scope: &PinScope<'s, '_>) -> Option<Local<'s, Value>>
pub fn evaluate<'s>(&self, scope: &PinScope<'s, '_>) -> Option<Local<'s, Value>>
Evaluates the module and its dependencies.
If status is kInstantiated, run the module’s code. On success, set status to kEvaluated and return the completion value; on failure, set status to kErrored and propagate the thrown exception (which is then also available via |GetException|).
Sourcepub fn is_graph_async(&self) -> bool
pub fn is_graph_async(&self) -> bool
Returns whether this module or any of its requested modules is async, i.e. contains top-level await.
The module’s status must be at least kInstantiated.
Sourcepub fn is_source_text_module(&self) -> bool
pub fn is_source_text_module(&self) -> bool
Returns whether the module is a SourceTextModule.
Sourcepub fn is_synthetic_module(&self) -> bool
pub fn is_synthetic_module(&self) -> bool
Returns whether the module is a SyntheticModule.
Sourcepub fn create_synthetic_module<'s, 'i>(
scope: &PinScope<'s, 'i>,
module_name: Local<'_, String>,
export_names: &[Local<'_, String>],
evaluation_steps: impl MapFnTo<SyntheticModuleEvaluationSteps<'s>>,
) -> Local<'s, Module>
pub fn create_synthetic_module<'s, 'i>( scope: &PinScope<'s, 'i>, module_name: Local<'_, String>, export_names: &[Local<'_, String>], evaluation_steps: impl MapFnTo<SyntheticModuleEvaluationSteps<'s>>, ) -> Local<'s, Module>
Creates a new SyntheticModule with the specified export names, where evaluation_steps will be executed upon module evaluation. export_names must not contain duplicates. module_name is used solely for logging/debugging and doesn’t affect module behavior.
Sourcepub fn set_synthetic_module_export<'s>(
&self,
scope: &mut PinScope<'s, '_>,
export_name: Local<'s, String>,
export_value: Local<'s, Value>,
) -> Option<bool>
pub fn set_synthetic_module_export<'s>( &self, scope: &mut PinScope<'s, '_>, export_name: Local<'s, String>, export_value: Local<'s, Value>, ) -> Option<bool>
Set this module’s exported value for the name export_name to the specified export_value. This method must be called only on Modules created via create_synthetic_module. An error will be thrown if export_name is not one of the export_names that were passed in that create_synthetic_module call. Returns Some(true) on success, None if an error was thrown.
pub fn get_unbound_module_script<'s>( &self, scope: &PinScope<'s, '_>, ) -> Local<'s, UnboundModuleScript>
Sourcepub fn get_stalled_top_level_await_message<'s>(
&self,
scope: &PinScope<'s, '_, ()>,
) -> Vec<(Local<'s, Module>, Local<'s, Message>)>
pub fn get_stalled_top_level_await_message<'s>( &self, scope: &PinScope<'s, '_, ()>, ) -> Vec<(Local<'s, Module>, Local<'s, Message>)>
Search the modules requested directly or indirectly by the module for any top-level await that has not yet resolved. If there is any, the returned vector contains a tuple of the unresolved module and a message with the pending top-level await. An embedder may call this before exiting to improve error messages.
Methods from Deref<Target = Data>§
Sourcepub fn is_big_int(&self) -> bool
pub fn is_big_int(&self) -> bool
Returns true if this data is a BigInt.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if this data is a Boolean.
Sourcepub fn is_context(&self) -> bool
pub fn is_context(&self) -> bool
Returns true if this data is a Context.
Sourcepub fn is_fixed_array(&self) -> bool
pub fn is_fixed_array(&self) -> bool
Returns true if this data is a FixedArray.
Sourcepub fn is_function_template(&self) -> bool
pub fn is_function_template(&self) -> bool
Returns true if this data is a FunctionTemplate.
Sourcepub fn is_module_request(&self) -> bool
pub fn is_module_request(&self) -> bool
Returns true if this data is a ModuleRequest.
Sourcepub fn is_object_template(&self) -> bool
pub fn is_object_template(&self) -> bool
Returns true if this data is a ObjectTemplate.
Sourcepub fn is_primitive(&self) -> bool
pub fn is_primitive(&self) -> bool
Returns true if this data is a Primitive.
Sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Returns true if this data is a Private.