Trait deno_core::ModuleLoader

source ·
pub trait ModuleLoader {
    // Required methods
    fn resolve(
        &self,
        specifier: &str,
        referrer: &str,
        kind: ResolutionKind,
    ) -> Result<ModuleSpecifier, Error>;
    fn load(
        &self,
        module_specifier: &ModuleSpecifier,
        maybe_referrer: Option<&ModuleSpecifier>,
        is_dyn_import: bool,
        requested_module_type: RequestedModuleType,
    ) -> ModuleLoadResponse;

    // Provided methods
    fn prepare_load(
        &self,
        _module_specifier: &ModuleSpecifier,
        _maybe_referrer: Option<String>,
        _is_dyn_import: bool,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> { ... }
    fn code_cache_ready(
        &self,
        _module_specifier: ModuleSpecifier,
        _hash: u64,
        _code_cache: &[u8],
    ) -> Pin<Box<dyn Future<Output = ()>>> { ... }
    fn get_source_map(&self, _file_name: &str) -> Option<Vec<u8>> { ... }
    fn get_source_mapped_source_line(
        &self,
        _file_name: &str,
        _line_number: usize,
    ) -> Option<String> { ... }
    fn get_host_defined_options<'s>(
        &self,
        _scope: &mut HandleScope<'s>,
        _name: &str,
    ) -> Option<Local<'s, Data>> { ... }
}

Required Methods§

source

fn resolve( &self, specifier: &str, referrer: &str, kind: ResolutionKind, ) -> Result<ModuleSpecifier, Error>

Returns an absolute URL. When implementing an spec-complaint VM, this should be exactly the algorithm described here: https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier

ResolutionKind::MainModule can be used to resolve from current working directory or apply import map for child imports.

ResolutionKind::DynamicImport can be used to check permissions or deny dynamic imports altogether.

source

fn load( &self, module_specifier: &ModuleSpecifier, maybe_referrer: Option<&ModuleSpecifier>, is_dyn_import: bool, requested_module_type: RequestedModuleType, ) -> ModuleLoadResponse

Given ModuleSpecifier, load its source code.

is_dyn_import can be used to check permissions or deny dynamic imports altogether.

Provided Methods§

source

fn prepare_load( &self, _module_specifier: &ModuleSpecifier, _maybe_referrer: Option<String>, _is_dyn_import: bool, ) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>

This hook can be used by implementors to do some preparation work before starting loading of modules.

For example implementor might download multiple modules in parallel and transpile them to final JS sources before yielding control back to the runtime.

It’s not required to implement this method.

source

fn code_cache_ready( &self, _module_specifier: ModuleSpecifier, _hash: u64, _code_cache: &[u8], ) -> Pin<Box<dyn Future<Output = ()>>>

Called when new v8 code cache is available for this module. Implementors can store the provided code cache for future executions of the same module.

It’s not required to implement this method.

source

fn get_source_map(&self, _file_name: &str) -> Option<Vec<u8>>

Returns a source map for given file_name.

This function will soon be deprecated or renamed.

source

fn get_source_mapped_source_line( &self, _file_name: &str, _line_number: usize, ) -> Option<String>

source

fn get_host_defined_options<'s>( &self, _scope: &mut HandleScope<'s>, _name: &str, ) -> Option<Local<'s, Data>>

Implementors can attach arbitrary data to scripts and modules by implementing this method. V8 currently requires that the returned data be a v8::PrimitiveArray.

Implementors§