Correctly hook up the anyref table initialization

This functionality got lost in recent refactorings for WebIDL bindings
unfortunately, so this commit touches things up to ensure that the
anyref table initialization in anyref-mode is hooked up correctly, even
when tests are enabled. This invovled moving injection of the start
function to the webidl processing pass and ensuring its intrinsic is
registered in the internal maps of wasm-bindgen.
This commit is contained in:
Alex Crichton
2019-08-01 11:56:57 -07:00
parent 36db788829
commit 6e3e9d2dae
5 changed files with 63 additions and 54 deletions

View File

@ -254,10 +254,6 @@ impl Transform<'_> {
// functions and make sure everything is still hooked up right.
self.rewrite_calls(module);
// Inject initialization routine to set up default slots in the table
// (things like null/undefined/true/false)
self.inject_initialization(module);
Ok(())
}
@ -669,31 +665,4 @@ impl Transform<'_> {
}
}
}
// Ensure that the `start` function for this module calls the
// `__wbindgen_init_anyref_table` function. This'll ensure that all
// instances of this module have the initial slots of the anyref table
// initialized correctly.
fn inject_initialization(&mut self, module: &mut Module) {
let ty = module.types.add(&[], &[]);
let (import, _) = module.add_import_func(
"__wbindgen_placeholder__",
"__wbindgen_init_anyref_table",
ty,
);
let prev_start = match module.start {
Some(f) => f,
None => {
module.start = Some(import);
return;
}
};
let mut builder = walrus::FunctionBuilder::new();
let call_init = builder.call(import, Box::new([]));
let call_prev = builder.call(prev_start, Box::new([]));
let new_start = builder.finish(ty, Vec::new(), vec![call_init, call_prev], module);
module.start = Some(new_start);
}
}