mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 13:01:22 +00:00
add char support (#206)
* 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:
committed by
Alex Crichton
parent
17861a45ab
commit
4ddd93d75d
@ -32,6 +32,7 @@ tys! {
|
||||
ANYREF
|
||||
ENUM
|
||||
RUST_STRUCT
|
||||
CHAR
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -57,6 +58,7 @@ pub enum Descriptor {
|
||||
Anyref,
|
||||
Enum,
|
||||
RustStruct(String),
|
||||
Char,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -122,6 +124,7 @@ impl Descriptor {
|
||||
.collect();
|
||||
Descriptor::RustStruct(name)
|
||||
}
|
||||
CHAR => Descriptor::Char,
|
||||
other => panic!("unknown descriptor: {}", other),
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -3,7 +3,7 @@ use failure::Error;
|
||||
use descriptor::{Descriptor, Function};
|
||||
use super::{indent, Context, Js2Rust};
|
||||
|
||||
/// Helper struct for manfuacturing a shim in JS used to translate Rust types to
|
||||
/// Helper struct for manufacturing a shim in JS used to translate Rust types to
|
||||
/// JS, then invoking an imported JS function.
|
||||
pub struct Rust2Js<'a, 'b: 'a> {
|
||||
cx: &'a mut Context<'b>,
|
||||
@ -211,6 +211,9 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
let invoc_arg = match *arg {
|
||||
ref d if d.is_number() => abi,
|
||||
Descriptor::Boolean => format!("{} !== 0", abi),
|
||||
Descriptor::Char => {
|
||||
format!("String.fromCodePoint({})", abi)
|
||||
}
|
||||
Descriptor::Anyref => {
|
||||
self.cx.expose_take_object();
|
||||
format!("takeObject({})", abi)
|
||||
@ -269,6 +272,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
||||
}
|
||||
self.ret_expr = match *ty {
|
||||
Descriptor::Boolean => "return JS ? 1 : 0;".to_string(),
|
||||
Descriptor::Char => "return JS.codePointAt(0)".to_string(),
|
||||
Descriptor::Anyref => {
|
||||
self.cx.expose_add_heap_object();
|
||||
"return addHeapObject(JS);".to_string()
|
||||
|
Reference in New Issue
Block a user