From aace8cedeecee6443ab64c3933fc39112e1aae12 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 12 Aug 2019 11:26:45 -0700 Subject: [PATCH] Move table export to the anyref pass Turns out #1704 was buggy and ended up never injecting initialization because the anyref table was never present! This fixes that issue and this should now be tested on CI to ensure this doesn't regress and future changes preserve correctness --- Cargo.toml | 1 - crates/anyref-xform/Cargo.toml | 2 +- crates/cli-support/src/anyref.rs | 15 +++++++++++++++ crates/cli-support/src/webidl/mod.rs | 13 ------------- crates/cli/Cargo.toml | 2 +- crates/threads-xform/Cargo.toml | 2 +- crates/wasm-interpreter/Cargo.toml | 2 +- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index be8b7a8d..43eb5abe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,4 +92,3 @@ wasm-bindgen = { path = '.' } wasm-bindgen-futures = { path = 'crates/futures' } js-sys = { path = 'crates/js-sys' } web-sys = { path = 'crates/web-sys' } -wasm-webidl-bindings = { git = 'https://github.com/alexcrichton/wasm-webidl-bindings', branch = 'update-walrus' } diff --git a/crates/anyref-xform/Cargo.toml b/crates/anyref-xform/Cargo.toml index 47412bad..1e38b9a1 100644 --- a/crates/anyref-xform/Cargo.toml +++ b/crates/anyref-xform/Cargo.toml @@ -13,4 +13,4 @@ edition = '2018' [dependencies] failure = "0.1" -walrus = "0.10.0" +walrus = "0.11.0" diff --git a/crates/cli-support/src/anyref.rs b/crates/cli-support/src/anyref.rs index d2556d40..f9936286 100644 --- a/crates/cli-support/src/anyref.rs +++ b/crates/cli-support/src/anyref.rs @@ -44,6 +44,21 @@ pub fn process(module: &mut Module) -> Result<(), Error> { } cfg.run(module)?; + + // 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 = module.tables.iter().find(|t| match t.kind { + walrus::TableKind::Anyref(_) => true, + _ => false, + }); + let table = match table { + Some(t) => t.id(), + None => return Ok(()), + }; + module.exports.add("__wbg_anyref_table", table); + + // Clean up now-unused intrinsics and shims and such walrus::passes::gc::run(module); // The GC pass above may end up removing some imported intrinsics. For diff --git a/crates/cli-support/src/webidl/mod.rs b/crates/cli-support/src/webidl/mod.rs index 26e9c920..33a2a0ed 100644 --- a/crates/cli-support/src/webidl/mod.rs +++ b/crates/cli-support/src/webidl/mod.rs @@ -624,19 +624,6 @@ impl<'a> Context<'a> { 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 (import, import_id) = self.module diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 5c029b14..4ea8d406 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -24,7 +24,7 @@ rouille = { version = "3.0.0", default-features = false } serde = { version = "1.0", features = ['derive'] } serde_derive = "1.0" serde_json = "1.0" -walrus = { version = "0.10.0", features = ['parallel'] } +walrus = { version = "0.11.0", features = ['parallel'] } wasm-bindgen-cli-support = { path = "../cli-support", version = "=0.2.48" } wasm-bindgen-shared = { path = "../shared", version = "=0.2.48" } diff --git a/crates/threads-xform/Cargo.toml b/crates/threads-xform/Cargo.toml index 92f5a73f..1f1248f0 100644 --- a/crates/threads-xform/Cargo.toml +++ b/crates/threads-xform/Cargo.toml @@ -13,4 +13,4 @@ edition = "2018" [dependencies] failure = "0.1" -walrus = "0.10.0" +walrus = "0.11.0" diff --git a/crates/wasm-interpreter/Cargo.toml b/crates/wasm-interpreter/Cargo.toml index 86c09817..f64fde83 100644 --- a/crates/wasm-interpreter/Cargo.toml +++ b/crates/wasm-interpreter/Cargo.toml @@ -14,7 +14,7 @@ edition = '2018' [dependencies] failure = "0.1" log = "0.4" -walrus = "0.10.0" +walrus = "0.11.0" [dev-dependencies] tempfile = "3"