mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Don't hardcode the __wbg_function_table
name (#1891)
Instead use the embedded `export_name_of` function to automatically export the table if necessary.
This commit is contained in:
@ -2375,8 +2375,8 @@ impl<'a> Context<'a> {
|
|||||||
// be deallocated while we're invoking it.
|
// be deallocated while we're invoking it.
|
||||||
js.push_str("state.cnt++;\n");
|
js.push_str("state.cnt++;\n");
|
||||||
|
|
||||||
self.export_function_table()?;
|
let table = self.export_function_table()?;
|
||||||
let dtor = format!("wasm.__wbg_function_table.get({})", dtor);
|
let dtor = format!("wasm.{}.get({})", table, dtor);
|
||||||
let call = self.adapter_name(*adapter);
|
let call = self.adapter_name(*adapter);
|
||||||
|
|
||||||
if *mutable {
|
if *mutable {
|
||||||
@ -2682,8 +2682,8 @@ impl<'a> Context<'a> {
|
|||||||
|
|
||||||
Intrinsic::FunctionTable => {
|
Intrinsic::FunctionTable => {
|
||||||
assert_eq!(args.len(), 0);
|
assert_eq!(args.len(), 0);
|
||||||
self.export_function_table()?;
|
let name = self.export_function_table()?;
|
||||||
format!("wasm.__wbg_function_table")
|
format!("wasm.{}", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
Intrinsic::DebugString => {
|
Intrinsic::DebugString => {
|
||||||
@ -2932,16 +2932,11 @@ impl<'a> Context<'a> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn export_function_table(&mut self) -> Result<(), Error> {
|
fn export_function_table(&mut self) -> Result<String, Error> {
|
||||||
if !self.should_write_global("wbg-function-table") {
|
match self.module.tables.main_function_table()? {
|
||||||
return Ok(());
|
Some(id) => Ok(self.export_name_of(id)),
|
||||||
}
|
|
||||||
let id = match self.module.tables.main_function_table()? {
|
|
||||||
Some(id) => id,
|
|
||||||
None => bail!("no function table found in module"),
|
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<walrus::ExportItem>) -> String {
|
fn export_name_of(&mut self, id: impl Into<walrus::ExportItem>) -> String {
|
||||||
|
Reference in New Issue
Block a user