Skip to content

Commit e61df94

Browse files
committed
Move table export to the anyref pass
Turns out rustwasm#1704 was buggy and ended up never injecting initialization because the anyref table was never present! This fixes that issue and this should now be tested on CI to ensure this doesn't regress and future changes preserve correctness
1 parent a904c96 commit e61df94

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

crates/cli-support/src/anyref.rs

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ pub fn process(module: &mut Module) -> Result<(), Error> {
4444
}
4545

4646
cfg.run(module)?;
47+
48+
// Make sure to export the `anyref` table for the JS bindings since it
49+
// will need to be initialized. If it doesn't exist though then the
50+
// module must not use it, so we skip it.
51+
let table = module.tables.iter().find(|t| match t.kind {
52+
walrus::TableKind::Anyref(_) => true,
53+
_ => false,
54+
});
55+
let table = match table {
56+
Some(t) => t.id(),
57+
None => return Ok(()),
58+
};
59+
module.exports.add("__wbg_anyref_table", table);
60+
61+
// Clean up now-unused intrinsics and shims and such
4762
walrus::passes::gc::run(module);
4863

4964
// The GC pass above may end up removing some imported intrinsics. For

crates/cli-support/src/webidl/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -624,19 +624,6 @@ impl<'a> Context<'a> {
624624
return Ok(());
625625
}
626626

627-
// Make sure to export the `anyref` table for the JS bindings since it
628-
// will need to be initialized. If it doesn't exist though then the
629-
// module must not use it, so we skip it.
630-
let table = self.module.tables.iter().find(|t| match t.kind {
631-
walrus::TableKind::Anyref(_) => true,
632-
_ => false,
633-
});
634-
let table = match table {
635-
Some(t) => t.id(),
636-
None => return Ok(()),
637-
};
638-
self.module.exports.add("__wbg_anyref_table", table);
639-
640627
let ty = self.module.types.add(&[], &[]);
641628
let (import, import_id) =
642629
self.module

0 commit comments

Comments
 (0)