Skip to main content

DynModuleLoader

Trait DynModuleLoader 

Source
pub trait DynModuleLoader: Any {
    // Required method
    fn load_imported_module<'context0, 'context1, 'dynify>(
        self: Rc<Self>,
        referrer: Referrer,
        request: ModuleRequest,
        context: &'context0 RefCell<&'context1 mut Context>,
    ) -> Fn<(RcSelf, Referrer, ModuleRequest, &'context0 RefCell<&'context1 mut Context>), dyn Future<Output = JsResult<Module>> + 'dynify>
       where Self: 'dynify,
             'context0: 'dynify,
             'context1: 'dynify;

    // Provided method
    fn init_import_meta(
        self: Rc<Self>,
        import_meta: &JsObject,
        module: &Module,
        context: &mut Context,
    ) { ... }
}
Expand description

Module loading related host hooks.

This trait allows to customize the behaviour of the engine on module load requests and import.meta requests.

Required Methods§

Source

fn load_imported_module<'context0, 'context1, 'dynify>( self: Rc<Self>, referrer: Referrer, request: ModuleRequest, context: &'context0 RefCell<&'context1 mut Context>, ) -> Fn<(RcSelf, Referrer, ModuleRequest, &'context0 RefCell<&'context1 mut Context>), dyn Future<Output = JsResult<Module>> + 'dynify>
where Self: 'dynify, 'context0: 'dynify, 'context1: 'dynify,

Host hook HostLoadImportedModule ( referrer, specifier, hostDefined, payload ).

This hook allows to customize the module loading functionality of the engine. Technically, this should call the FinishLoadingImportedModule operation, but this simpler API just provides an async method that replaces FinishLoadingImportedModule.

§Requirements
  • The host environment must perform FinishLoadingImportedModule(referrer, specifier, payload, result), where result is either a normal completion containing the loaded Module Record or a throw completion, either synchronously or asynchronously. This is replaced by simply returning from the method.
  • If this operation is called multiple times with the same (referrer, specifier) pair and it performs FinishLoadingImportedModule(referrer, specifier, payload, result) where result is a normal completion, then it must perform FinishLoadingImportedModule(referrer, specifier, payload, result) with the same result each time.
  • The operation must treat payload as an opaque value to be passed through to FinishLoadingImportedModule. (can be ignored)

Provided Methods§

Source

fn init_import_meta( self: Rc<Self>, import_meta: &JsObject, module: &Module, context: &mut Context, )

Host hooks HostGetImportMetaProperties ( moduleRecord ) and HostFinalizeImportMeta ( importMeta, moduleRecord ).

This unifies both APIs into a single hook that can be overridden on both cases. The most common usage is to add properties to import_meta and return, but this also allows modifying the import meta object in more exotic ways before exposing it to ECMAScript code.

The default implementation of HostGetImportMetaProperties is to return a new empty List.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<ModuleLoaderImplementor: ModuleLoader> DynModuleLoader for ModuleLoaderImplementor