Trait HostImportModuleWithPhaseDynamicallyCallback

Source
pub trait HostImportModuleWithPhaseDynamicallyCallback: UnitType + for<'s> FnOnce(&mut HandleScope<'s>, Local<'s, Data>, Local<'s, Value>, Local<'s, String>, ModuleImportPhase, Local<'s, FixedArray>) -> Option<Local<'s, Promise>> {
    // Required method
    fn to_c_fn(
        self,
    ) -> for<'s> unsafe extern "C" fn(Local<'s, Context>, Local<'s, Data>, Local<'s, Value>, Local<'s, String>, ModuleImportPhase, Local<'s, FixedArray>) -> *mut Promise;
}
Expand description

HostImportModuleWithPhaseDynamicallyCallback is called when we require the embedder to load a module with a specific phase. This is used as part of the dynamic import syntax.

The referrer contains metadata about the script/module that calls import.

The specifier is the name of the module that should be imported.

The phase is the phase of the import requested.

The import_attributes are import attributes for this request in the form: [key1, value1, key2, value2, …] where the keys and values are of type v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and returned from ModuleRequest::GetImportAttributes(), this array does not contain the source Locations of the attributes.

The Promise returned from this function is forwarded to userland JavaScript. The embedder must resolve this promise according to the phase requested:

  • For ModuleImportPhase::kSource, the promise must be resolved with a compiled ModuleSource object, or rejected with a SyntaxError if the module does not support source representation.
  • For ModuleImportPhase::kEvaluation, the promise must be resolved with a ModuleNamespace object of a module that has been compiled, instantiated, and evaluated.

In case of an exception, the embedder must reject this promise with the exception. If the promise creation itself fails (e.g. due to stack overflow), the embedder must propagate that exception by returning an empty MaybeLocal.

This callback is still experimental and is only invoked for source phase imports.

Required Methods§

Source

fn to_c_fn( self, ) -> for<'s> unsafe extern "C" fn(Local<'s, Context>, Local<'s, Data>, Local<'s, Value>, Local<'s, String>, ModuleImportPhase, Local<'s, FixedArray>) -> *mut Promise

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F> HostImportModuleWithPhaseDynamicallyCallback for F
where F: UnitType + for<'s> FnOnce(&mut HandleScope<'s>, Local<'s, Data>, Local<'s, Value>, Local<'s, String>, ModuleImportPhase, Local<'s, FixedArray>) -> Option<Local<'s, Promise>>,