Skip to content

Commit cbab8a1

Browse files
authored
Merge pull request #1704 from alexcrichton/skip-anyref
Fix anyref table export in empty modules
2 parents 9314873 + ba0c6a9 commit cbab8a1

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,6 @@ impl<'a> Context<'a> {
11521152
}
11531153
self.expose_uint32_memory();
11541154
if self.config.anyref {
1155-
self.expose_anyref_table();
11561155
self.global(
11571156
"
11581157
function getArrayJsValueFromWasm(ptr, len) {
@@ -1834,30 +1833,11 @@ impl<'a> Context<'a> {
18341833
true
18351834
}
18361835

1837-
fn expose_anyref_table(&mut self) {
1838-
assert!(self.config.anyref);
1839-
if !self.should_write_global("anyref_table") {
1840-
return;
1841-
}
1842-
let table = self
1843-
.module
1844-
.tables
1845-
.iter()
1846-
.find(|t| match t.kind {
1847-
walrus::TableKind::Anyref(_) => true,
1848-
_ => false,
1849-
})
1850-
.expect("failed to find anyref table in module")
1851-
.id();
1852-
self.module.exports.add("__wbg_anyref_table", table);
1853-
}
1854-
18551836
fn expose_add_to_anyref_table(&mut self) -> Result<(), Error> {
18561837
assert!(self.config.anyref);
18571838
if !self.should_write_global("add_to_anyref_table") {
18581839
return Ok(());
18591840
}
1860-
self.expose_anyref_table();
18611841
self.require_internal_export("__wbindgen_anyref_table_alloc")?;
18621842
self.global(
18631843
"
@@ -2640,8 +2620,6 @@ impl<'a> Context<'a> {
26402620
}
26412621

26422622
Intrinsic::InitAnyrefTable => {
2643-
self.expose_anyref_table();
2644-
26452623
// Grow the table to insert our initial values, and then also
26462624
// set the 0th slot to `undefined` since that's what we've
26472625
// historically used for our ABI which is that the index of 0

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,24 @@ impl<'a> Context<'a> {
623623
if !self.anyref_enabled {
624624
return Ok(());
625625
}
626+
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
631+
.module
632+
.tables
633+
.iter()
634+
.find(|t| match t.kind {
635+
walrus::TableKind::Anyref(_) => true,
636+
_ => false,
637+
});
638+
let table = match table {
639+
Some(t) => t.id(),
640+
None => return Ok(()),
641+
};
642+
self.module.exports.add("__wbg_anyref_table", table);
643+
626644
let ty = self.module.types.add(&[], &[]);
627645
let (import, import_id) = self.module.add_import_func(
628646
PLACEHOLDER_MODULE,
@@ -640,6 +658,7 @@ impl<'a> Context<'a> {
640658
None => import,
641659
});
642660
self.bind_intrinsic(import_id, Intrinsic::InitAnyrefTable)?;
661+
643662
Ok(())
644663
}
645664

0 commit comments

Comments
 (0)