mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 09:11:35 +00:00
Handle variadic no args more gracefully.
This commit is contained in:
@ -1964,7 +1964,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
.catch(import.catch)
|
.catch(import.catch)
|
||||||
.variadic(import.variadic)
|
.variadic(import.variadic)
|
||||||
.process(descriptor.unwrap_function())?
|
.process(descriptor.unwrap_function())?
|
||||||
.finish(&target);
|
.finish(&target)?;
|
||||||
self.cx.export(&import.shim, &js, None);
|
self.cx.export(&import.shim, &js, None);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use failure::Error;
|
use failure::{self, Error};
|
||||||
|
|
||||||
use super::{Context, Js2Rust};
|
use super::{Context, Js2Rust};
|
||||||
use descriptor::{Descriptor, Function};
|
use descriptor::{Descriptor, Function};
|
||||||
@ -529,8 +529,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(&self, invoc: &str) -> String {
|
pub fn finish(&self, invoc: &str) -> Result<String, Error> {
|
||||||
use std::fmt::Write;
|
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
ret.push_str("function(");
|
ret.push_str("function(");
|
||||||
ret.push_str(&self.shim_arguments.join(", "));
|
ret.push_str(&self.shim_arguments.join(", "));
|
||||||
@ -545,7 +544,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
|
|
||||||
let mut invoc = if self.variadic {
|
let mut invoc = if self.variadic {
|
||||||
if self.js_arguments.is_empty() {
|
if self.js_arguments.is_empty() {
|
||||||
unreachable!("the last argument of a variadic must be a slice");
|
return Err(failure::err_msg("a function with no arguments cannot be variadic"));
|
||||||
}
|
}
|
||||||
let last_arg = self.js_arguments.len() - 1; // check implies >= 0
|
let last_arg = self.js_arguments.len() - 1; // check implies >= 0
|
||||||
self.ret_expr.replace(
|
self.ret_expr.replace(
|
||||||
@ -595,7 +594,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
ret.push_str(&invoc);
|
ret.push_str(&invoc);
|
||||||
|
|
||||||
ret.push_str("\n}\n");
|
ret.push_str("\n}\n");
|
||||||
return ret;
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn global_idx(&mut self) -> usize {
|
fn global_idx(&mut self) -> usize {
|
||||||
|
Reference in New Issue
Block a user