mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 01:01:34 +00:00
Run rustfmt
This commit is contained in:
@ -53,7 +53,8 @@ pub fn rewrite(input: &mut Context) -> Result<(), Error> {
|
||||
// everything.
|
||||
idx + info.code_idx_to_descriptor.len() as u32
|
||||
}
|
||||
}).remap_module(input.module);
|
||||
})
|
||||
.remap_module(input.module);
|
||||
|
||||
info.delete_function_table_entries(input);
|
||||
info.inject_imports(input)?;
|
||||
@ -263,9 +264,7 @@ impl ClosureDescriptors {
|
||||
real.original = cb;
|
||||
return addHeapObject(real);
|
||||
}}",
|
||||
closure.shim_idx,
|
||||
closure.dtor_idx,
|
||||
js,
|
||||
closure.shim_idx, closure.dtor_idx, js,
|
||||
);
|
||||
input.export(&import_name, &body, None);
|
||||
|
||||
|
@ -177,7 +177,7 @@ impl<'a> Context<'a> {
|
||||
function(idx) {
|
||||
return addHeapObject(getObject(idx));
|
||||
}
|
||||
"
|
||||
",
|
||||
))
|
||||
})?;
|
||||
|
||||
@ -424,9 +424,7 @@ impl<'a> Context<'a> {
|
||||
Ok(String::from("function(idx) { throw takeObject(idx); }"))
|
||||
})?;
|
||||
|
||||
closures::rewrite(self).with_context(|_| {
|
||||
"failed to generate internal closure shims"
|
||||
})?;
|
||||
closures::rewrite(self).with_context(|_| "failed to generate internal closure shims")?;
|
||||
self.unexport_unused_internal_exports();
|
||||
|
||||
// Handle the `start` function, if one was specified. If we're in a
|
||||
@ -1405,7 +1403,7 @@ impl<'a> Context<'a> {
|
||||
heap[--stack_pointer] = obj;
|
||||
return stack_pointer;
|
||||
}
|
||||
"
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
@ -2067,7 +2065,9 @@ impl<'a> Context<'a> {
|
||||
None => return Ok(()),
|
||||
};
|
||||
let idx = {
|
||||
let exports = self.module.export_section()
|
||||
let exports = self
|
||||
.module
|
||||
.export_section()
|
||||
.ok_or_else(|| format_err!("no export section found"))?;
|
||||
let entry = exports
|
||||
.entries()
|
||||
@ -2082,13 +2082,20 @@ impl<'a> Context<'a> {
|
||||
if let Some(prev_start) = self.module.start_section() {
|
||||
if let Some(NameSection::Function(n)) = self.module.names_section() {
|
||||
if let Some(prev) = n.names().get(prev_start) {
|
||||
bail!("cannot flag `{}` as start function as `{}` is \
|
||||
already the start function", start, prev);
|
||||
bail!(
|
||||
"cannot flag `{}` as start function as `{}` is \
|
||||
already the start function",
|
||||
start,
|
||||
prev
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bail!("cannot flag `{}` as start function as another \
|
||||
function is already the start function", start);
|
||||
bail!(
|
||||
"cannot flag `{}` as start function as another \
|
||||
function is already the start function",
|
||||
start
|
||||
);
|
||||
}
|
||||
|
||||
self.set_start_section(idx);
|
||||
@ -2101,21 +2108,23 @@ impl<'a> Context<'a> {
|
||||
// for section ordering
|
||||
for (i, section) in self.module.sections().iter().enumerate() {
|
||||
match section {
|
||||
Section::Type(_) |
|
||||
Section::Import(_) |
|
||||
Section::Function(_) |
|
||||
Section::Table(_) |
|
||||
Section::Memory(_) |
|
||||
Section::Global(_) |
|
||||
Section::Export(_) => continue,
|
||||
Section::Type(_)
|
||||
| Section::Import(_)
|
||||
| Section::Function(_)
|
||||
| Section::Table(_)
|
||||
| Section::Memory(_)
|
||||
| Section::Global(_)
|
||||
| Section::Export(_) => continue,
|
||||
_ => {
|
||||
pos = Some(i);
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let pos = pos.unwrap_or(self.module.sections().len() - 1);
|
||||
self.module.sections_mut().insert(pos, Section::Start(start));
|
||||
self.module
|
||||
.sections_mut()
|
||||
.insert(pos, Section::Start(start));
|
||||
}
|
||||
|
||||
/// If a start function is present, it removes it from the `start` section
|
||||
@ -2134,11 +2143,13 @@ impl<'a> Context<'a> {
|
||||
match pos {
|
||||
Some(i) => {
|
||||
self.module.sections_mut().remove(i);
|
||||
let entry = ExportEntry::new(
|
||||
"__wbindgen_start".to_string(),
|
||||
Internal::Function(start),
|
||||
);
|
||||
self.module.export_section_mut().unwrap().entries_mut().push(entry);
|
||||
let entry =
|
||||
ExportEntry::new("__wbindgen_start".to_string(), Internal::Function(start));
|
||||
self.module
|
||||
.export_section_mut()
|
||||
.unwrap()
|
||||
.entries_mut()
|
||||
.push(entry);
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
@ -2156,12 +2167,12 @@ impl<'a> Context<'a> {
|
||||
}";
|
||||
self.export("__wbindgen_defer_start", body, None);
|
||||
|
||||
let imports = self.module.import_section()
|
||||
let imports = self
|
||||
.module
|
||||
.import_section()
|
||||
.map(|s| s.functions() as u32)
|
||||
.unwrap_or(0);
|
||||
Remap(|idx| {
|
||||
if idx < imports { idx } else { idx + 1 }
|
||||
}).remap_module(self.module);
|
||||
Remap(|idx| if idx < imports { idx } else { idx + 1 }).remap_module(self.module);
|
||||
|
||||
let type_idx = {
|
||||
let types = self.module.type_section_mut().unwrap();
|
||||
@ -2207,10 +2218,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
}
|
||||
for s in self.program.structs.iter() {
|
||||
self.generate_struct(s).with_context(|_| {
|
||||
format!(
|
||||
"failed to generate bindings for Rust struct `{}`",
|
||||
s.name,
|
||||
)
|
||||
format!("failed to generate bindings for Rust struct `{}`", s.name,)
|
||||
})?;
|
||||
}
|
||||
for s in self.program.typescript_custom_sections.iter() {
|
||||
@ -2253,8 +2261,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
||||
|
||||
fn set_start_function(&mut self, start: &str) -> Result<(), Error> {
|
||||
if let Some(prev) = &self.cx.start {
|
||||
bail!("cannot flag `{}` as start function as `{}` is \
|
||||
already the start function", start, prev);
|
||||
bail!(
|
||||
"cannot flag `{}` as start function as `{}` is \
|
||||
already the start function",
|
||||
start,
|
||||
prev
|
||||
);
|
||||
}
|
||||
self.cx.start = Some(start.to_string());
|
||||
Ok(())
|
||||
|
@ -560,12 +560,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
&format!("{}({}, ...{})", invoc, args.join(", "), last_arg),
|
||||
)
|
||||
} else {
|
||||
ret_expr
|
||||
.replace("JS", &format!("{}(...{})", invoc, last_arg))
|
||||
ret_expr.replace("JS", &format!("{}(...{})", invoc, last_arg))
|
||||
}
|
||||
} else {
|
||||
ret_expr
|
||||
.replace("JS", &format!("{}({})", invoc, js_arguments.join(", ")))
|
||||
ret_expr.replace("JS", &format!("{}({})", invoc, js_arguments.join(", ")))
|
||||
};
|
||||
Ok(ret)
|
||||
};
|
||||
@ -575,9 +573,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
bail!("{} cannot be variadic", desc);
|
||||
}
|
||||
match (class, js_arguments.len()) {
|
||||
(None, n) if n == amt + 1 => {
|
||||
Ok((js_arguments[0].clone(), &js_arguments[1..]))
|
||||
}
|
||||
(None, n) if n == amt + 1 => Ok((js_arguments[0].clone(), &js_arguments[1..])),
|
||||
(None, _) => bail!("setters must have {} arguments", amt + 1),
|
||||
(Some(class), n) if n == amt => Ok((class.clone(), &js_arguments[..])),
|
||||
(Some(_), _) => bail!("static setters must have {} arguments", amt),
|
||||
|
@ -22,8 +22,8 @@ use parity_wasm::elements::*;
|
||||
mod decode;
|
||||
mod descriptor;
|
||||
mod js;
|
||||
mod wasm_utils;
|
||||
pub mod wasm2es6js;
|
||||
mod wasm_utils;
|
||||
|
||||
pub struct Bindgen {
|
||||
input: Input,
|
||||
|
@ -58,20 +58,17 @@ pub fn typescript(module: &Module) -> String {
|
||||
.unwrap_or(0);
|
||||
for entry in i.entries() {
|
||||
let idx = match *entry.internal() {
|
||||
Internal::Function(i) if i < imported_functions => {
|
||||
*module.import_section()
|
||||
.unwrap()
|
||||
.entries()
|
||||
.iter()
|
||||
.filter_map(|f| {
|
||||
match f.external() {
|
||||
External::Function(i) => Some(i),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.nth(i as usize)
|
||||
.unwrap()
|
||||
}
|
||||
Internal::Function(i) if i < imported_functions => *module
|
||||
.import_section()
|
||||
.unwrap()
|
||||
.entries()
|
||||
.iter()
|
||||
.filter_map(|f| match f.external() {
|
||||
External::Function(i) => Some(i),
|
||||
_ => None,
|
||||
})
|
||||
.nth(i as usize)
|
||||
.unwrap(),
|
||||
Internal::Function(i) => {
|
||||
let idx = i - imported_functions;
|
||||
let functions = module
|
||||
@ -96,9 +93,7 @@ pub fn typescript(module: &Module) -> String {
|
||||
Internal::Global(_) => continue,
|
||||
};
|
||||
|
||||
let types = module
|
||||
.type_section()
|
||||
.expect("failed to find type section");
|
||||
let types = module.type_section().expect("failed to find type section");
|
||||
let ty = match types.types()[idx as usize] {
|
||||
Type::Function(ref f) => f,
|
||||
};
|
||||
@ -133,7 +128,7 @@ impl Output {
|
||||
if self.base64 {
|
||||
ts.push_str("export const booted: Promise<boolean>;\n");
|
||||
}
|
||||
return ts
|
||||
return ts;
|
||||
}
|
||||
|
||||
pub fn js_and_wasm(mut self) -> Result<(String, Option<Vec<u8>>), Error> {
|
||||
@ -259,7 +254,7 @@ impl Output {
|
||||
fn unstart(&mut self) -> bool {
|
||||
let mut start = None;
|
||||
for (i, section) in self.module.sections().iter().enumerate() {
|
||||
if let Section::Start(idx) = section {
|
||||
if let Section::Start(idx) = section {
|
||||
start = Some((i, *idx));
|
||||
break;
|
||||
}
|
||||
@ -269,11 +264,12 @@ impl Output {
|
||||
None => return false,
|
||||
};
|
||||
self.module.sections_mut().remove(i);
|
||||
let entry = ExportEntry::new(
|
||||
"__wasm2es6js_start".to_string(),
|
||||
Internal::Function(idx),
|
||||
);
|
||||
self.module.export_section_mut().unwrap().entries_mut().push(entry);
|
||||
let entry = ExportEntry::new("__wasm2es6js_start".to_string(), Internal::Function(idx));
|
||||
self.module
|
||||
.export_section_mut()
|
||||
.unwrap()
|
||||
.entries_mut()
|
||||
.push(entry);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ use parity_wasm::elements::*;
|
||||
|
||||
pub struct Remap<F>(pub F);
|
||||
|
||||
impl<F> Remap<F> where F: FnMut(u32) -> u32 {
|
||||
impl<F> Remap<F>
|
||||
where
|
||||
F: FnMut(u32) -> u32,
|
||||
{
|
||||
pub fn remap_module(&mut self, module: &mut Module) {
|
||||
for section in module.sections_mut() {
|
||||
match section {
|
||||
|
Reference in New Issue
Block a user