Update wasm2es6js.rs

Binaryen renamed the tool to wasm2js instead of wasm2asm - https://github.com/WebAssembly/binaryen/pull/1642
This commit is contained in:
bspeice 2018-09-02 22:02:15 -04:00 committed by GitHub
parent 986f561209
commit 724eb53d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,14 +11,14 @@ use parity_wasm::elements::*;
pub struct Config { pub struct Config {
base64: bool, base64: bool,
wasm2asm: bool, wasm2js: bool,
fetch_path: Option<String>, fetch_path: Option<String>,
} }
pub struct Output { pub struct Output {
module: Module, module: Module,
base64: bool, base64: bool,
wasm2asm: bool, wasm2js: bool,
fetch_path: Option<String>, fetch_path: Option<String>,
} }
@ -26,7 +26,7 @@ impl Config {
pub fn new() -> Config { pub fn new() -> Config {
Config { Config {
base64: false, base64: false,
wasm2asm: false, wasm2js: false,
fetch_path: None, fetch_path: None,
} }
} }
@ -36,8 +36,8 @@ impl Config {
self self
} }
pub fn wasm2asm(&mut self, wasm2asm: bool) -> &mut Self { pub fn wasm2js(&mut self, wasm2js: bool) -> &mut Self {
self.wasm2asm = wasm2asm; self.wasm2js = wasm2js;
self self
} }
@ -47,14 +47,14 @@ impl Config {
} }
pub fn generate(&mut self, wasm: &[u8]) -> Result<Output, Error> { pub fn generate(&mut self, wasm: &[u8]) -> Result<Output, Error> {
if !self.base64 && !self.fetch_path.is_some() && !self.wasm2asm { if !self.base64 && !self.fetch_path.is_some() && !self.wasm2js {
bail!("one of --base64, --fetch, or --wasm2asm is required"); bail!("one of --base64, --fetch, or --wasm2js is required");
} }
let module = deserialize_buffer(wasm)?; let module = deserialize_buffer(wasm)?;
Ok(Output { Ok(Output {
module, module,
base64: self.base64, base64: self.base64,
wasm2asm: self.wasm2asm, wasm2js: self.wasm2js,
fetch_path: self.fetch_path.clone(), fetch_path: self.fetch_path.clone(),
}) })
} }
@ -139,8 +139,8 @@ impl Output {
} }
pub fn js(self) -> Result<String, Error> { pub fn js(self) -> Result<String, Error> {
if self.wasm2asm { if self.wasm2js {
return self.js_wasm2asm(); return self.js_wasm2js();
} }
let mut js_imports = String::new(); let mut js_imports = String::new();
let mut exports = String::new(); let mut exports = String::new();
@ -233,7 +233,7 @@ impl Output {
)) ))
} }
fn js_wasm2asm(self) -> Result<String, Error> { fn js_wasm2js(self) -> Result<String, Error> {
let mut js_imports = String::new(); let mut js_imports = String::new();
let mut imported_items = Vec::new(); let mut imported_items = Vec::new();
if let Some(i) = self.module.import_section() { if let Some(i) = self.module.import_section() {
@ -256,7 +256,7 @@ impl Output {
if *m != entry.module() { if *m != entry.module() {
bail!( bail!(
"the name `{}` is imported from two differnet \ "the name `{}` is imported from two differnet \
modules which currently isn't supported in `wasm2asm` \ modules which currently isn't supported in `wasm2js` \
mode" mode"
); );
} }
@ -287,7 +287,7 @@ impl Output {
} }
if !export_mem { if !export_mem {
bail!( bail!(
"the `wasm2asm` mode is currently only compatible with \ "the `wasm2js` mode is currently only compatible with \
modules that export memory" modules that export memory"
) )
} }
@ -333,11 +333,11 @@ impl Output {
)?; )?;
let js_file = td.as_ref().join("foo.js"); let js_file = td.as_ref().join("foo.js");
run( run(
Command::new("wasm2asm") Command::new("wasm2js")
.arg(&wast_file) .arg(&wast_file)
.arg("-o") .arg("-o")
.arg(&js_file), .arg(&js_file),
"wasm2asm", "wasm2js",
)?; )?;
let asm_func = fs::read_to_string(&js_file) let asm_func = fs::read_to_string(&js_file)