mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-17 06:51:24 +00:00
Fix anyref table export in empty modules
This commit fixes an issue previously introduced around handling the anyref table, gracefully handling the case where the source module doesn't actually use the anyref table at all, meaning that the logic around initializing it can be entirely skipped.
This commit is contained in:
@ -623,6 +623,24 @@ impl<'a> Context<'a> {
|
||||
if !self.anyref_enabled {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Make sure to export the `anyref` table for the JS bindings since it
|
||||
// will need to be initialized. If it doesn't exist though then the
|
||||
// module must not use it, so we skip it.
|
||||
let table = self
|
||||
.module
|
||||
.tables
|
||||
.iter()
|
||||
.find(|t| match t.kind {
|
||||
walrus::TableKind::Anyref(_) => true,
|
||||
_ => false,
|
||||
});
|
||||
let table = match table {
|
||||
Some(t) => t.id(),
|
||||
None => return Ok(()),
|
||||
};
|
||||
self.module.exports.add("__wbg_anyref_table", table);
|
||||
|
||||
let ty = self.module.types.add(&[], &[]);
|
||||
let (import, import_id) = self.module.add_import_func(
|
||||
PLACEHOLDER_MODULE,
|
||||
@ -640,6 +658,7 @@ impl<'a> Context<'a> {
|
||||
None => import,
|
||||
});
|
||||
self.bind_intrinsic(import_id, Intrinsic::InitAnyrefTable)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user