mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-16 15:51:19 +00:00
Merge pull request #1704 from alexcrichton/skip-anyref
Fix anyref table export in empty modules
This commit is contained in:
commit
cbab8a191d
@ -1152,7 +1152,6 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
self.expose_uint32_memory();
|
self.expose_uint32_memory();
|
||||||
if self.config.anyref {
|
if self.config.anyref {
|
||||||
self.expose_anyref_table();
|
|
||||||
self.global(
|
self.global(
|
||||||
"
|
"
|
||||||
function getArrayJsValueFromWasm(ptr, len) {
|
function getArrayJsValueFromWasm(ptr, len) {
|
||||||
@ -1834,30 +1833,11 @@ impl<'a> Context<'a> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expose_anyref_table(&mut self) {
|
|
||||||
assert!(self.config.anyref);
|
|
||||||
if !self.should_write_global("anyref_table") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let table = self
|
|
||||||
.module
|
|
||||||
.tables
|
|
||||||
.iter()
|
|
||||||
.find(|t| match t.kind {
|
|
||||||
walrus::TableKind::Anyref(_) => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.expect("failed to find anyref table in module")
|
|
||||||
.id();
|
|
||||||
self.module.exports.add("__wbg_anyref_table", table);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expose_add_to_anyref_table(&mut self) -> Result<(), Error> {
|
fn expose_add_to_anyref_table(&mut self) -> Result<(), Error> {
|
||||||
assert!(self.config.anyref);
|
assert!(self.config.anyref);
|
||||||
if !self.should_write_global("add_to_anyref_table") {
|
if !self.should_write_global("add_to_anyref_table") {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
self.expose_anyref_table();
|
|
||||||
self.require_internal_export("__wbindgen_anyref_table_alloc")?;
|
self.require_internal_export("__wbindgen_anyref_table_alloc")?;
|
||||||
self.global(
|
self.global(
|
||||||
"
|
"
|
||||||
@ -2640,8 +2620,6 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intrinsic::InitAnyrefTable => {
|
Intrinsic::InitAnyrefTable => {
|
||||||
self.expose_anyref_table();
|
|
||||||
|
|
||||||
// Grow the table to insert our initial values, and then also
|
// Grow the table to insert our initial values, and then also
|
||||||
// set the 0th slot to `undefined` since that's what we've
|
// set the 0th slot to `undefined` since that's what we've
|
||||||
// historically used for our ABI which is that the index of 0
|
// historically used for our ABI which is that the index of 0
|
||||||
|
@ -623,6 +623,24 @@ impl<'a> Context<'a> {
|
|||||||
if !self.anyref_enabled {
|
if !self.anyref_enabled {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure to export the `anyref` table for the JS bindings since it
|
||||||
|
// will need to be initialized. If it doesn't exist though then the
|
||||||
|
// module must not use it, so we skip it.
|
||||||
|
let table = self
|
||||||
|
.module
|
||||||
|
.tables
|
||||||
|
.iter()
|
||||||
|
.find(|t| match t.kind {
|
||||||
|
walrus::TableKind::Anyref(_) => true,
|
||||||
|
_ => false,
|
||||||
|
});
|
||||||
|
let table = match table {
|
||||||
|
Some(t) => t.id(),
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
self.module.exports.add("__wbg_anyref_table", table);
|
||||||
|
|
||||||
let ty = self.module.types.add(&[], &[]);
|
let ty = self.module.types.add(&[], &[]);
|
||||||
let (import, import_id) = self.module.add_import_func(
|
let (import, import_id) = self.module.add_import_func(
|
||||||
PLACEHOLDER_MODULE,
|
PLACEHOLDER_MODULE,
|
||||||
@ -640,6 +658,7 @@ impl<'a> Context<'a> {
|
|||||||
None => import,
|
None => import,
|
||||||
});
|
});
|
||||||
self.bind_intrinsic(import_id, Intrinsic::InitAnyrefTable)?;
|
self.bind_intrinsic(import_id, Intrinsic::InitAnyrefTable)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user