Fix name collisions with test functions and intrinsics (#2123)

There was an unfortunate collision with how test symbols were named and
the various bindings functions exported by wasm-bindgen. This commit
fixes these issues by using a separate prefix for `#[wasm_bindgen_test]`
than other `#[wasm_bindgen]` functions which should avoid the name
clash.

Closes #2121
This commit is contained in:
Alex Crichton 2020-05-04 16:20:41 -05:00 committed by GitHub
parent d896446edc
commit dc54c0fb25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 6 deletions

View File

@ -63,7 +63,7 @@ fn main() -> anyhow::Result<()> {
let mut tests = Vec::new(); let mut tests = Vec::new();
for export in wasm.exports.iter() { for export in wasm.exports.iter() {
if !export.name.starts_with("__wbg_test") { if !export.name.starts_with("__wbgt_") {
continue; continue;
} }
tests.push(export.name.to_string()); tests.push(export.name.to_string());

View File

@ -59,11 +59,7 @@ pub fn wasm_bindgen_test(
// We generate a `#[no_mangle]` with a known prefix so the test harness can // We generate a `#[no_mangle]` with a known prefix so the test harness can
// later slurp up all of these functions and pass them as arguments to the // later slurp up all of these functions and pass them as arguments to the
// main test harness. This is the entry point for all tests. // main test harness. This is the entry point for all tests.
let name = format!( let name = format!("__wbgt_{}_{}", ident, CNT.fetch_add(1, Ordering::SeqCst));
"__wbg_test_{}_{}",
ident,
CNT.fetch_add(1, Ordering::SeqCst)
);
let name = Ident::new(&name, Span::call_site()); let name = Ident::new(&name, Span::call_site());
tokens.extend( tokens.extend(
(quote! { (quote! {