From 8be8e09d35aacd8b3f58ab7161d6a1bc3d57be58 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 3 Dec 2019 13:01:40 -0600 Subject: [PATCH] Don't hardcode the `__wbg_function_table` name (#1891) Instead use the embedded `export_name_of` function to automatically export the table if necessary. --- crates/cli-support/src/js/mod.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 8869f4e1..094eb8e9 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -2375,8 +2375,8 @@ impl<'a> Context<'a> { // be deallocated while we're invoking it. js.push_str("state.cnt++;\n"); - self.export_function_table()?; - let dtor = format!("wasm.__wbg_function_table.get({})", dtor); + let table = self.export_function_table()?; + let dtor = format!("wasm.{}.get({})", table, dtor); let call = self.adapter_name(*adapter); if *mutable { @@ -2682,8 +2682,8 @@ impl<'a> Context<'a> { Intrinsic::FunctionTable => { assert_eq!(args.len(), 0); - self.export_function_table()?; - format!("wasm.__wbg_function_table") + let name = self.export_function_table()?; + format!("wasm.{}", name) } Intrinsic::DebugString => { @@ -2932,16 +2932,11 @@ impl<'a> Context<'a> { ); } - fn export_function_table(&mut self) -> Result<(), Error> { - if !self.should_write_global("wbg-function-table") { - return Ok(()); - } - let id = match self.module.tables.main_function_table()? { - Some(id) => id, + fn export_function_table(&mut self) -> Result { + match self.module.tables.main_function_table()? { + Some(id) => Ok(self.export_name_of(id)), None => bail!("no function table found in module"), - }; - self.module.exports.add("__wbg_function_table", id); - Ok(()) + } } fn export_name_of(&mut self, id: impl Into) -> String {