Handle variadic no args more gracefully.

This commit is contained in:
Richard Dodd
2018-09-03 09:50:26 +01:00
parent e279987fa4
commit 5c7e638b8c
2 changed files with 5 additions and 6 deletions

View File

@ -1964,7 +1964,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
.catch(import.catch)
.variadic(import.variadic)
.process(descriptor.unwrap_function())?
.finish(&target);
.finish(&target)?;
self.cx.export(&import.shim, &js, None);
Ok(())
}

View File

@ -1,4 +1,4 @@
use failure::Error;
use failure::{self, Error};
use super::{Context, Js2Rust};
use descriptor::{Descriptor, Function};
@ -529,8 +529,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
Ok(())
}
pub fn finish(&self, invoc: &str) -> String {
use std::fmt::Write;
pub fn finish(&self, invoc: &str) -> Result<String, Error> {
let mut ret = String::new();
ret.push_str("function(");
ret.push_str(&self.shim_arguments.join(", "));
@ -545,7 +544,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
let mut invoc = if self.variadic {
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
self.ret_expr.replace(
@ -595,7 +594,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
ret.push_str(&invoc);
ret.push_str("\n}\n");
return ret;
Ok(ret)
}
fn global_idx(&mut self) -> usize {