Skip to content

Commit 8be8e09

Browse files
authored
Don't hardcode the __wbg_function_table name (#1891)
Instead use the embedded `export_name_of` function to automatically export the table if necessary.
1 parent 8e56cda commit 8be8e09

File tree

1 file changed

+8
-13
lines changed
  • crates/cli-support/src/js

1 file changed

+8
-13
lines changed

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

+8-13
Original file line numberDiff line numberDiff line change
@@ -2375,8 +2375,8 @@ impl<'a> Context<'a> {
23752375
// be deallocated while we're invoking it.
23762376
js.push_str("state.cnt++;\n");
23772377

2378-
self.export_function_table()?;
2379-
let dtor = format!("wasm.__wbg_function_table.get({})", dtor);
2378+
let table = self.export_function_table()?;
2379+
let dtor = format!("wasm.{}.get({})", table, dtor);
23802380
let call = self.adapter_name(*adapter);
23812381

23822382
if *mutable {
@@ -2682,8 +2682,8 @@ impl<'a> Context<'a> {
26822682

26832683
Intrinsic::FunctionTable => {
26842684
assert_eq!(args.len(), 0);
2685-
self.export_function_table()?;
2686-
format!("wasm.__wbg_function_table")
2685+
let name = self.export_function_table()?;
2686+
format!("wasm.{}", name)
26872687
}
26882688

26892689
Intrinsic::DebugString => {
@@ -2932,16 +2932,11 @@ impl<'a> Context<'a> {
29322932
);
29332933
}
29342934

2935-
fn export_function_table(&mut self) -> Result<(), Error> {
2936-
if !self.should_write_global("wbg-function-table") {
2937-
return Ok(());
2938-
}
2939-
let id = match self.module.tables.main_function_table()? {
2940-
Some(id) => id,
2935+
fn export_function_table(&mut self) -> Result<String, Error> {
2936+
match self.module.tables.main_function_table()? {
2937+
Some(id) => Ok(self.export_name_of(id)),
29412938
None => bail!("no function table found in module"),
2942-
};
2943-
self.module.exports.add("__wbg_function_table", id);
2944-
Ok(())
2939+
}
29452940
}
29462941

29472942
fn export_name_of(&mut self, id: impl Into<walrus::ExportItem>) -> String {

0 commit comments

Comments
 (0)