add char support ()

* add char support

* add char test

* remove __wbindgen_char fns

* re-order travis script

* update serve script

* remove binds to unused char functions

* add more wide character items to chars list

* remove unused code

* add char to readme

* remove built file
This commit is contained in:
Robert Masen
2018-05-22 12:34:41 -05:00
committed by Alex Crichton
parent 17861a45ab
commit 4ddd93d75d
20 changed files with 437 additions and 5 deletions

@ -3,7 +3,7 @@ use failure::Error;
use super::{indent, Context};
use descriptor::{Descriptor, Function};
/// Helper struct for manfuacturing a shim in JS used to translate JS types to
/// Helper struct for manufacturing a shim in JS used to translate JS types to
/// Rust, aka pass from JS back into Rust
pub struct Js2Rust<'a, 'b: 'a> {
cx: &'a mut Context<'b>,
@ -210,6 +210,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
}
self.rust_arguments.push(format!("{} ? 1 : 0", name));
}
Descriptor::Char => {
self.js_arguments.push((name.clone(), "string".to_string()));
self.rust_arguments.push(format!("{}.codePointAt(0)", name))
},
Descriptor::Anyref => {
self.js_arguments.push((name.clone(), "any".to_string()));
self.cx.expose_add_heap_object();
@ -299,6 +303,10 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
self.ret_ty = "boolean".to_string();
self.ret_expr = format!("return (RET) !== 0;");
}
Descriptor::Char => {
self.ret_ty = "string".to_string();
self.ret_expr = format!("return String.fromCodePoint(RET)")
}
Descriptor::Anyref => {
self.ret_ty = "any".to_string();
self.cx.expose_take_object();
@ -316,7 +324,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
/// invoking, like `wasm.bar` or `this.f`.
///
/// Returns two strings, the first of which is the JS expression for the
/// generated function shim and the second is a TyepScript signature of rthe
/// generated function shim and the second is a TypeScript signature of the
/// JS expression.
pub fn finish(&self, prefix: &str, invoc: &str) -> (String, String) {
let js_args = self.js_arguments