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

HostImportModuleDynamicallyCallback is called when we require the embedder to load a module. 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 import_assertions are import assertions 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::GetImportAssertions(), this array does not contain the source Locations of the assertions.

The embedder must compile, instantiate, evaluate the Module, and obtain its namespace object.

The Promise returned from this function is forwarded to userland JavaScript. The embedder must resolve this promise with the module namespace object. 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.

Example

fn host_import_module_dynamically_callback_example<'s>(
  scope: &mut v8::HandleScope<'s>,
  host_defined_options: v8::Local<'s, v8::Data>,
  resource_name: v8::Local<'s, v8::Value>,
  specifier: v8::Local<'s, v8::String>,
  import_assertions: v8::Local<'s, v8::FixedArray>,
) -> Option<v8::Local<'s, v8::Promise>> {
  todo!()
}

Required Methods§

Implementors§