pub struct WasmModuleCompilation(/* private fields */);Expand description
An interface for asynchronous WebAssembly module compilation, to be used e.g. for implementing source phase imports.
Note: This interface is experimental and can change or be removed without notice.
Implementations§
Source§impl WasmModuleCompilation
impl WasmModuleCompilation
Sourcepub fn new() -> Self
pub fn new() -> Self
Start an asynchronous module compilation. This can be called on any thread.
Sourcepub fn on_bytes_received(&mut self, data: &[u8])
pub fn on_bytes_received(&mut self, data: &[u8])
Pass a new chunk of bytes to WebAssembly compilation. The buffer is owned by the caller and will not be accessed after this call returns. Can be called from any thread.
Sourcepub fn finish(
self,
scope: &mut PinScope<'_, '_>,
caching_callback: Option<unsafe extern "C" fn(*mut ModuleCachingInterface)>,
resolution_callback: impl FnOnce(&Isolate, Result<Local<'_, WasmModuleObject>, Local<'_, Value>>) + 'static,
)
pub fn finish( self, scope: &mut PinScope<'_, '_>, caching_callback: Option<unsafe extern "C" fn(*mut ModuleCachingInterface)>, resolution_callback: impl FnOnce(&Isolate, Result<Local<'_, WasmModuleObject>, Local<'_, Value>>) + 'static, )
Finish compilation. Must be called on the main thread after all bytes
were passed to Self::on_bytes_received.
The resolution_callback will eventually be called with either the
compiled module or a compilation error. The callback receives &Isolate
so that crate::Global handles can be created from the Local
handles to persist them beyond the callback.
Must not be called after Self::abort.
Sourcepub fn abort(self)
pub fn abort(self)
Abort compilation. Can be called from any thread.
Must not be called repeatedly, or after Self::finish.
Sourcepub fn set_has_compiled_module_bytes(&mut self)
pub fn set_has_compiled_module_bytes(&mut self)
Mark that the embedder has (potentially) cached compiled module bytes
(i.e. a serialized CompiledWasmModule) that could match this
compilation request. This will cause V8 to skip streaming compilation.
The embedder should then pass a caching callback to Self::finish.
Sourcepub fn set_more_functions_can_be_serialized_callback(
&mut self,
callback: impl Fn(CompiledWasmModule) + Send + 'static,
)
pub fn set_more_functions_can_be_serialized_callback( &mut self, callback: impl Fn(CompiledWasmModule) + Send + 'static, )
Sets a callback which is called whenever a significant number of new functions are ready for serialization.
Sourcepub fn set_url(&mut self, url: &str)
pub fn set_url(&mut self, url: &str)
Sets the UTF-8 encoded source URL for the Script object. This must
be called before Self::finish.