mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-14 16:36:07 +00:00
Merge pull request #340 from ohanar/rustfmt
Use rustfmt for standarized formatting
This commit is contained in:
commit
e31da84bce
@ -8,6 +8,11 @@ matrix:
|
|||||||
install: true
|
install: true
|
||||||
script: cargo build --manifest-path crates/cli/Cargo.toml
|
script: cargo build --manifest-path crates/cli/Cargo.toml
|
||||||
|
|
||||||
|
# check formatting
|
||||||
|
- rust: nightly
|
||||||
|
before_install: rustup component add rustfmt-preview --toolchain nightly
|
||||||
|
script: cargo fmt -- --check
|
||||||
|
|
||||||
# Tests pass on nightly
|
# Tests pass on nightly
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
before_install:
|
before_install:
|
||||||
@ -41,6 +46,7 @@ matrix:
|
|||||||
# Check JS output from all tests against eslint
|
# Check JS output from all tests against eslint
|
||||||
- ./node_modules/.bin/eslint ./target/generated-tests/*/out*.js
|
- ./node_modules/.bin/eslint ./target/generated-tests/*/out*.js
|
||||||
env: RUST_BACKTRACE=1
|
env: RUST_BACKTRACE=1
|
||||||
|
|
||||||
# WebIDL tests pass on nightly
|
# WebIDL tests pass on nightly
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
before_install: rustup component add rustfmt-preview --toolchain nightly
|
before_install: rustup component add rustfmt-preview --toolchain nightly
|
||||||
|
@ -405,7 +405,10 @@ impl Program {
|
|||||||
};
|
};
|
||||||
let class_name = extract_path_ident(class_name)
|
let class_name = extract_path_ident(class_name)
|
||||||
.expect("first argument of method must be a bare type");
|
.expect("first argument of method must be a bare type");
|
||||||
let class_name = wasm.opts.js_class().map(Into::into)
|
let class_name = wasm
|
||||||
|
.opts
|
||||||
|
.js_class()
|
||||||
|
.map(Into::into)
|
||||||
.unwrap_or_else(|| class_name.to_string());
|
.unwrap_or_else(|| class_name.to_string());
|
||||||
|
|
||||||
ImportFunctionKind::Method {
|
ImportFunctionKind::Method {
|
||||||
|
@ -138,15 +138,15 @@ impl Descriptor {
|
|||||||
|
|
||||||
pub fn is_number(&self) -> bool {
|
pub fn is_number(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Descriptor::I8 |
|
Descriptor::I8
|
||||||
Descriptor::U8 |
|
| Descriptor::U8
|
||||||
Descriptor::I16 |
|
| Descriptor::I16
|
||||||
Descriptor::U16 |
|
| Descriptor::U16
|
||||||
Descriptor::I32 |
|
| Descriptor::I32
|
||||||
Descriptor::U32 |
|
| Descriptor::U32
|
||||||
Descriptor::F32 |
|
| Descriptor::F32
|
||||||
Descriptor::F64 |
|
| Descriptor::F64
|
||||||
Descriptor::Enum => true,
|
| Descriptor::Enum => true,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,19 +191,15 @@ impl Descriptor {
|
|||||||
let inner = match *self {
|
let inner = match *self {
|
||||||
Descriptor::String => return Some(VectorKind::String),
|
Descriptor::String => return Some(VectorKind::String),
|
||||||
Descriptor::Vector(ref d) => &**d,
|
Descriptor::Vector(ref d) => &**d,
|
||||||
Descriptor::Ref(ref d) => {
|
Descriptor::Ref(ref d) => match **d {
|
||||||
match **d {
|
Descriptor::Slice(ref d) => &**d,
|
||||||
Descriptor::Slice(ref d) => &**d,
|
Descriptor::String => return Some(VectorKind::String),
|
||||||
Descriptor::String => return Some(VectorKind::String),
|
_ => return None,
|
||||||
_ => return None,
|
},
|
||||||
}
|
Descriptor::RefMut(ref d) => match **d {
|
||||||
}
|
Descriptor::Slice(ref d) => &**d,
|
||||||
Descriptor::RefMut(ref d) => {
|
_ => return None,
|
||||||
match **d {
|
},
|
||||||
Descriptor::Slice(ref d) => &**d,
|
|
||||||
_ => return None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
match *inner {
|
match *inner {
|
||||||
@ -218,7 +214,7 @@ impl Descriptor {
|
|||||||
Descriptor::F32 => Some(VectorKind::F32),
|
Descriptor::F32 => Some(VectorKind::F32),
|
||||||
Descriptor::F64 => Some(VectorKind::F64),
|
Descriptor::F64 => Some(VectorKind::F64),
|
||||||
Descriptor::Anyref => Some(VectorKind::Anyref),
|
Descriptor::Anyref => Some(VectorKind::Anyref),
|
||||||
_ => None
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,8 +244,7 @@ impl Descriptor {
|
|||||||
|
|
||||||
pub fn is_by_ref(&self) -> bool {
|
pub fn is_by_ref(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Descriptor::Ref(_) |
|
Descriptor::Ref(_) | Descriptor::RefMut(_) => true,
|
||||||
Descriptor::RefMut(_) => true,
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,11 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
/// passed should be `this.ptr`.
|
/// passed should be `this.ptr`.
|
||||||
pub fn method(&mut self, method: bool) -> &mut Self {
|
pub fn method(&mut self, method: bool) -> &mut Self {
|
||||||
if method {
|
if method {
|
||||||
self.prelude("if (this.ptr === 0) {
|
self.prelude(
|
||||||
|
"if (this.ptr === 0) {
|
||||||
throw new Error('Attempt to use a moved value');
|
throw new Error('Attempt to use a moved value');
|
||||||
}");
|
}",
|
||||||
|
);
|
||||||
self.rust_arguments.insert(0, "this.ptr".to_string());
|
self.rust_arguments.insert(0, "this.ptr".to_string());
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
@ -111,30 +113,46 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
let name = self.abi_arg();
|
let name = self.abi_arg();
|
||||||
|
|
||||||
if let Some(kind) = arg.vector_kind() {
|
if let Some(kind) = arg.vector_kind() {
|
||||||
self.js_arguments.push((name.clone(), kind.js_ty().to_string()));
|
self.js_arguments
|
||||||
|
.push((name.clone(), kind.js_ty().to_string()));
|
||||||
|
|
||||||
let func = self.cx.pass_to_wasm_function(kind)?;
|
let func = self.cx.pass_to_wasm_function(kind)?;
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
const [ptr{i}, len{i}] = {func}({arg});\n\
|
"\
|
||||||
", i = i, func = func, arg = name));
|
const [ptr{i}, len{i}] = {func}({arg});\n\
|
||||||
|
",
|
||||||
|
i = i,
|
||||||
|
func = func,
|
||||||
|
arg = name
|
||||||
|
));
|
||||||
if arg.is_by_ref() {
|
if arg.is_by_ref() {
|
||||||
if arg.is_mut_ref() {
|
if arg.is_mut_ref() {
|
||||||
let get = self.cx.memview_function(kind);
|
let get = self.cx.memview_function(kind);
|
||||||
self.finally(&format!("\
|
self.finally(&format!(
|
||||||
{arg}.set({get}().subarray(\
|
"\
|
||||||
ptr{i} / {size}, \
|
{arg}.set({get}().subarray(\
|
||||||
ptr{i} / {size} + len{i}\
|
ptr{i} / {size}, \
|
||||||
));\n\
|
ptr{i} / {size} + len{i}\
|
||||||
", i = i, arg = name, get = get, size = kind.size()));
|
));\n\
|
||||||
|
",
|
||||||
|
i = i,
|
||||||
|
arg = name,
|
||||||
|
get = get,
|
||||||
|
size = kind.size()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
self.finally(&format!("\
|
self.finally(&format!(
|
||||||
wasm.__wbindgen_free(ptr{i}, len{i} * {size});\n\
|
"\
|
||||||
", i = i, size = kind.size()));
|
wasm.__wbindgen_free(ptr{i}, len{i} * {size});\n\
|
||||||
|
",
|
||||||
|
i = i,
|
||||||
|
size = kind.size()
|
||||||
|
));
|
||||||
self.cx.require_internal_export("__wbindgen_free")?;
|
self.cx.require_internal_export("__wbindgen_free")?;
|
||||||
}
|
}
|
||||||
self.rust_arguments.push(format!("ptr{}", i));
|
self.rust_arguments.push(format!("ptr{}", i));
|
||||||
self.rust_arguments.push(format!("len{}", i));
|
self.rust_arguments.push(format!("len{}", i));
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(s) = arg.rust_struct() {
|
if let Some(s) = arg.rust_struct() {
|
||||||
@ -142,24 +160,32 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
|
|
||||||
if self.cx.config.debug {
|
if self.cx.config.debug {
|
||||||
self.cx.expose_assert_class();
|
self.cx.expose_assert_class();
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
_assertClass({arg}, {struct_});\n\
|
"\
|
||||||
", arg = name, struct_ = s));
|
_assertClass({arg}, {struct_});\n\
|
||||||
|
",
|
||||||
|
arg = name,
|
||||||
|
struct_ = s
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg.is_by_ref() {
|
if arg.is_by_ref() {
|
||||||
self.rust_arguments.push(format!("{}.ptr", name));
|
self.rust_arguments.push(format!("{}.ptr", name));
|
||||||
} else {
|
} else {
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
|
"\
|
||||||
const ptr{i} = {arg}.ptr;\n\
|
const ptr{i} = {arg}.ptr;\n\
|
||||||
if (ptr{i} === 0) {{
|
if (ptr{i} === 0) {{
|
||||||
throw new Error('Attempt to use a moved value');
|
throw new Error('Attempt to use a moved value');
|
||||||
}}
|
}}
|
||||||
{arg}.ptr = 0;\n\
|
{arg}.ptr = 0;\n\
|
||||||
", i = i, arg = name));
|
",
|
||||||
|
i = i,
|
||||||
|
arg = name
|
||||||
|
));
|
||||||
self.rust_arguments.push(format!("ptr{}", i));
|
self.rust_arguments.push(format!("ptr{}", i));
|
||||||
}
|
}
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg.is_number() {
|
if arg.is_number() {
|
||||||
@ -171,7 +197,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.rust_arguments.push(name);
|
self.rust_arguments.push(name);
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(signed) = arg.get_64bit() {
|
if let Some(signed) = arg.get_64bit() {
|
||||||
@ -183,51 +209,55 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
self.cx.expose_uint32_memory();
|
self.cx.expose_uint32_memory();
|
||||||
self.cx.expose_global_argument_ptr()?;
|
self.cx.expose_global_argument_ptr()?;
|
||||||
self.js_arguments.push((name.clone(), "BigInt".to_string()));
|
self.js_arguments.push((name.clone(), "BigInt".to_string()));
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
{f}[0] = {name};\n\
|
"\
|
||||||
const lo{i} = u32CvtShim[0];\n\
|
{f}[0] = {name};\n\
|
||||||
const hi{i} = u32CvtShim[1];\n\
|
const lo{i} = u32CvtShim[0];\n\
|
||||||
",
|
const hi{i} = u32CvtShim[1];\n\
|
||||||
|
",
|
||||||
i = i,
|
i = i,
|
||||||
f = f,
|
f = f,
|
||||||
name = name,
|
name = name,
|
||||||
));
|
));
|
||||||
self.rust_arguments.push(format!("lo{}", i));
|
self.rust_arguments.push(format!("lo{}", i));
|
||||||
self.rust_arguments.push(format!("hi{}", i));
|
self.rust_arguments.push(format!("hi{}", i));
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg.is_ref_anyref() {
|
if arg.is_ref_anyref() {
|
||||||
self.js_arguments.push((name.clone(), "any".to_string()));
|
self.js_arguments.push((name.clone(), "any".to_string()));
|
||||||
self.cx.expose_borrowed_objects();
|
self.cx.expose_borrowed_objects();
|
||||||
self.finally("stack.pop();");
|
self.finally("stack.pop();");
|
||||||
self.rust_arguments.push(format!("addBorrowedObject({})", name));
|
self.rust_arguments
|
||||||
return Ok(self)
|
.push(format!("addBorrowedObject({})", name));
|
||||||
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
match *arg {
|
match *arg {
|
||||||
Descriptor::Boolean => {
|
Descriptor::Boolean => {
|
||||||
self.js_arguments.push((name.clone(), "boolean".to_string()));
|
self.js_arguments
|
||||||
|
.push((name.clone(), "boolean".to_string()));
|
||||||
if self.cx.config.debug {
|
if self.cx.config.debug {
|
||||||
self.cx.expose_assert_bool();
|
self.cx.expose_assert_bool();
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
_assertBoolean({name});\n\
|
"\
|
||||||
", name = name));
|
_assertBoolean({name});\n\
|
||||||
|
",
|
||||||
|
name = name
|
||||||
|
));
|
||||||
}
|
}
|
||||||
self.rust_arguments.push(format!("{} ? 1 : 0", name));
|
self.rust_arguments.push(format!("{} ? 1 : 0", name));
|
||||||
}
|
}
|
||||||
Descriptor::Char => {
|
Descriptor::Char => {
|
||||||
self.js_arguments.push((name.clone(), "string".to_string()));
|
self.js_arguments.push((name.clone(), "string".to_string()));
|
||||||
self.rust_arguments.push(format!("{}.codePointAt(0)", name))
|
self.rust_arguments.push(format!("{}.codePointAt(0)", name))
|
||||||
},
|
}
|
||||||
Descriptor::Anyref => {
|
Descriptor::Anyref => {
|
||||||
self.js_arguments.push((name.clone(), "any".to_string()));
|
self.js_arguments.push((name.clone(), "any".to_string()));
|
||||||
self.cx.expose_add_heap_object();
|
self.cx.expose_add_heap_object();
|
||||||
self.rust_arguments.push(format!("addHeapObject({})", name));
|
self.rust_arguments.push(format!("addHeapObject({})", name));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => bail!("unsupported argument to rust function {:?}", arg),
|
||||||
bail!("unsupported argument to rust function {:?}", arg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
@ -238,7 +268,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
None => {
|
None => {
|
||||||
self.ret_ty = "void".to_string();
|
self.ret_ty = "void".to_string();
|
||||||
self.ret_expr = format!("return RET;");
|
self.ret_expr = format!("return RET;");
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -246,7 +276,7 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
self.ret_ty = "any".to_string();
|
self.ret_ty = "any".to_string();
|
||||||
self.cx.expose_get_object();
|
self.cx.expose_get_object();
|
||||||
self.ret_expr = format!("return getObject(RET);");
|
self.ret_expr = format!("return getObject(RET);");
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ty.is_by_ref() {
|
if ty.is_by_ref() {
|
||||||
@ -261,28 +291,32 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
self.cx.require_internal_export("__wbindgen_free")?;
|
self.cx.require_internal_export("__wbindgen_free")?;
|
||||||
self.prelude("const retptr = globalArgumentPtr();");
|
self.prelude("const retptr = globalArgumentPtr();");
|
||||||
self.rust_arguments.insert(0, "retptr".to_string());
|
self.rust_arguments.insert(0, "retptr".to_string());
|
||||||
self.ret_expr = format!("\
|
self.ret_expr = format!(
|
||||||
RET;\n\
|
"\
|
||||||
const mem = getUint32Memory();\n\
|
RET;\n\
|
||||||
const ptr = mem[retptr / 4];\n\
|
const mem = getUint32Memory();\n\
|
||||||
const len = mem[retptr / 4 + 1];\n\
|
const ptr = mem[retptr / 4];\n\
|
||||||
const realRet = {}(ptr, len).slice();\n\
|
const len = mem[retptr / 4 + 1];\n\
|
||||||
wasm.__wbindgen_free(ptr, len * {});\n\
|
const realRet = {}(ptr, len).slice();\n\
|
||||||
return realRet;\n\
|
wasm.__wbindgen_free(ptr, len * {});\n\
|
||||||
", f, ty.size());
|
return realRet;\n\
|
||||||
return Ok(self)
|
",
|
||||||
|
f,
|
||||||
|
ty.size()
|
||||||
|
);
|
||||||
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = ty.rust_struct() {
|
if let Some(name) = ty.rust_struct() {
|
||||||
self.ret_ty = name.to_string();
|
self.ret_ty = name.to_string();
|
||||||
self.ret_expr = format!("return {name}.__construct(RET);", name = name);
|
self.ret_expr = format!("return {name}.__construct(RET);", name = name);
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ty.is_number() {
|
if ty.is_number() {
|
||||||
self.ret_ty = "number".to_string();
|
self.ret_ty = "number".to_string();
|
||||||
self.ret_expr = format!("return RET;");
|
self.ret_expr = format!("return RET;");
|
||||||
return Ok(self)
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(signed) = ty.get_64bit() {
|
if let Some(signed) = ty.get_64bit() {
|
||||||
@ -297,11 +331,14 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
};
|
};
|
||||||
self.prelude("const retptr = globalArgumentPtr();");
|
self.prelude("const retptr = globalArgumentPtr();");
|
||||||
self.rust_arguments.insert(0, "retptr".to_string());
|
self.rust_arguments.insert(0, "retptr".to_string());
|
||||||
self.ret_expr = format!("\
|
self.ret_expr = format!(
|
||||||
RET;\n\
|
"\
|
||||||
return {}()[retptr / 8];\n\
|
RET;\n\
|
||||||
", f);
|
return {}()[retptr / 8];\n\
|
||||||
return Ok(self)
|
",
|
||||||
|
f
|
||||||
|
);
|
||||||
|
return Ok(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
match *ty {
|
match *ty {
|
||||||
@ -333,7 +370,8 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
/// generated function shim and the second is a TypeScript signature of the
|
/// generated function shim and the second is a TypeScript signature of the
|
||||||
/// JS expression.
|
/// JS expression.
|
||||||
pub fn finish(&self, prefix: &str, invoc: &str) -> (String, String) {
|
pub fn finish(&self, prefix: &str, invoc: &str) -> (String, String) {
|
||||||
let js_args = self.js_arguments
|
let js_args = self
|
||||||
|
.js_arguments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| &s.0[..])
|
.map(|s| &s.0[..])
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
@ -342,29 +380,35 @@ impl<'a, 'b> Js2Rust<'a, 'b> {
|
|||||||
js.push_str(&self.prelude);
|
js.push_str(&self.prelude);
|
||||||
let rust_args = self.rust_arguments.join(", ");
|
let rust_args = self.rust_arguments.join(", ");
|
||||||
|
|
||||||
let invoc = self.ret_expr.replace("RET", &format!("{}({})", invoc, rust_args));
|
let invoc = self
|
||||||
|
.ret_expr
|
||||||
|
.replace("RET", &format!("{}({})", invoc, rust_args));
|
||||||
let invoc = if self.finally.len() == 0 {
|
let invoc = if self.finally.len() == 0 {
|
||||||
invoc
|
invoc
|
||||||
} else {
|
} else {
|
||||||
format!("\
|
format!(
|
||||||
|
"\
|
||||||
try {{\n\
|
try {{\n\
|
||||||
{}
|
{}
|
||||||
\n}} finally {{\n\
|
\n}} finally {{\n\
|
||||||
{}
|
{}
|
||||||
}}\n\
|
}}\n\
|
||||||
",
|
",
|
||||||
&invoc,
|
&invoc, &self.finally,
|
||||||
&self.finally,
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
js.push_str(&invoc);
|
js.push_str(&invoc);
|
||||||
js.push_str("\n}");
|
js.push_str("\n}");
|
||||||
let ts_args = self.js_arguments
|
let ts_args = self
|
||||||
|
.js_arguments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| format!("{}: {}", s.0, s.1))
|
.map(|s| format!("{}: {}", s.0, s.1))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(", ");
|
.join(", ");
|
||||||
let ts = format!("{} {}({}): {};\n", prefix, self.js_name, ts_args, self.ret_ty);
|
let ts = format!(
|
||||||
|
"{} {}({}): {};\n",
|
||||||
|
prefix, self.js_name, ts_args, self.ret_ty
|
||||||
|
);
|
||||||
(js, ts)
|
(js, ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
use failure::Error;
|
use failure::Error;
|
||||||
|
|
||||||
use descriptor::{Descriptor, Function};
|
|
||||||
use super::{Context, Js2Rust};
|
use super::{Context, Js2Rust};
|
||||||
|
use descriptor::{Descriptor, Function};
|
||||||
|
|
||||||
/// Helper struct for manufacturing 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.
|
/// JS, then invoking an imported JS function.
|
||||||
@ -85,18 +85,27 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
if let Some(ty) = arg.vector_kind() {
|
if let Some(ty) = arg.vector_kind() {
|
||||||
let abi2 = self.shim_argument();
|
let abi2 = self.shim_argument();
|
||||||
let f = self.cx.expose_get_vector_from_wasm(ty);
|
let f = self.cx.expose_get_vector_from_wasm(ty);
|
||||||
self.prelude(&format!("let v{0} = {func}({0}, {1});",
|
self.prelude(&format!(
|
||||||
abi, abi2, func = f));
|
"let v{0} = {func}({0}, {1});",
|
||||||
|
abi,
|
||||||
|
abi2,
|
||||||
|
func = f
|
||||||
|
));
|
||||||
|
|
||||||
if !arg.is_by_ref() {
|
if !arg.is_by_ref() {
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
v{0} = v{0}.slice();\n\
|
"\
|
||||||
wasm.__wbindgen_free({0}, {1} * {size});\
|
v{0} = v{0}.slice();\n\
|
||||||
", abi, abi2, size = ty.size()));
|
wasm.__wbindgen_free({0}, {1} * {size});\
|
||||||
|
",
|
||||||
|
abi,
|
||||||
|
abi2,
|
||||||
|
size = ty.size()
|
||||||
|
));
|
||||||
self.cx.require_internal_export("__wbindgen_free")?;
|
self.cx.require_internal_export("__wbindgen_free")?;
|
||||||
}
|
}
|
||||||
self.js_arguments.push(format!("v{}", abi));
|
self.js_arguments.push(format!("v{}", abi));
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(signed) = arg.get_64bit() {
|
if let Some(signed) = arg.get_64bit() {
|
||||||
@ -107,18 +116,19 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
};
|
};
|
||||||
let hi = self.shim_argument();
|
let hi = self.shim_argument();
|
||||||
let name = format!("n{}", abi);
|
let name = format!("n{}", abi);
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
u32CvtShim[0] = {lo};\n\
|
"\
|
||||||
u32CvtShim[1] = {hi};\n\
|
u32CvtShim[0] = {lo};\n\
|
||||||
const {name} = {f}[0];\n\
|
u32CvtShim[1] = {hi};\n\
|
||||||
",
|
const {name} = {f}[0];\n\
|
||||||
|
",
|
||||||
lo = abi,
|
lo = abi,
|
||||||
hi = hi,
|
hi = hi,
|
||||||
f = f,
|
f = f,
|
||||||
name = name,
|
name = name,
|
||||||
));
|
));
|
||||||
self.js_arguments.push(name);
|
self.js_arguments.push(name);
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(class) = arg.rust_struct() {
|
if let Some(class) = arg.rust_struct() {
|
||||||
@ -128,14 +138,15 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
let assign = format!("let c{0} = {1}.__construct({0});", abi, class);
|
let assign = format!("let c{0} = {1}.__construct({0});", abi, class);
|
||||||
self.prelude(&assign);
|
self.prelude(&assign);
|
||||||
self.js_arguments.push(format!("c{}", abi));
|
self.js_arguments.push(format!("c{}", abi));
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some((f, mutable)) = arg.stack_closure() {
|
if let Some((f, mutable)) = arg.stack_closure() {
|
||||||
let (js, _ts) = {
|
let (js, _ts) = {
|
||||||
let mut builder = Js2Rust::new("", self.cx);
|
let mut builder = Js2Rust::new("", self.cx);
|
||||||
if mutable {
|
if mutable {
|
||||||
builder.prelude("let a = this.a;\n")
|
builder
|
||||||
|
.prelude("let a = this.a;\n")
|
||||||
.prelude("this.a = 0;\n")
|
.prelude("this.a = 0;\n")
|
||||||
.rust_argument("a")
|
.rust_argument("a")
|
||||||
.finally("this.a = a;\n");
|
.finally("this.a = a;\n");
|
||||||
@ -151,22 +162,28 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
self.cx.function_table_needed = true;
|
self.cx.function_table_needed = true;
|
||||||
let next_global = self.global_idx();
|
let next_global = self.global_idx();
|
||||||
self.global_idx();
|
self.global_idx();
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
let cb{0} = {js};\n\
|
"\
|
||||||
cb{0}.f = wasm.__wbg_function_table.get({0});\n\
|
let cb{0} = {js};\n\
|
||||||
cb{0}.a = getGlobalArgument({next_global});\n\
|
cb{0}.f = wasm.__wbg_function_table.get({0});\n\
|
||||||
cb{0}.b = getGlobalArgument({next_global} + 1);\n\
|
cb{0}.a = getGlobalArgument({next_global});\n\
|
||||||
", abi, js = js, next_global = next_global));
|
cb{0}.b = getGlobalArgument({next_global} + 1);\n\
|
||||||
|
",
|
||||||
|
abi,
|
||||||
|
js = js,
|
||||||
|
next_global = next_global
|
||||||
|
));
|
||||||
self.finally(&format!("cb{0}.a = cb{0}.b = 0;", abi));
|
self.finally(&format!("cb{0}.a = cb{0}.b = 0;", abi));
|
||||||
self.js_arguments.push(format!("cb{0}.bind(cb{0})", abi));
|
self.js_arguments.push(format!("cb{0}.bind(cb{0})", abi));
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(closure) = arg.ref_closure() {
|
if let Some(closure) = arg.ref_closure() {
|
||||||
let (js, _ts) = {
|
let (js, _ts) = {
|
||||||
let mut builder = Js2Rust::new("", self.cx);
|
let mut builder = Js2Rust::new("", self.cx);
|
||||||
if closure.mutable {
|
if closure.mutable {
|
||||||
builder.prelude("let a = this.a;\n")
|
builder
|
||||||
|
.prelude("let a = this.a;\n")
|
||||||
.prelude("this.a = 0;\n")
|
.prelude("this.a = 0;\n")
|
||||||
.rust_argument("a")
|
.rust_argument("a")
|
||||||
.finally("this.a = a;\n");
|
.finally("this.a = a;\n");
|
||||||
@ -182,38 +199,40 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
self.cx.expose_uint32_memory();
|
self.cx.expose_uint32_memory();
|
||||||
self.cx.expose_add_heap_object();
|
self.cx.expose_add_heap_object();
|
||||||
self.cx.function_table_needed = true;
|
self.cx.function_table_needed = true;
|
||||||
let reset_idx = format!("\
|
let reset_idx = format!(
|
||||||
let cb{0} = {js};\n\
|
"\
|
||||||
cb{0}.a = getGlobalArgument({a});\n\
|
let cb{0} = {js};\n\
|
||||||
cb{0}.b = getGlobalArgument({b});\n\
|
cb{0}.a = getGlobalArgument({a});\n\
|
||||||
cb{0}.f = wasm.__wbg_function_table.get(getGlobalArgument({c}));\n\
|
cb{0}.b = getGlobalArgument({b});\n\
|
||||||
let real = cb{0}.bind(cb{0});\n\
|
cb{0}.f = wasm.__wbg_function_table.get(getGlobalArgument({c}));\n\
|
||||||
real.original = cb{0};\n\
|
let real = cb{0}.bind(cb{0});\n\
|
||||||
idx{0} = getUint32Memory()[{0} / 4] = addHeapObject(real);\n\
|
real.original = cb{0};\n\
|
||||||
",
|
idx{0} = getUint32Memory()[{0} / 4] = addHeapObject(real);\n\
|
||||||
|
",
|
||||||
abi,
|
abi,
|
||||||
js = js,
|
js = js,
|
||||||
a = self.global_idx(),
|
a = self.global_idx(),
|
||||||
b = self.global_idx(),
|
b = self.global_idx(),
|
||||||
c = self.global_idx(),
|
c = self.global_idx(),
|
||||||
);
|
);
|
||||||
self.prelude(&format!("\
|
self.prelude(&format!(
|
||||||
let idx{0} = getUint32Memory()[{0} / 4];\n\
|
"\
|
||||||
if (idx{0} === 0xffffffff) {{\n\
|
let idx{0} = getUint32Memory()[{0} / 4];\n\
|
||||||
{1}\
|
if (idx{0} === 0xffffffff) {{\n\
|
||||||
}}\n\
|
{1}\
|
||||||
", abi, &reset_idx));
|
}}\n\
|
||||||
|
",
|
||||||
|
abi, &reset_idx
|
||||||
|
));
|
||||||
self.cx.expose_get_object();
|
self.cx.expose_get_object();
|
||||||
self.js_arguments.push(format!("getObject(idx{})", abi));
|
self.js_arguments.push(format!("getObject(idx{})", abi));
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let invoc_arg = match *arg {
|
let invoc_arg = match *arg {
|
||||||
ref d if d.is_number() => abi,
|
ref d if d.is_number() => abi,
|
||||||
Descriptor::Boolean => format!("{} !== 0", abi),
|
Descriptor::Boolean => format!("{} !== 0", abi),
|
||||||
Descriptor::Char => {
|
Descriptor::Char => format!("String.fromCodePoint({})", abi),
|
||||||
format!("String.fromCodePoint({})", abi)
|
|
||||||
}
|
|
||||||
Descriptor::Anyref => {
|
Descriptor::Anyref => {
|
||||||
self.cx.expose_take_object();
|
self.cx.expose_take_object();
|
||||||
format!("takeObject({})", abi)
|
format!("takeObject({})", abi)
|
||||||
@ -222,7 +241,10 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
self.cx.expose_get_object();
|
self.cx.expose_get_object();
|
||||||
format!("getObject({})", abi)
|
format!("getObject({})", abi)
|
||||||
}
|
}
|
||||||
_ => bail!("unimplemented argument type in imported function: {:?}", arg),
|
_ => bail!(
|
||||||
|
"unimplemented argument type in imported function: {:?}",
|
||||||
|
arg
|
||||||
|
),
|
||||||
};
|
};
|
||||||
self.js_arguments.push(invoc_arg);
|
self.js_arguments.push(invoc_arg);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -233,7 +255,7 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
Some(ref t) => t,
|
Some(ref t) => t,
|
||||||
None => {
|
None => {
|
||||||
self.ret_expr = "JS;".to_string();
|
self.ret_expr = "JS;".to_string();
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if ty.is_by_ref() {
|
if ty.is_by_ref() {
|
||||||
@ -243,17 +265,20 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
let f = self.cx.pass_to_wasm_function(ty)?;
|
let f = self.cx.pass_to_wasm_function(ty)?;
|
||||||
self.cx.expose_uint32_memory();
|
self.cx.expose_uint32_memory();
|
||||||
self.shim_arguments.insert(0, "ret".to_string());
|
self.shim_arguments.insert(0, "ret".to_string());
|
||||||
self.ret_expr = format!("\
|
self.ret_expr = format!(
|
||||||
|
"\
|
||||||
const [retptr, retlen] = {}(JS);\n\
|
const [retptr, retlen] = {}(JS);\n\
|
||||||
const mem = getUint32Memory();
|
const mem = getUint32Memory();
|
||||||
mem[ret / 4] = retptr;
|
mem[ret / 4] = retptr;
|
||||||
mem[ret / 4 + 1] = retlen;
|
mem[ret / 4 + 1] = retlen;
|
||||||
", f);
|
",
|
||||||
return Ok(())
|
f
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
if ty.is_number() {
|
if ty.is_number() {
|
||||||
self.ret_expr = "return JS;".to_string();
|
self.ret_expr = "return JS;".to_string();
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
if let Some(signed) = ty.get_64bit() {
|
if let Some(signed) = ty.get_64bit() {
|
||||||
let f = if signed {
|
let f = if signed {
|
||||||
@ -264,11 +289,14 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
"getUint64Memory"
|
"getUint64Memory"
|
||||||
};
|
};
|
||||||
self.shim_arguments.insert(0, "ret".to_string());
|
self.shim_arguments.insert(0, "ret".to_string());
|
||||||
self.ret_expr = format!("\
|
self.ret_expr = format!(
|
||||||
const val = JS;\n\
|
"\
|
||||||
{}()[ret / 8] = val;\n\
|
const val = JS;\n\
|
||||||
", f);
|
{}()[ret / 8] = val;\n\
|
||||||
return Ok(())
|
",
|
||||||
|
f
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
self.ret_expr = match *ty {
|
self.ret_expr = match *ty {
|
||||||
Descriptor::Boolean => "return JS ? 1 : 0;".to_string(),
|
Descriptor::Boolean => "return JS ? 1 : 0;".to_string(),
|
||||||
@ -301,33 +329,39 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
|
|||||||
);
|
);
|
||||||
if self.catch {
|
if self.catch {
|
||||||
let catch = "\
|
let catch = "\
|
||||||
const view = getUint32Memory();\n\
|
const view = getUint32Memory();\n\
|
||||||
view[exnptr / 4] = 1;\n\
|
view[exnptr / 4] = 1;\n\
|
||||||
view[exnptr / 4 + 1] = addHeapObject(e);\n\
|
view[exnptr / 4 + 1] = addHeapObject(e);\n\
|
||||||
";
|
";
|
||||||
|
|
||||||
invoc = format!("\
|
invoc = format!(
|
||||||
try {{\n\
|
"\
|
||||||
{}
|
try {{\n\
|
||||||
}} catch (e) {{\n\
|
{}
|
||||||
{}
|
}} catch (e) {{\n\
|
||||||
}}\
|
{}
|
||||||
", &invoc, catch);
|
}}\
|
||||||
|
",
|
||||||
|
&invoc, catch
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.finally.len() > 0 {
|
if self.finally.len() > 0 {
|
||||||
invoc = format!("\
|
invoc = format!(
|
||||||
try {{\n\
|
"\
|
||||||
{}
|
try {{\n\
|
||||||
}} finally {{\n\
|
{}
|
||||||
{}
|
}} finally {{\n\
|
||||||
}}\
|
{}
|
||||||
", &invoc, &self.finally);
|
}}\
|
||||||
|
",
|
||||||
|
&invoc, &self.finally
|
||||||
|
);
|
||||||
}
|
}
|
||||||
ret.push_str(&invoc);
|
ret.push_str(&invoc);
|
||||||
|
|
||||||
ret.push_str("\n}\n");
|
ret.push_str("\n}\n");
|
||||||
return ret
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn global_idx(&mut self) -> usize {
|
fn global_idx(&mut self) -> usize {
|
||||||
|
@ -17,8 +17,8 @@ use std::path::{Path, PathBuf};
|
|||||||
use failure::{Error, ResultExt};
|
use failure::{Error, ResultExt};
|
||||||
use parity_wasm::elements::*;
|
use parity_wasm::elements::*;
|
||||||
|
|
||||||
mod js;
|
|
||||||
mod descriptor;
|
mod descriptor;
|
||||||
|
mod js;
|
||||||
pub mod wasm2es6js;
|
pub mod wasm2es6js;
|
||||||
|
|
||||||
pub struct Bindgen {
|
pub struct Bindgen {
|
||||||
@ -142,11 +142,9 @@ impl Bindgen {
|
|||||||
let mut v = MyExternals(Vec::new());
|
let mut v = MyExternals(Vec::new());
|
||||||
match instance.invoke_export(name, &[], &mut v) {
|
match instance.invoke_export(name, &[], &mut v) {
|
||||||
Ok(None) => Some(v.0),
|
Ok(None) => Some(v.0),
|
||||||
Ok(Some(_)) => {
|
Ok(Some(_)) => unreachable!(
|
||||||
unreachable!(
|
"there is only one export, and we only return None from it"
|
||||||
"there is only one export, and we only return None from it"
|
),
|
||||||
)
|
|
||||||
},
|
|
||||||
// Allow missing exported describe functions. This can
|
// Allow missing exported describe functions. This can
|
||||||
// happen when a nested dependency crate exports things
|
// happen when a nested dependency crate exports things
|
||||||
// but the root crate doesn't use them.
|
// but the root crate doesn't use them.
|
||||||
@ -207,13 +205,16 @@ impl Bindgen {
|
|||||||
shim.push_str(&format!("imports['{0}'] = require('{0}');\n", module));
|
shim.push_str(&format!("imports['{0}'] = require('{0}');\n", module));
|
||||||
}
|
}
|
||||||
|
|
||||||
shim.push_str(&format!("
|
shim.push_str(&format!(
|
||||||
|
"
|
||||||
const join = require('path').join;
|
const join = require('path').join;
|
||||||
const bytes = require('fs').readFileSync(join(__dirname, '{}'));
|
const bytes = require('fs').readFileSync(join(__dirname, '{}'));
|
||||||
const wasmModule = new WebAssembly.Module(bytes);
|
const wasmModule = new WebAssembly.Module(bytes);
|
||||||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
||||||
module.exports = wasmInstance.exports;
|
module.exports = wasmInstance.exports;
|
||||||
", path.file_name().unwrap().to_str().unwrap()));
|
",
|
||||||
|
path.file_name().unwrap().to_str().unwrap()
|
||||||
|
));
|
||||||
|
|
||||||
reset_indentation(&shim)
|
reset_indentation(&shim)
|
||||||
}
|
}
|
||||||
@ -230,27 +231,25 @@ fn extract_programs(module: &mut Module) -> Result<Vec<shared::Program>, Error>
|
|||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
if custom.name() != "__wasm_bindgen_unstable" {
|
if custom.name() != "__wasm_bindgen_unstable" {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
to_remove.push(i);
|
to_remove.push(i);
|
||||||
|
|
||||||
let mut payload = custom.payload();
|
let mut payload = custom.payload();
|
||||||
while payload.len() > 0 {
|
while payload.len() > 0 {
|
||||||
let len =
|
let len = ((payload[0] as usize) << 0)
|
||||||
((payload[0] as usize) << 0) |
|
| ((payload[1] as usize) << 8)
|
||||||
((payload[1] as usize) << 8) |
|
| ((payload[2] as usize) << 16)
|
||||||
((payload[2] as usize) << 16) |
|
| ((payload[3] as usize) << 24);
|
||||||
((payload[3] as usize) << 24);
|
|
||||||
let (a, b) = payload[4..].split_at(len as usize);
|
let (a, b) = payload[4..].split_at(len as usize);
|
||||||
payload = b;
|
payload = b;
|
||||||
let p: shared::ProgramOnlySchema = match serde_json::from_slice(&a) {
|
let p: shared::ProgramOnlySchema = match serde_json::from_slice(&a) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => bail!("failed to decode what looked like wasm-bindgen data: {}", e),
|
||||||
bail!("failed to decode what looked like wasm-bindgen data: {}", e)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if p.schema_version != shared::SCHEMA_VERSION {
|
if p.schema_version != shared::SCHEMA_VERSION {
|
||||||
bail!("
|
bail!(
|
||||||
|
"
|
||||||
|
|
||||||
it looks like the Rust project used to create this wasm file was linked against
|
it looks like the Rust project used to create this wasm file was linked against
|
||||||
a different version of wasm-bindgen than this binary:
|
a different version of wasm-bindgen than this binary:
|
||||||
@ -272,13 +271,13 @@ or you can update the binary with
|
|||||||
if this warning fails to go away though and you're not sure what to do feel free
|
if this warning fails to go away though and you're not sure what to do feel free
|
||||||
to open an issue at https://github.com/alexcrichton/wasm-bindgen/issues!
|
to open an issue at https://github.com/alexcrichton/wasm-bindgen/issues!
|
||||||
",
|
",
|
||||||
p.version, version);
|
p.version,
|
||||||
|
version
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let p: shared::Program = match serde_json::from_slice(&a) {
|
let p: shared::Program = match serde_json::from_slice(&a) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => bail!("failed to decode what looked like wasm-bindgen data: {}", e),
|
||||||
bail!("failed to decode what looked like wasm-bindgen data: {}", e)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
ret.push(p);
|
ret.push(p);
|
||||||
}
|
}
|
||||||
@ -297,13 +296,13 @@ impl wasmi::ImportResolver for MyResolver {
|
|||||||
&self,
|
&self,
|
||||||
module_name: &str,
|
module_name: &str,
|
||||||
field_name: &str,
|
field_name: &str,
|
||||||
signature: &wasmi::Signature
|
signature: &wasmi::Signature,
|
||||||
) -> Result<wasmi::FuncRef, wasmi::Error> {
|
) -> Result<wasmi::FuncRef, wasmi::Error> {
|
||||||
// Route our special "describe" export to 1 and everything else to 0.
|
// Route our special "describe" export to 1 and everything else to 0.
|
||||||
// That way whenever the function 1 is invoked we know what to do and
|
// That way whenever the function 1 is invoked we know what to do and
|
||||||
// when 0 is invoked (by accident) we'll trap and produce an error.
|
// when 0 is invoked (by accident) we'll trap and produce an error.
|
||||||
let idx = (module_name == "__wbindgen_placeholder__" &&
|
let idx = (module_name == "__wbindgen_placeholder__" && field_name == "__wbindgen_describe")
|
||||||
field_name == "__wbindgen_describe") as usize;
|
as usize;
|
||||||
Ok(wasmi::FuncInstance::alloc_host(signature.clone(), idx))
|
Ok(wasmi::FuncInstance::alloc_host(signature.clone(), idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +310,7 @@ impl wasmi::ImportResolver for MyResolver {
|
|||||||
&self,
|
&self,
|
||||||
_module_name: &str,
|
_module_name: &str,
|
||||||
_field_name: &str,
|
_field_name: &str,
|
||||||
descriptor: &wasmi::GlobalDescriptor
|
descriptor: &wasmi::GlobalDescriptor,
|
||||||
) -> Result<wasmi::GlobalRef, wasmi::Error> {
|
) -> Result<wasmi::GlobalRef, wasmi::Error> {
|
||||||
// dummy implementation to ensure instantiation succeeds
|
// dummy implementation to ensure instantiation succeeds
|
||||||
let val = match descriptor.value_type() {
|
let val = match descriptor.value_type() {
|
||||||
@ -340,7 +339,7 @@ impl wasmi::ImportResolver for MyResolver {
|
|||||||
&self,
|
&self,
|
||||||
_module_name: &str,
|
_module_name: &str,
|
||||||
_field_name: &str,
|
_field_name: &str,
|
||||||
descriptor: &wasmi::TableDescriptor
|
descriptor: &wasmi::TableDescriptor,
|
||||||
) -> Result<wasmi::TableRef, wasmi::Error> {
|
) -> Result<wasmi::TableRef, wasmi::Error> {
|
||||||
// dummy implementation to ensure instantiation succeeds
|
// dummy implementation to ensure instantiation succeeds
|
||||||
let initial = descriptor.initial();
|
let initial = descriptor.initial();
|
||||||
@ -358,7 +357,7 @@ impl wasmi::Externals for MyExternals {
|
|||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: usize,
|
index: usize,
|
||||||
args: wasmi::RuntimeArgs
|
args: wasmi::RuntimeArgs,
|
||||||
) -> Result<Option<wasmi::RuntimeValue>, wasmi::Trap> {
|
) -> Result<Option<wasmi::RuntimeValue>, wasmi::Trap> {
|
||||||
macro_rules! bail {
|
macro_rules! bail {
|
||||||
($($t:tt)*) => ({
|
($($t:tt)*) => ({
|
||||||
@ -413,7 +412,12 @@ fn indent_recurse(mut lines: ::std::str::Lines, current_indent: usize) -> String
|
|||||||
if trimmed.starts_with('?') || trimmed.starts_with(':') {
|
if trimmed.starts_with('?') || trimmed.starts_with(':') {
|
||||||
current_indent += 1;
|
current_indent += 1;
|
||||||
}
|
}
|
||||||
format!("\n{}{}{}", " ".repeat(current_indent), &trimmed, &indent_recurse(lines, next_indent))
|
format!(
|
||||||
|
"\n{}{}{}",
|
||||||
|
" ".repeat(current_indent),
|
||||||
|
&trimmed,
|
||||||
|
&indent_recurse(lines, next_indent)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
extern crate base64;
|
extern crate base64;
|
||||||
extern crate tempfile;
|
extern crate tempfile;
|
||||||
|
|
||||||
use std::collections::{HashSet, HashMap};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write, Read};
|
use std::io::{self, Read, Write};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use parity_wasm::elements::*;
|
|
||||||
use failure::{Error, ResultExt};
|
use failure::{Error, ResultExt};
|
||||||
|
use parity_wasm::elements::*;
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
base64: bool,
|
base64: bool,
|
||||||
@ -65,31 +65,36 @@ impl Output {
|
|||||||
let mut exports = format!("/* tslint:disable */\n");
|
let mut exports = format!("/* tslint:disable */\n");
|
||||||
|
|
||||||
if let Some(i) = self.module.export_section() {
|
if let Some(i) = self.module.export_section() {
|
||||||
let imported_functions = self.module.import_section()
|
let imported_functions = self
|
||||||
|
.module
|
||||||
|
.import_section()
|
||||||
.map(|m| m.functions() as u32)
|
.map(|m| m.functions() as u32)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
for entry in i.entries() {
|
for entry in i.entries() {
|
||||||
let idx = match *entry.internal() {
|
let idx = match *entry.internal() {
|
||||||
Internal::Function(i) => i - imported_functions,
|
Internal::Function(i) => i - imported_functions,
|
||||||
Internal::Memory(_) => {
|
Internal::Memory(_) => {
|
||||||
exports.push_str(&format!("
|
exports.push_str(&format!(
|
||||||
|
"
|
||||||
export const {}: WebAssembly.Memory;
|
export const {}: WebAssembly.Memory;
|
||||||
", entry.field()));
|
",
|
||||||
continue
|
entry.field()
|
||||||
}
|
));
|
||||||
Internal::Table(_) => {
|
continue;
|
||||||
continue
|
|
||||||
}
|
|
||||||
Internal::Global(_) => {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
Internal::Table(_) => continue,
|
||||||
|
Internal::Global(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let functions = self.module.function_section()
|
let functions = self
|
||||||
|
.module
|
||||||
|
.function_section()
|
||||||
.expect("failed to find function section");
|
.expect("failed to find function section");
|
||||||
let idx = functions.entries()[idx as usize].type_ref();
|
let idx = functions.entries()[idx as usize].type_ref();
|
||||||
|
|
||||||
let types = self.module.type_section()
|
let types = self
|
||||||
|
.module
|
||||||
|
.type_section()
|
||||||
.expect("failed to find type section");
|
.expect("failed to find type section");
|
||||||
let ty = match types.types()[idx as usize] {
|
let ty = match types.types()[idx as usize] {
|
||||||
Type::Function(ref f) => f,
|
Type::Function(ref f) => f,
|
||||||
@ -103,12 +108,17 @@ impl Output {
|
|||||||
args.push_str(": number");
|
args.push_str(": number");
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.push_str(&format!("
|
exports.push_str(&format!(
|
||||||
|
"
|
||||||
export function {name}({args}): {ret};
|
export function {name}({args}): {ret};
|
||||||
",
|
",
|
||||||
name = entry.field(),
|
name = entry.field(),
|
||||||
args = args,
|
args = args,
|
||||||
ret = if ty.return_type().is_some() { "number" } else { "void" },
|
ret = if ty.return_type().is_some() {
|
||||||
|
"number"
|
||||||
|
} else {
|
||||||
|
"void"
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +127,7 @@ impl Output {
|
|||||||
exports.push_str("export const booted: Promise<boolean>;");
|
exports.push_str("export const booted: Promise<boolean>;");
|
||||||
}
|
}
|
||||||
|
|
||||||
return exports
|
return exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn js(self) -> Result<String, Error> {
|
pub fn js(self) -> Result<String, Error> {
|
||||||
@ -146,19 +156,23 @@ impl Output {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !set.insert(entry.module()) {
|
if !set.insert(entry.module()) {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = (b'a' + (set.len() as u8)) as char;
|
let name = (b'a' + (set.len() as u8)) as char;
|
||||||
js_imports.push_str(&format!("import * as import_{} from '{}';",
|
js_imports.push_str(&format!(
|
||||||
name,
|
"import * as import_{} from '{}';",
|
||||||
entry.module()));
|
name,
|
||||||
|
entry.module()
|
||||||
|
));
|
||||||
imports.push_str(&format!("'{}': import_{}, ", entry.module(), name));
|
imports.push_str(&format!("'{}': import_{}, ", entry.module(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(i) = self.module.export_section() {
|
if let Some(i) = self.module.export_section() {
|
||||||
let imported_functions = self.module.import_section()
|
let imported_functions = self
|
||||||
|
.module
|
||||||
|
.import_section()
|
||||||
.map(|m| m.functions() as u32)
|
.map(|m| m.functions() as u32)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
for entry in i.entries() {
|
for entry in i.entries() {
|
||||||
@ -166,21 +180,21 @@ impl Output {
|
|||||||
Internal::Function(i) => i - imported_functions,
|
Internal::Function(i) => i - imported_functions,
|
||||||
Internal::Memory(_) => {
|
Internal::Memory(_) => {
|
||||||
export_mem = true;
|
export_mem = true;
|
||||||
continue
|
continue;
|
||||||
}
|
|
||||||
Internal::Table(_) => {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
Internal::Global(_) => {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
Internal::Table(_) => continue,
|
||||||
|
Internal::Global(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let functions = self.module.function_section()
|
let functions = self
|
||||||
|
.module
|
||||||
|
.function_section()
|
||||||
.expect("failed to find function section");
|
.expect("failed to find function section");
|
||||||
let idx = functions.entries()[idx as usize].type_ref();
|
let idx = functions.entries()[idx as usize].type_ref();
|
||||||
|
|
||||||
let types = self.module.type_section()
|
let types = self
|
||||||
|
.module
|
||||||
|
.type_section()
|
||||||
.expect("failed to find type section");
|
.expect("failed to find type section");
|
||||||
let ty = match types.types()[idx as usize] {
|
let ty = match types.types()[idx as usize] {
|
||||||
Type::Function(ref f) => f,
|
Type::Function(ref f) => f,
|
||||||
@ -193,57 +207,79 @@ impl Output {
|
|||||||
args.push((b'a' + (i as u8)) as char);
|
args.push((b'a' + (i as u8)) as char);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.push_str(&format!("
|
exports.push_str(&format!(
|
||||||
|
"
|
||||||
export function {name}({args}) {{
|
export function {name}({args}) {{
|
||||||
{ret} wasm.exports.{name}({args});
|
{ret} wasm.exports.{name}({args});
|
||||||
}}
|
}}
|
||||||
",
|
",
|
||||||
name = entry.field(),
|
name = entry.field(),
|
||||||
args = args,
|
args = args,
|
||||||
ret = if ty.return_type().is_some() { "return" } else { "" },
|
ret = if ty.return_type().is_some() {
|
||||||
|
"return"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let inst = format!("WebAssembly.instantiate(bytes,{{ {imports} }})
|
let inst = format!(
|
||||||
|
"
|
||||||
|
WebAssembly.instantiate(bytes,{{ {imports} }})
|
||||||
.then(obj => {{
|
.then(obj => {{
|
||||||
wasm = obj.instance;
|
wasm = obj.instance;
|
||||||
{memory}
|
{memory}
|
||||||
}})",
|
}})
|
||||||
imports = imports,
|
",
|
||||||
memory = if export_mem { "memory = wasm.exports.memory;" } else { "" },
|
imports = imports,
|
||||||
);
|
memory = if export_mem {
|
||||||
|
"memory = wasm.exports.memory;"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
);
|
||||||
let (bytes, booted) = if self.base64 {
|
let (bytes, booted) = if self.base64 {
|
||||||
let wasm = serialize(self.module)
|
let wasm = serialize(self.module).expect("failed to serialize");
|
||||||
.expect("failed to serialize");
|
|
||||||
(
|
(
|
||||||
format!("
|
format!(
|
||||||
|
"
|
||||||
let bytes;
|
let bytes;
|
||||||
const base64 = \"{base64}\";
|
const base64 = \"{base64}\";
|
||||||
if (typeof Buffer === 'undefined') {{
|
if (typeof Buffer === 'undefined') {{
|
||||||
bytes = Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
bytes = Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
||||||
}} else {{
|
}} else {{
|
||||||
bytes = Buffer.from(base64, 'base64');
|
bytes = Buffer.from(base64, 'base64');
|
||||||
}}", base64 = base64::encode(&wasm)),
|
}}
|
||||||
inst
|
",
|
||||||
|
base64 = base64::encode(&wasm)
|
||||||
|
),
|
||||||
|
inst,
|
||||||
)
|
)
|
||||||
} else if let Some(ref path) = self.fetch_path {
|
} else if let Some(ref path) = self.fetch_path {
|
||||||
(
|
(
|
||||||
String::new(),
|
String::new(),
|
||||||
format!("fetch('{path}')
|
format!(
|
||||||
.then(res => res.arrayBuffer())
|
"
|
||||||
.then(bytes => {inst})", path = path, inst = inst)
|
fetch('{path}')
|
||||||
|
.then(res => res.arrayBuffer())
|
||||||
|
.then(bytes => {inst})
|
||||||
|
",
|
||||||
|
path = path,
|
||||||
|
inst = inst
|
||||||
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
bail!("the option --base64 or --fetch is required");
|
bail!("the option --base64 or --fetch is required");
|
||||||
};
|
};
|
||||||
Ok(format!("
|
Ok(format!(
|
||||||
|
"
|
||||||
{js_imports}
|
{js_imports}
|
||||||
let wasm;
|
let wasm;
|
||||||
{bytes}
|
{bytes}
|
||||||
{mem_export}
|
{mem_export}
|
||||||
export const booted = {booted};
|
export const booted = {booted};
|
||||||
{exports}
|
{exports}
|
||||||
",
|
",
|
||||||
bytes = bytes,
|
bytes = bytes,
|
||||||
booted = booted,
|
booted = booted,
|
||||||
js_imports = js_imports,
|
js_imports = js_imports,
|
||||||
@ -273,16 +309,20 @@ impl Output {
|
|||||||
|
|
||||||
let m = name_map.entry(entry.field()).or_insert(entry.module());
|
let m = name_map.entry(entry.field()).or_insert(entry.module());
|
||||||
if *m != entry.module() {
|
if *m != entry.module() {
|
||||||
bail!("the name `{}` is imported from two differnet \
|
bail!(
|
||||||
modules which currently isn't supported in `wasm2asm` \
|
"the name `{}` is imported from two differnet \
|
||||||
mode");
|
modules which currently isn't supported in `wasm2asm` \
|
||||||
|
mode"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = format!("import{}", i);
|
let name = format!("import{}", i);
|
||||||
js_imports.push_str(&format!("import {{ {} as {} }} from '{}';\n",
|
js_imports.push_str(&format!(
|
||||||
entry.field(),
|
"import {{ {} as {} }} from '{}';\n",
|
||||||
name,
|
entry.field(),
|
||||||
entry.module()));
|
name,
|
||||||
|
entry.module()
|
||||||
|
));
|
||||||
imported_items.push((entry.field().to_string(), name));
|
imported_items.push((entry.field().to_string(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,18 +338,17 @@ impl Output {
|
|||||||
Internal::Global(_) => continue,
|
Internal::Global(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
js_exports.push_str(&format!("export const {0} = ret.{0};\n",
|
js_exports.push_str(&format!("export const {0} = ret.{0};\n", entry.field()));
|
||||||
entry.field()));
|
|
||||||
}
|
}
|
||||||
if !export_mem {
|
if !export_mem {
|
||||||
bail!("the `wasm2asm` mode is currently only compatible with \
|
bail!(
|
||||||
modules that export memory")
|
"the `wasm2asm` mode is currently only compatible with \
|
||||||
|
modules that export memory"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let memory_size = self.module.memory_section()
|
let memory_size = self.module.memory_section().unwrap().entries()[0]
|
||||||
.unwrap()
|
|
||||||
.entries()[0]
|
|
||||||
.limits()
|
.limits()
|
||||||
.initial();
|
.initial();
|
||||||
|
|
||||||
@ -329,9 +368,7 @@ impl Output {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let base64 = base64::encode(entry.value());
|
let base64 = base64::encode(entry.value());
|
||||||
js_init_mem.push_str(&format!("_assign({}, \"{}\");\n",
|
js_init_mem.push_str(&format!("_assign({}, \"{}\");\n", offset, base64));
|
||||||
offset,
|
|
||||||
base64));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,9 +377,7 @@ impl Output {
|
|||||||
let wasm_file = td.as_ref().join("foo.wasm");
|
let wasm_file = td.as_ref().join("foo.wasm");
|
||||||
File::create(&wasm_file)
|
File::create(&wasm_file)
|
||||||
.and_then(|mut f| f.write_all(&wasm))
|
.and_then(|mut f| f.write_all(&wasm))
|
||||||
.with_context(|_| {
|
.with_context(|_| format!("failed to write wasm to `{}`", wasm_file.display()))?;
|
||||||
format!("failed to write wasm to `{}`", wasm_file.display())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let wast_file = td.as_ref().join("foo.wast");
|
let wast_file = td.as_ref().join("foo.wast");
|
||||||
run(
|
run(
|
||||||
@ -364,19 +399,19 @@ impl Output {
|
|||||||
let mut asm_func = String::new();
|
let mut asm_func = String::new();
|
||||||
File::open(&js_file)
|
File::open(&js_file)
|
||||||
.and_then(|mut f| f.read_to_string(&mut asm_func))
|
.and_then(|mut f| f.read_to_string(&mut asm_func))
|
||||||
.with_context(|_| {
|
.with_context(|_| format!("failed to read `{}`", js_file.display()))?;
|
||||||
format!("failed to read `{}`", js_file.display())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
|
let mut make_imports = String::from(
|
||||||
let mut make_imports = String::from("
|
"
|
||||||
var imports = {};
|
var imports = {};
|
||||||
");
|
",
|
||||||
|
);
|
||||||
for (name, import) in imported_items {
|
for (name, import) in imported_items {
|
||||||
make_imports.push_str(&format!("imports['{}'] = {};\n", name, import));
|
make_imports.push_str(&format!("imports['{}'] = {};\n", name, import));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(format!("\
|
Ok(format!(
|
||||||
|
"\
|
||||||
{js_imports}
|
{js_imports}
|
||||||
|
|
||||||
{asm_func}
|
{asm_func}
|
||||||
@ -410,7 +445,7 @@ impl Output {
|
|||||||
Infinity,
|
Infinity,
|
||||||
}}, imports, mem);
|
}}, imports, mem);
|
||||||
{js_exports}
|
{js_exports}
|
||||||
",
|
",
|
||||||
js_imports = js_imports,
|
js_imports = js_imports,
|
||||||
js_init_mem = js_init_mem,
|
js_init_mem = js_init_mem,
|
||||||
asm_func = asm_func,
|
asm_func = asm_func,
|
||||||
@ -424,28 +459,31 @@ impl Output {
|
|||||||
fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
|
fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
|
||||||
let output = cmd.output().with_context(|e| {
|
let output = cmd.output().with_context(|e| {
|
||||||
if e.kind() == io::ErrorKind::NotFound {
|
if e.kind() == io::ErrorKind::NotFound {
|
||||||
format!("failed to execute `{}`, is the tool installed \
|
format!(
|
||||||
from the binaryen project?\ncommand line: {:?}",
|
"failed to execute `{}`, is the tool installed \
|
||||||
program,
|
from the binaryen project?\ncommand line: {:?}",
|
||||||
cmd)
|
program, cmd
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
format!("failed to execute: {:?}", cmd)
|
format!("failed to execute: {:?}", cmd)
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
return Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = format!("failed to execute: {:?}\nstatus: {}\n",
|
let mut s = format!("failed to execute: {:?}\nstatus: {}\n", cmd, output.status);
|
||||||
cmd,
|
|
||||||
output.status);
|
|
||||||
if !output.stdout.is_empty() {
|
if !output.stdout.is_empty() {
|
||||||
s.push_str(&format!("----- stdout ------\n{}\n",
|
s.push_str(&format!(
|
||||||
String::from_utf8_lossy(&output.stdout)));
|
"----- stdout ------\n{}\n",
|
||||||
|
String::from_utf8_lossy(&output.stdout)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
if !output.stderr.is_empty() {
|
if !output.stderr.is_empty() {
|
||||||
s.push_str(&format!("----- stderr ------\n{}\n",
|
s.push_str(&format!(
|
||||||
String::from_utf8_lossy(&output.stderr)));
|
"----- stderr ------\n{}\n",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
bail!("{}", s)
|
bail!("{}", s)
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ use std::path::PathBuf;
|
|||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use wasm_bindgen_cli_support::Bindgen;
|
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
|
use wasm_bindgen_cli_support::Bindgen;
|
||||||
|
|
||||||
const USAGE: &'static str = "
|
const USAGE: &'static str = "
|
||||||
Generating JS bindings for a wasm file
|
Generating JS bindings for a wasm file
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
|
extern crate failure;
|
||||||
extern crate parity_wasm;
|
extern crate parity_wasm;
|
||||||
extern crate wasm_bindgen_cli_support;
|
extern crate wasm_bindgen_cli_support;
|
||||||
extern crate failure;
|
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Write, Read};
|
use std::io::{Read, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
@ -76,9 +76,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
|
|||||||
let ts = object.typescript();
|
let ts = object.typescript();
|
||||||
File::create(&dst)
|
File::create(&dst)
|
||||||
.and_then(|mut f| f.write_all(ts.as_bytes()))
|
.and_then(|mut f| f.write_all(ts.as_bytes()))
|
||||||
.with_context(|_| {
|
.with_context(|_| format!("failed to write `{}`", dst.display()))?;
|
||||||
format!("failed to write `{}`", dst.display())
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#![feature(proc_macro)]
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
extern crate syn;
|
|
||||||
extern crate quote;
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
|
extern crate quote;
|
||||||
|
extern crate syn;
|
||||||
extern crate wasm_bindgen_backend as backend;
|
extern crate wasm_bindgen_backend as backend;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
@ -26,7 +26,6 @@ pub(crate) enum TsExport {
|
|||||||
#[serde(rename = "returnValue")]
|
#[serde(rename = "returnValue")]
|
||||||
return_value: TsReturnValue,
|
return_value: TsReturnValue,
|
||||||
},
|
},
|
||||||
|
|
||||||
//TODO: implement ...
|
//TODO: implement ...
|
||||||
//{ "$ref": "#/definitions/interfaceApiItem" },
|
//{ "$ref": "#/definitions/interfaceApiItem" },
|
||||||
//{ "$ref": "#/definitions/namespaceApiItem" },
|
//{ "$ref": "#/definitions/namespaceApiItem" },
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
extern crate wasm_bindgen_backend as backend;
|
extern crate wasm_bindgen_backend as backend;
|
||||||
|
@ -2,11 +2,11 @@ use std::collections::HashMap;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use backend::{self};
|
use backend;
|
||||||
use backend::ast::{BindgenAttrs, Export, Function};
|
use backend::ast::{BindgenAttrs, Export, Function};
|
||||||
use proc_macro2::{self};
|
use proc_macro2;
|
||||||
use serde_json::{self};
|
use serde_json;
|
||||||
use syn::{self};
|
use syn;
|
||||||
|
|
||||||
use api_extractor;
|
use api_extractor;
|
||||||
use definitions::*;
|
use definitions::*;
|
||||||
@ -25,7 +25,11 @@ pub fn ts_to_program(file_name: &str) -> backend::ast::Program {
|
|||||||
match member {
|
match member {
|
||||||
TsClassMembers::TsProperty { .. } => {}
|
TsClassMembers::TsProperty { .. } => {}
|
||||||
TsClassMembers::TsConstructor { .. } => {}
|
TsClassMembers::TsConstructor { .. } => {}
|
||||||
TsClassMembers::TsMethod { parameters, return_value, .. } => {
|
TsClassMembers::TsMethod {
|
||||||
|
parameters,
|
||||||
|
return_value,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
let function = build_function(member_name, parameters, return_value);
|
let function = build_function(member_name, parameters, return_value);
|
||||||
|
|
||||||
program.exports.push(Export {
|
program.exports.push(Export {
|
||||||
@ -33,14 +37,17 @@ pub fn ts_to_program(file_name: &str) -> backend::ast::Program {
|
|||||||
method: true,
|
method: true,
|
||||||
mutable: false,
|
mutable: false,
|
||||||
constructor: None,
|
constructor: None,
|
||||||
function,
|
function,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TsExport::TsFunction { parameters, return_value } => {
|
TsExport::TsFunction {
|
||||||
|
parameters,
|
||||||
|
return_value,
|
||||||
|
} => {
|
||||||
let function = build_function(name, parameters, return_value);
|
let function = build_function(name, parameters, return_value);
|
||||||
|
|
||||||
program.exports.push(Export {
|
program.exports.push(Export {
|
||||||
@ -65,22 +72,29 @@ fn parse_json(file_name: &str) -> TsPackage {
|
|||||||
serde_json::from_str(&data).unwrap()
|
serde_json::from_str(&data).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_function(name: String, parameters: HashMap<String, TsMethodProperty>, return_value: TsReturnValue) -> Function {
|
fn build_function(
|
||||||
let arguments = parameters.iter().map( |(_name, property)| {
|
name: String,
|
||||||
let mut segments = syn::punctuated::Punctuated::new();
|
parameters: HashMap<String, TsMethodProperty>,
|
||||||
segments.push(syn::PathSegment {
|
return_value: TsReturnValue,
|
||||||
ident: syn::Ident::new(&property.property_type, proc_macro2::Span::call_site()),
|
) -> Function {
|
||||||
arguments: syn::PathArguments::None,
|
let arguments = parameters
|
||||||
});
|
.iter()
|
||||||
|
.map(|(_name, property)| {
|
||||||
|
let mut segments = syn::punctuated::Punctuated::new();
|
||||||
|
segments.push(syn::PathSegment {
|
||||||
|
ident: syn::Ident::new(&property.property_type, proc_macro2::Span::call_site()),
|
||||||
|
arguments: syn::PathArguments::None,
|
||||||
|
});
|
||||||
|
|
||||||
syn::Type::Path(syn::TypePath {
|
syn::Type::Path(syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: syn::Path {
|
path: syn::Path {
|
||||||
leading_colon: None,
|
leading_colon: None,
|
||||||
segments,
|
segments,
|
||||||
}
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}).collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut ret_segments = syn::punctuated::Punctuated::new();
|
let mut ret_segments = syn::punctuated::Punctuated::new();
|
||||||
ret_segments.push(syn::PathSegment {
|
ret_segments.push(syn::PathSegment {
|
||||||
@ -93,7 +107,7 @@ fn build_function(name: String, parameters: HashMap<String, TsMethodProperty>, r
|
|||||||
path: syn::Path {
|
path: syn::Path {
|
||||||
leading_colon: None,
|
leading_colon: None,
|
||||||
segments: ret_segments,
|
segments: ret_segments,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let rust_decl = Box::new(syn::FnDecl {
|
let rust_decl = Box::new(syn::FnDecl {
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
fn log(s: &str);
|
fn log(s: &str);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
fn log(s: &str);
|
fn log(s: &str);
|
||||||
}
|
}
|
||||||
@ -14,7 +14,7 @@ extern {
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct Counter {
|
pub struct Counter {
|
||||||
key: char,
|
key: char,
|
||||||
count: i32
|
count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -25,7 +25,10 @@ impl Counter {
|
|||||||
}
|
}
|
||||||
pub fn new(key: char, count: i32) -> Counter {
|
pub fn new(key: char, count: i32) -> Counter {
|
||||||
log(&format!("Counter::new({}, {})", key, count));
|
log(&format!("Counter::new({}, {})", key, count));
|
||||||
Counter { key: key, count: count }
|
Counter {
|
||||||
|
key: key,
|
||||||
|
count: count,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn key(&self) -> char {
|
pub fn key(&self) -> char {
|
||||||
@ -46,4 +49,4 @@ impl Counter {
|
|||||||
pub fn update_key(&mut self, key: char) {
|
pub fn update_key(&mut self, key: char) {
|
||||||
self.key = key;
|
self.key = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use wasm_bindgen::js::Date;
|
use wasm_bindgen::js::Date;
|
||||||
use wasm_bindgen::js::JsString;
|
use wasm_bindgen::js::JsString;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
// Binding for the `setInverval` method in JS. This function takes a "long
|
// Binding for the `setInverval` method in JS. This function takes a "long
|
||||||
// lived" closure as the first argument so we use `Closure` instead of
|
// lived" closure as the first argument so we use `Closure` instead of
|
||||||
// a bare `&Fn()` which only surives for that one stack frame.
|
// a bare `&Fn()` which only surives for that one stack frame.
|
||||||
@ -51,12 +51,11 @@ pub fn run() {
|
|||||||
set_interval(&a, 1000);
|
set_interval(&a, 1000);
|
||||||
update_time();
|
update_time();
|
||||||
fn update_time() {
|
fn update_time() {
|
||||||
document.get_element_by_id("current-time")
|
document
|
||||||
.set_inner_html(
|
.get_element_by_id("current-time")
|
||||||
&String::from(
|
.set_inner_html(&String::from(
|
||||||
Date::new()
|
Date::new().to_locale_string(JsString::from("en-GB"), JsValue::undefined()),
|
||||||
.to_locale_string(
|
));
|
||||||
JsString::from("en-GB"), JsValue::undefined())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We also want to count the number of times that our green square has been
|
// We also want to count the number of times that our green square has been
|
||||||
@ -65,7 +64,8 @@ pub fn run() {
|
|||||||
let mut clicks = 0;
|
let mut clicks = 0;
|
||||||
let b = Closure::new(move || {
|
let b = Closure::new(move || {
|
||||||
clicks += 1;
|
clicks += 1;
|
||||||
document.get_element_by_id("num-clicks")
|
document
|
||||||
|
.get_element_by_id("num-clicks")
|
||||||
.set_inner_html(&clicks.to_string());
|
.set_inner_html(&clicks.to_string());
|
||||||
});
|
});
|
||||||
square.set_onclick(&b);
|
square.set_onclick(&b);
|
||||||
@ -84,10 +84,12 @@ pub fn run() {
|
|||||||
|
|
||||||
// And finally now that our demo is ready to go let's switch things up so
|
// And finally now that our demo is ready to go let's switch things up so
|
||||||
// everything is displayed and our loading prompt is hidden.
|
// everything is displayed and our loading prompt is hidden.
|
||||||
document.get_html_element_by_id("loading")
|
document
|
||||||
|
.get_html_element_by_id("loading")
|
||||||
.style()
|
.style()
|
||||||
.set_display("none");
|
.set_display("none");
|
||||||
document.get_html_element_by_id("script")
|
document
|
||||||
|
.get_html_element_by_id("script")
|
||||||
.style()
|
.style()
|
||||||
.set_display("block");
|
.set_display("block");
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ pub struct Comment {
|
|||||||
color: Color,
|
color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl Comment {
|
impl Comment {
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
@ -57,4 +56,4 @@ impl Comment {
|
|||||||
pub enum Color {
|
pub enum Color {
|
||||||
Blue,
|
Blue,
|
||||||
Pink,
|
Pink,
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
fn log(s: &str);
|
fn log(s: &str);
|
||||||
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
||||||
|
@ -15,7 +15,7 @@ use wasm_bindgen::prelude::*;
|
|||||||
// In the meantime these are written out by hand and correspond to the names and
|
// In the meantime these are written out by hand and correspond to the names and
|
||||||
// signatures documented on MDN, for example
|
// signatures documented on MDN, for example
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
type HTMLDocument;
|
type HTMLDocument;
|
||||||
static document: HTMLDocument;
|
static document: HTMLDocument;
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
fn alert(s: &str);
|
fn alert(s: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen(module = "./defined-in-js")]
|
#[wasm_bindgen(module = "./defined-in-js")]
|
||||||
extern {
|
extern "C" {
|
||||||
fn name() -> String;
|
fn name() -> String;
|
||||||
|
|
||||||
type MyClass;
|
type MyClass;
|
||||||
@ -23,7 +23,7 @@ extern {
|
|||||||
|
|
||||||
// Import `console.log` so we can log something to the console
|
// Import `console.log` so we can log something to the console
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
#[wasm_bindgen(js_namespace = console)]
|
||||||
fn log(s: &str);
|
fn log(s: &str);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_namespace = Math)]
|
#[wasm_bindgen(js_namespace = Math)]
|
||||||
fn log2(a: f64) -> f64;
|
fn log2(a: f64) -> f64;
|
||||||
#[wasm_bindgen(js_namespace = Math)]
|
#[wasm_bindgen(js_namespace = Math)]
|
||||||
|
@ -5,7 +5,7 @@ extern crate wasm_bindgen;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
fn alert(s: &str);
|
fn alert(s: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
|
||||||
extern crate humantime;
|
extern crate humantime;
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ use wasm_bindgen::prelude::*;
|
|||||||
// Like with the `dom` example this block will eventually be auto-generated, but
|
// Like with the `dom` example this block will eventually be auto-generated, but
|
||||||
// for now we can write it by hand to get by!
|
// for now we can write it by hand to get by!
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
type Performance;
|
type Performance;
|
||||||
static performance: Performance;
|
static performance: Performance;
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
|
@ -7,10 +7,10 @@ use wasm_bindgen::prelude::*;
|
|||||||
// Strings can both be passed in and received
|
// Strings can both be passed in and received
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn concat(a: &str, b: &str) -> String {
|
pub extern "C" fn concat(a: &str, b: &str) -> String {
|
||||||
let mut a = a.to_string();
|
let mut a = a.to_string();
|
||||||
a.push_str(b);
|
a.push_str(b);
|
||||||
return a
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A struct will show up as a class on the JS side of things
|
// A struct will show up as a class on the JS side of things
|
||||||
@ -29,7 +29,7 @@ impl Foo {
|
|||||||
// can pass to a normal free function also all work in methods.
|
// can pass to a normal free function also all work in methods.
|
||||||
pub fn add(&mut self, amt: u32) -> u32 {
|
pub fn add(&mut self, amt: u32) -> u32 {
|
||||||
self.contents += amt;
|
self.contents += amt;
|
||||||
return self.contents
|
return self.contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can also take a limited set of references to other types as well.
|
// You can also take a limited set of references to other types as well.
|
||||||
@ -50,7 +50,7 @@ pub struct Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(module = "./awesome")] // what ES6 module to import from
|
#[wasm_bindgen(module = "./awesome")] // what ES6 module to import from
|
||||||
extern {
|
extern "C" {
|
||||||
fn bar_on_reset(to: &str, opaque: &JsValue);
|
fn bar_on_reset(to: &str, opaque: &JsValue);
|
||||||
|
|
||||||
// We can import classes and annotate functionality on those classes as well
|
// We can import classes and annotate functionality on those classes as well
|
||||||
@ -64,9 +64,7 @@ extern {
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl Bar {
|
impl Bar {
|
||||||
pub fn from_str(s: &str, opaque: JsValue) -> Bar {
|
pub fn from_str(s: &str, opaque: JsValue) -> Bar {
|
||||||
let contents = s.parse().unwrap_or_else(|_| {
|
let contents = s.parse().unwrap_or_else(|_| Awesome::new().get_internal());
|
||||||
Awesome::new().get_internal()
|
|
||||||
});
|
|
||||||
Bar { contents, opaque }
|
Bar { contents, opaque }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use wasm_bindgen::prelude::*;
|
|||||||
// Like with the `dom` example this block will eventually be auto-generated, but
|
// Like with the `dom` example this block will eventually be auto-generated, but
|
||||||
// for now we can write it by hand to get by!
|
// for now we can write it by hand to get by!
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
type Module;
|
type Module;
|
||||||
#[wasm_bindgen(constructor, js_namespace = WebAssembly)]
|
#[wasm_bindgen(constructor, js_namespace = WebAssembly)]
|
||||||
fn new(data: &[u8]) -> Module;
|
fn new(data: &[u8]) -> Module;
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
//! This is mostly an internal module, no stability guarantees are provided. Use
|
//! This is mostly an internal module, no stability guarantees are provided. Use
|
||||||
//! at your own risk.
|
//! at your own risk.
|
||||||
|
|
||||||
|
use core::char;
|
||||||
use core::mem::{self, ManuallyDrop};
|
use core::mem::{self, ManuallyDrop};
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::slice;
|
use core::slice;
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::char;
|
|
||||||
|
|
||||||
use {JsValue, throw};
|
|
||||||
use describe::*;
|
use describe::*;
|
||||||
|
use {throw, JsValue};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -59,7 +59,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
|
|||||||
/// invocation of the function that has an `&Self` parameter. This is
|
/// invocation of the function that has an `&Self` parameter. This is
|
||||||
/// required to ensure that the lifetimes don't persist beyond one function
|
/// required to ensure that the lifetimes don't persist beyond one function
|
||||||
/// call, and so that they remain anonymous.
|
/// call, and so that they remain anonymous.
|
||||||
type Anchor: Deref<Target=Self>;
|
type Anchor: Deref<Target = Self>;
|
||||||
|
|
||||||
/// Recover a `Self::Anchor` from `Self::Abi`.
|
/// Recover a `Self::Anchor` from `Self::Abi`.
|
||||||
///
|
///
|
||||||
@ -71,7 +71,7 @@ pub trait RefFromWasmAbi: WasmDescribe {
|
|||||||
|
|
||||||
pub trait RefMutFromWasmAbi: WasmDescribe {
|
pub trait RefMutFromWasmAbi: WasmDescribe {
|
||||||
type Abi: WasmAbi;
|
type Abi: WasmAbi;
|
||||||
type Anchor: DerefMut<Target=Self>;
|
type Anchor: DerefMut<Target = Self>;
|
||||||
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
|
unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,18 +159,24 @@ as_u32!(i8 u8 i16 u16 isize usize);
|
|||||||
impl IntoWasmAbi for bool {
|
impl IntoWasmAbi for bool {
|
||||||
type Abi = u32;
|
type Abi = u32;
|
||||||
|
|
||||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||||
|
self as u32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWasmAbi for bool {
|
impl FromWasmAbi for bool {
|
||||||
type Abi = u32;
|
type Abi = u32;
|
||||||
|
|
||||||
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool { js != 0 }
|
unsafe fn from_abi(js: u32, _extra: &mut Stack) -> bool {
|
||||||
|
js != 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoWasmAbi for char {
|
impl IntoWasmAbi for char {
|
||||||
type Abi = u32;
|
type Abi = u32;
|
||||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||||
|
self as u32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWasmAbi for char {
|
impl FromWasmAbi for char {
|
||||||
@ -183,7 +189,9 @@ impl FromWasmAbi for char {
|
|||||||
impl<T> IntoWasmAbi for *const T {
|
impl<T> IntoWasmAbi for *const T {
|
||||||
type Abi = u32;
|
type Abi = u32;
|
||||||
|
|
||||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||||
|
self as u32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> FromWasmAbi for *const T {
|
impl<T> FromWasmAbi for *const T {
|
||||||
@ -197,7 +205,9 @@ impl<T> FromWasmAbi for *const T {
|
|||||||
impl<T> IntoWasmAbi for *mut T {
|
impl<T> IntoWasmAbi for *mut T {
|
||||||
type Abi = u32;
|
type Abi = u32;
|
||||||
|
|
||||||
fn into_abi(self, _extra: &mut Stack) -> u32 { self as u32 }
|
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||||
|
self as u32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> FromWasmAbi for *mut T {
|
impl<T> FromWasmAbi for *mut T {
|
||||||
@ -343,7 +353,7 @@ impl IntoWasmAbi for JsValue {
|
|||||||
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
fn into_abi(self, _extra: &mut Stack) -> u32 {
|
||||||
let ret = self.idx;
|
let ret = self.idx;
|
||||||
mem::forget(self);
|
mem::forget(self);
|
||||||
return ret
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +407,9 @@ if_std! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GlobalStack { next: usize }
|
pub struct GlobalStack {
|
||||||
|
next: usize,
|
||||||
|
}
|
||||||
|
|
||||||
const GLOBAL_STACK_CAP: usize = 16;
|
const GLOBAL_STACK_CAP: usize = 16;
|
||||||
static mut GLOBAL_STACK: [u32; GLOBAL_STACK_CAP] = [0; GLOBAL_STACK_CAP];
|
static mut GLOBAL_STACK: [u32; GLOBAL_STACK_CAP] = [0; GLOBAL_STACK_CAP];
|
||||||
@ -429,7 +441,7 @@ impl Stack for GlobalStack {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn __wbindgen_global_argument_ptr() -> *mut u32 {
|
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
|
||||||
GLOBAL_STACK.as_mut_ptr()
|
GLOBAL_STACK.as_mut_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +41,7 @@ tys! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn inform(a: u32) {
|
pub fn inform(a: u32) {
|
||||||
unsafe {
|
unsafe { super::__wbindgen_describe(a) }
|
||||||
super::__wbindgen_describe(a)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WasmDescribe {
|
pub trait WasmDescribe {
|
||||||
@ -78,11 +76,15 @@ simple! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> WasmDescribe for *const T {
|
impl<T> WasmDescribe for *const T {
|
||||||
fn describe() { inform(I32) }
|
fn describe() {
|
||||||
|
inform(I32)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> WasmDescribe for *mut T {
|
impl<T> WasmDescribe for *mut T {
|
||||||
fn describe() { inform(I32) }
|
fn describe() {
|
||||||
|
inform(I32)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: WasmDescribe> WasmDescribe for [T] {
|
impl<T: WasmDescribe> WasmDescribe for [T] {
|
||||||
@ -127,7 +129,9 @@ if_std! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _cnt<T: WasmDescribe>() -> u32 { 1 }
|
fn _cnt<T: WasmDescribe>() -> u32 {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! doit {
|
macro_rules! doit {
|
||||||
($( ($($var:ident)*))*) => ($(
|
($( ($($var:ident)*))*) => ($(
|
||||||
|
81
src/js.rs
81
src/js.rs
@ -41,7 +41,7 @@ if_std! {
|
|||||||
// for that case.
|
// for that case.
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
/// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
|
/// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
|
||||||
/// previously created by `encodeURI` or by a similar routine.
|
/// previously created by `encodeURI` or by a similar routine.
|
||||||
///
|
///
|
||||||
@ -68,7 +68,7 @@ extern {
|
|||||||
|
|
||||||
// UInt8Array
|
// UInt8Array
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Uint8Array;
|
pub type Uint8Array;
|
||||||
|
|
||||||
/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
|
/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
|
||||||
@ -87,7 +87,7 @@ extern {
|
|||||||
|
|
||||||
// Array
|
// Array
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Array;
|
pub type Array;
|
||||||
|
|
||||||
/// The copyWithin() method shallow copies part of an array to another
|
/// The copyWithin() method shallow copies part of an array to another
|
||||||
@ -106,7 +106,7 @@ extern {
|
|||||||
|
|
||||||
/// The every() method tests whether all elements in the array pass the test
|
/// The every() method tests whether all elements in the array pass the test
|
||||||
/// implemented by the provided function.
|
/// implemented by the provided function.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn every(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> bool;
|
pub fn every(this: &Array, predicate: &mut FnMut(JsValue, u32, Array) -> bool) -> bool;
|
||||||
@ -240,7 +240,7 @@ extern {
|
|||||||
|
|
||||||
// Array Iterator
|
// Array Iterator
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type ArrayIterator;
|
pub type ArrayIterator;
|
||||||
|
|
||||||
/// The keys() method returns a new Array Iterator object that contains the
|
/// The keys() method returns a new Array Iterator object that contains the
|
||||||
@ -260,7 +260,7 @@ extern {
|
|||||||
|
|
||||||
// Boolean
|
// Boolean
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Boolean;
|
pub type Boolean;
|
||||||
|
|
||||||
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
|
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
|
||||||
@ -278,12 +278,12 @@ extern {
|
|||||||
|
|
||||||
// Function
|
// Function
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Function;
|
pub type Function;
|
||||||
|
|
||||||
/// The apply() method calls a function with a given this value, and arguments provided as an array
|
/// The apply() method calls a function with a given this value, and arguments provided as an array
|
||||||
/// (or an array-like object).
|
/// (or an array-like object).
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Function;
|
pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Function;
|
||||||
@ -303,7 +303,7 @@ extern {
|
|||||||
pub fn name(this: &Function) -> JsString;
|
pub fn name(this: &Function) -> JsString;
|
||||||
|
|
||||||
/// The toString() method returns a string representing the source code of the function.
|
/// The toString() method returns a string representing the source code of the function.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
|
||||||
#[wasm_bindgen(method, js_name = toString)]
|
#[wasm_bindgen(method, js_name = toString)]
|
||||||
pub fn to_string(this: &Function) -> JsString;
|
pub fn to_string(this: &Function) -> JsString;
|
||||||
@ -311,7 +311,7 @@ extern {
|
|||||||
|
|
||||||
// Math
|
// Math
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Math;
|
pub type Math;
|
||||||
/// The Math.abs() function returns the absolute value of a number, that is
|
/// The Math.abs() function returns the absolute value of a number, that is
|
||||||
/// Math.abs(x) = |x|
|
/// Math.abs(x) = |x|
|
||||||
@ -372,7 +372,6 @@ extern {
|
|||||||
#[wasm_bindgen(static_method_of = Math)]
|
#[wasm_bindgen(static_method_of = Math)]
|
||||||
pub fn atanh(x: i32) -> Number;
|
pub fn atanh(x: i32) -> Number;
|
||||||
|
|
||||||
|
|
||||||
/// The Math.cbrt() function returns the cube root of a number, that is
|
/// The Math.cbrt() function returns the cube root of a number, that is
|
||||||
/// Math.cbrt(x) = x^3 = the unique y such that y^3 = x
|
/// Math.cbrt(x) = x^3 = the unique y such that y^3 = x
|
||||||
///
|
///
|
||||||
@ -404,7 +403,7 @@ extern {
|
|||||||
|
|
||||||
// Number.
|
// Number.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Number;
|
pub type Number;
|
||||||
|
|
||||||
/// The toLocaleString() method returns a string with a language sensitive
|
/// The toLocaleString() method returns a string with a language sensitive
|
||||||
@ -452,35 +451,35 @@ extern {
|
|||||||
|
|
||||||
// Date.
|
// Date.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Date;
|
pub type Date;
|
||||||
|
|
||||||
/// Creates a JavaScript Date instance that represents
|
/// Creates a JavaScript Date instance that represents
|
||||||
/// a single moment in time. Date objects are based on a time value that is
|
/// a single moment in time. Date objects are based on a time value that is
|
||||||
/// the number of milliseconds since 1 January 1970 UTC.
|
/// the number of milliseconds since 1 January 1970 UTC.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new() -> Date;
|
pub fn new() -> Date;
|
||||||
|
|
||||||
/// The toDateString() method returns the date portion of a Date object
|
/// The toDateString() method returns the date portion of a Date object
|
||||||
/// in human readable form in American English.
|
/// in human readable form in American English.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString
|
||||||
#[wasm_bindgen(method, js_name = toDateString)]
|
#[wasm_bindgen(method, js_name = toDateString)]
|
||||||
pub fn to_date_string(this: &Date) -> JsString;
|
pub fn to_date_string(this: &Date) -> JsString;
|
||||||
|
|
||||||
/// The toISOString() method returns a string in simplified extended ISO format (ISO
|
/// The toISOString() method returns a string in simplified extended ISO format (ISO
|
||||||
/// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
|
/// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
|
||||||
/// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
|
/// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
|
||||||
/// as denoted by the suffix "Z"
|
/// as denoted by the suffix "Z"
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||||
#[wasm_bindgen(method, js_name = toISOString)]
|
#[wasm_bindgen(method, js_name = toISOString)]
|
||||||
pub fn to_iso_string(this: &Date) -> JsString;
|
pub fn to_iso_string(this: &Date) -> JsString;
|
||||||
|
|
||||||
/// The toJSON() method returns a string representation of the Date object.
|
/// The toJSON() method returns a string representation of the Date object.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON
|
||||||
#[wasm_bindgen(method, js_name = toJSON)]
|
#[wasm_bindgen(method, js_name = toJSON)]
|
||||||
pub fn to_json(this: &Date) -> JsString;
|
pub fn to_json(this: &Date) -> JsString;
|
||||||
@ -492,17 +491,17 @@ extern {
|
|||||||
/// In older implementations, which ignore the locales and options arguments,
|
/// In older implementations, which ignore the locales and options arguments,
|
||||||
/// the locale used and the form of the string
|
/// the locale used and the form of the string
|
||||||
/// returned are entirely implementation dependent.
|
/// returned are entirely implementation dependent.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
|
||||||
#[wasm_bindgen(method, js_name = toLocaleDateString)]
|
#[wasm_bindgen(method, js_name = toLocaleDateString)]
|
||||||
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
|
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
|
||||||
|
|
||||||
/// The toLocaleString() method returns a string with a language sensitive
|
/// The toLocaleString() method returns a string with a language sensitive
|
||||||
/// representation of this date. The new locales and options arguments
|
/// representation of this date. The new locales and options arguments
|
||||||
/// let applications specify the language whose formatting conventions
|
/// let applications specify the language whose formatting conventions
|
||||||
/// should be used and customize the behavior of the function.
|
/// should be used and customize the behavior of the function.
|
||||||
/// In older implementations, which ignore the locales
|
/// In older implementations, which ignore the locales
|
||||||
/// and options arguments, the locale used and the form of the string
|
/// and options arguments, the locale used and the form of the string
|
||||||
/// returned are entirely implementation dependent.
|
/// returned are entirely implementation dependent.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
||||||
@ -551,7 +550,7 @@ extern {
|
|||||||
|
|
||||||
// Object.
|
// Object.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type Object;
|
pub type Object;
|
||||||
|
|
||||||
/// The `hasOwnProperty()` method returns a boolean indicating whether the
|
/// The `hasOwnProperty()` method returns a boolean indicating whether the
|
||||||
@ -592,7 +591,7 @@ extern {
|
|||||||
/// The Object.seal() method seals an object, preventing new properties
|
/// The Object.seal() method seals an object, preventing new properties
|
||||||
/// from being added to it and marking all existing properties as non-configurable.
|
/// from being added to it and marking all existing properties as non-configurable.
|
||||||
/// Values of present properties can still be changed as long as they are writable.
|
/// Values of present properties can still be changed as long as they are writable.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal
|
||||||
#[wasm_bindgen(static_method_of = Object)]
|
#[wasm_bindgen(static_method_of = Object)]
|
||||||
pub fn seal(value: &JsValue) -> JsValue;
|
pub fn seal(value: &JsValue) -> JsValue;
|
||||||
@ -698,7 +697,7 @@ extern {
|
|||||||
|
|
||||||
// WeakMap
|
// WeakMap
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type WeakMap;
|
pub type WeakMap;
|
||||||
|
|
||||||
/// The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced.
|
/// The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced.
|
||||||
@ -708,21 +707,21 @@ extern {
|
|||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new() -> WeakMap;
|
pub fn new() -> WeakMap;
|
||||||
|
|
||||||
/// The set() method sets the value for the key in the WeakMap object. Returns
|
/// The set() method sets the value for the key in the WeakMap object. Returns
|
||||||
/// the WeakMap object.
|
/// the WeakMap object.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set
|
||||||
#[wasm_bindgen(method, js_class="WeakMap")]
|
#[wasm_bindgen(method, js_class = "WeakMap")]
|
||||||
pub fn set(this: &WeakMap, key: Object, value: JsValue) -> WeakMap;
|
pub fn set(this: &WeakMap, key: Object, value: JsValue) -> WeakMap;
|
||||||
|
|
||||||
/// The get() method returns a specified by key element
|
/// The get() method returns a specified by key element
|
||||||
/// from a WeakMap object.
|
/// from a WeakMap object.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn get(this: &WeakMap, key: Object) -> JsValue;
|
pub fn get(this: &WeakMap, key: Object) -> JsValue;
|
||||||
|
|
||||||
/// The has() method returns a boolean indicating whether an element with
|
/// The has() method returns a boolean indicating whether an element with
|
||||||
/// the specified key exists in the WeakMap object or not.
|
/// the specified key exists in the WeakMap object or not.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has
|
||||||
@ -738,29 +737,29 @@ extern {
|
|||||||
|
|
||||||
// WeakSet
|
// WeakSet
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
pub type WeakSet;
|
pub type WeakSet;
|
||||||
|
|
||||||
/// The WeakSet object lets you store weakly held objects in a collection.
|
/// The WeakSet object lets you store weakly held objects in a collection.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new() -> WeakSet;
|
pub fn new() -> WeakSet;
|
||||||
|
|
||||||
/// The has() method returns a boolean indicating whether an object exists in a WeakSet or not.
|
/// The has() method returns a boolean indicating whether an object exists in a WeakSet or not.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn has(this: &WeakSet, value: Object) -> bool;
|
pub fn has(this: &WeakSet, value: Object) -> bool;
|
||||||
|
|
||||||
/// The add() method appends a new object to the end of a WeakSet object.
|
/// The add() method appends a new object to the end of a WeakSet object.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn add(this: &WeakSet, value: Object) -> WeakSet;
|
pub fn add(this: &WeakSet, value: Object) -> WeakSet;
|
||||||
|
|
||||||
/// The delete() method removes the specified element from a WeakSet object.
|
/// The delete() method removes the specified element from a WeakSet object.
|
||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn delete(this: &WeakSet, value: Object) -> bool;
|
pub fn delete(this: &WeakSet, value: Object) -> bool;
|
||||||
@ -768,7 +767,7 @@ extern {
|
|||||||
|
|
||||||
// JsString
|
// JsString
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern "C" {
|
||||||
#[wasm_bindgen(js_name = JsString)]
|
#[wasm_bindgen(js_name = JsString)]
|
||||||
pub type JsString;
|
pub type JsString;
|
||||||
|
|
||||||
@ -821,7 +820,7 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
|
||||||
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
|
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
|
||||||
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32;
|
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32;
|
||||||
|
|
||||||
/// The slice() method extracts a section of a string and returns it as a
|
/// The slice() method extracts a section of a string and returns it as a
|
||||||
/// new string, without modifying the original string.
|
/// new string, without modifying the original string.
|
||||||
///
|
///
|
||||||
|
76
src/lib.rs
76
src/lib.rs
@ -76,16 +76,18 @@ const JSIDX_RESERVED: u32 = 8;
|
|||||||
|
|
||||||
impl JsValue {
|
impl JsValue {
|
||||||
/// The `null` JS value constant.
|
/// The `null` JS value constant.
|
||||||
pub const NULL: JsValue = JsValue { idx: JSIDX_NULL };
|
pub const NULL: JsValue = JsValue { idx: JSIDX_NULL };
|
||||||
|
|
||||||
/// The `undefined` JS value constant.
|
/// The `undefined` JS value constant.
|
||||||
pub const UNDEFINED: JsValue = JsValue { idx: JSIDX_UNDEFINED };
|
pub const UNDEFINED: JsValue = JsValue {
|
||||||
|
idx: JSIDX_UNDEFINED,
|
||||||
|
};
|
||||||
|
|
||||||
/// The `true` JS value constant.
|
/// The `true` JS value constant.
|
||||||
pub const TRUE: JsValue = JsValue { idx: JSIDX_TRUE };
|
pub const TRUE: JsValue = JsValue { idx: JSIDX_TRUE };
|
||||||
|
|
||||||
/// The `false` JS value constant.
|
/// The `false` JS value constant.
|
||||||
pub const FALSE: JsValue = JsValue { idx: JSIDX_FALSE };
|
pub const FALSE: JsValue = JsValue { idx: JSIDX_FALSE };
|
||||||
|
|
||||||
/// Creates a new JS value which is a string.
|
/// Creates a new JS value which is a string.
|
||||||
///
|
///
|
||||||
@ -93,7 +95,9 @@ impl JsValue {
|
|||||||
/// be owned by the JS garbage collector.
|
/// be owned by the JS garbage collector.
|
||||||
pub fn from_str(s: &str) -> JsValue {
|
pub fn from_str(s: &str) -> JsValue {
|
||||||
unsafe {
|
unsafe {
|
||||||
JsValue { idx: __wbindgen_string_new(s.as_ptr(), s.len()) }
|
JsValue {
|
||||||
|
idx: __wbindgen_string_new(s.as_ptr(), s.len()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +107,9 @@ impl JsValue {
|
|||||||
/// allocated number) and returns a handle to the JS version of it.
|
/// allocated number) and returns a handle to the JS version of it.
|
||||||
pub fn from_f64(n: f64) -> JsValue {
|
pub fn from_f64(n: f64) -> JsValue {
|
||||||
unsafe {
|
unsafe {
|
||||||
JsValue { idx: __wbindgen_number_new(n) }
|
JsValue {
|
||||||
|
idx: __wbindgen_number_new(n),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,12 +118,16 @@ impl JsValue {
|
|||||||
/// This function creates a JS object representing a boolean (a heap
|
/// This function creates a JS object representing a boolean (a heap
|
||||||
/// allocated boolean) and returns a handle to the JS version of it.
|
/// allocated boolean) and returns a handle to the JS version of it.
|
||||||
pub fn from_bool(b: bool) -> JsValue {
|
pub fn from_bool(b: bool) -> JsValue {
|
||||||
JsValue { idx: if b { JSIDX_TRUE } else { JSIDX_FALSE } }
|
JsValue {
|
||||||
|
idx: if b { JSIDX_TRUE } else { JSIDX_FALSE },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new JS value representing `undefined`.
|
/// Creates a new JS value representing `undefined`.
|
||||||
pub fn undefined() -> JsValue {
|
pub fn undefined() -> JsValue {
|
||||||
JsValue { idx: JSIDX_UNDEFINED }
|
JsValue {
|
||||||
|
idx: JSIDX_UNDEFINED,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new JS value representing `null`.
|
/// Creates a new JS value representing `null`.
|
||||||
@ -133,7 +143,9 @@ impl JsValue {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let ptr = description.map(|s| s.as_ptr()).unwrap_or(ptr::null());
|
let ptr = description.map(|s| s.as_ptr()).unwrap_or(ptr::null());
|
||||||
let len = description.map(|s| s.len()).unwrap_or(0);
|
let len = description.map(|s| s.len()).unwrap_or(0);
|
||||||
JsValue { idx: __wbindgen_symbol_new(ptr, len) }
|
JsValue {
|
||||||
|
idx: __wbindgen_symbol_new(ptr, len),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +166,8 @@ impl JsValue {
|
|||||||
/// Returns any error encountered when serializing `T` into JSON.
|
/// Returns any error encountered when serializing `T` into JSON.
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
pub fn from_serde<T>(t: &T) -> serde_json::Result<JsValue>
|
pub fn from_serde<T>(t: &T) -> serde_json::Result<JsValue>
|
||||||
where T: serde::ser::Serialize + ?Sized,
|
where
|
||||||
|
T: serde::ser::Serialize + ?Sized,
|
||||||
{
|
{
|
||||||
let s = serde_json::to_string(t)?;
|
let s = serde_json::to_string(t)?;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -179,7 +192,8 @@ impl JsValue {
|
|||||||
/// Returns any error encountered when parsing the JSON into a `T`.
|
/// Returns any error encountered when parsing the JSON into a `T`.
|
||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
pub fn into_serde<T>(&self) -> serde_json::Result<T>
|
pub fn into_serde<T>(&self) -> serde_json::Result<T>
|
||||||
where T: for<'a> serde::de::Deserialize<'a>,
|
where
|
||||||
|
T: for<'a> serde::de::Deserialize<'a>,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut ptr = ptr::null_mut();
|
let mut ptr = ptr::null_mut();
|
||||||
@ -243,31 +257,23 @@ impl JsValue {
|
|||||||
|
|
||||||
/// Tests whether this JS value is `null`
|
/// Tests whether this JS value is `null`
|
||||||
pub fn is_null(&self) -> bool {
|
pub fn is_null(&self) -> bool {
|
||||||
unsafe {
|
unsafe { __wbindgen_is_null(self.idx) == 1 }
|
||||||
__wbindgen_is_null(self.idx) == 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether this JS value is `undefined`
|
/// Tests whether this JS value is `undefined`
|
||||||
pub fn is_undefined(&self) -> bool {
|
pub fn is_undefined(&self) -> bool {
|
||||||
unsafe {
|
unsafe { __wbindgen_is_undefined(self.idx) == 1 }
|
||||||
__wbindgen_is_undefined(self.idx) == 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests whether the type of this JS value is `symbol`
|
/// Tests whether the type of this JS value is `symbol`
|
||||||
pub fn is_symbol(&self) -> bool {
|
pub fn is_symbol(&self) -> bool {
|
||||||
unsafe {
|
unsafe { __wbindgen_is_symbol(self.idx) == 1 }
|
||||||
__wbindgen_is_symbol(self.idx) == 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for JsValue {
|
impl PartialEq for JsValue {
|
||||||
fn eq(&self, other: &JsValue) -> bool {
|
fn eq(&self, other: &JsValue) -> bool {
|
||||||
unsafe {
|
unsafe { __wbindgen_jsval_eq(self.idx, other.idx) != 0 }
|
||||||
__wbindgen_jsval_eq(self.idx, other.idx) != 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +427,7 @@ impl<T: FromWasmAbi + 'static> Deref for JsStatic<T> {
|
|||||||
// `JsStatic` a bit as well.
|
// `JsStatic` a bit as well.
|
||||||
let ptr = self.__inner.get();
|
let ptr = self.__inner.get();
|
||||||
if let Some(ref t) = *ptr {
|
if let Some(ref t) = *ptr {
|
||||||
return t
|
return t;
|
||||||
}
|
}
|
||||||
let init = Some((self.__init)());
|
let init = Some((self.__init)());
|
||||||
debug_assert!((*ptr).is_none());
|
debug_assert!((*ptr).is_none());
|
||||||
@ -455,7 +461,7 @@ pub mod __rt {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
macro_rules! __wbindgen_if_not_std {
|
macro_rules! __wbindgen_if_not_std {
|
||||||
($($i:item)*) => ()
|
($($i:item)*) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@ -500,7 +506,10 @@ pub mod __rt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized> WasmRefCell<T> {
|
impl<T: ?Sized> WasmRefCell<T> {
|
||||||
pub fn new(value: T) -> WasmRefCell<T> where T: Sized {
|
pub fn new(value: T) -> WasmRefCell<T>
|
||||||
|
where
|
||||||
|
T: Sized,
|
||||||
|
{
|
||||||
WasmRefCell {
|
WasmRefCell {
|
||||||
value: UnsafeCell::new(value),
|
value: UnsafeCell::new(value),
|
||||||
borrow: Cell::new(0),
|
borrow: Cell::new(0),
|
||||||
@ -508,9 +517,7 @@ pub mod __rt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mut(&mut self) -> &mut T {
|
pub fn get_mut(&mut self) -> &mut T {
|
||||||
unsafe {
|
unsafe { &mut *self.value.get() }
|
||||||
&mut *self.value.get()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn borrow(&self) -> Ref<T> {
|
pub fn borrow(&self) -> Ref<T> {
|
||||||
@ -539,7 +546,10 @@ pub mod __rt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_inner(self) -> T where T: Sized {
|
pub fn into_inner(self) -> T
|
||||||
|
where
|
||||||
|
T: Sized,
|
||||||
|
{
|
||||||
self.value.into_inner()
|
self.value.into_inner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,8 +602,10 @@ pub mod __rt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn borrow_fail() -> ! {
|
fn borrow_fail() -> ! {
|
||||||
super::throw("recursive use of an object detected which would lead to \
|
super::throw(
|
||||||
unsafe aliasing in rust");
|
"recursive use of an object detected which would lead to \
|
||||||
|
unsafe aliasing in rust",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if_std! {
|
if_std! {
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -108,8 +110,11 @@ fn works() {
|
|||||||
pub fn acquire_string2(a: &JsValue) -> String {
|
pub fn acquire_string2(a: &JsValue) -> String {
|
||||||
a.as_string().unwrap_or("wrong".to_string())
|
a.as_string().unwrap_or("wrong".to_string())
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -138,14 +143,17 @@ fn works() {
|
|||||||
assert.strictEqual(wasm.acquire_string2(''), '');
|
assert.strictEqual(wasm.acquire_string2(''), '');
|
||||||
assert.strictEqual(wasm.acquire_string2('a'), 'a');
|
assert.strictEqual(wasm.acquire_string2('a'), 'a');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn eq_works() {
|
fn eq_works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -161,8 +169,11 @@ fn eq_works() {
|
|||||||
pub fn test1(a: &JsValue) -> bool {
|
pub fn test1(a: &JsValue) -> bool {
|
||||||
a == a
|
a == a
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -176,7 +187,7 @@ fn eq_works() {
|
|||||||
assert.strictEqual(wasm.test(x, x), true);
|
assert.strictEqual(wasm.test(x, x), true);
|
||||||
assert.strictEqual(wasm.test1(x), true);
|
assert.strictEqual(wasm.test1(x), true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -30,8 +32,11 @@ fn works() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn char_round(c: char)-> char { js_parrot(c) }
|
pub fn char_round(c: char)-> char { js_parrot(c) }
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
import * as wasm from './out';
|
import * as wasm from './out';
|
||||||
|
|
||||||
function assertEq(a, b) {
|
function assertEq(a, b) {
|
||||||
@ -55,6 +60,7 @@ fn works() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function js_parrot(a) { return a; }
|
export function js_parrot(a) { return a; }
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -31,8 +33,11 @@ fn simple() {
|
|||||||
self.contents
|
self.contents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import { Foo } from "./out";
|
import { Foo } from "./out";
|
||||||
|
|
||||||
@ -53,14 +58,17 @@ fn simple() {
|
|||||||
assert.strictEqual(r3.add(42), 42);
|
assert.strictEqual(r3.add(42), 42);
|
||||||
r3.free();
|
r3.free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn strings() {
|
fn strings() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -98,8 +106,11 @@ fn strings() {
|
|||||||
self.contents.clone()
|
self.contents.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import { Foo } from "./out";
|
import { Foo } from "./out";
|
||||||
|
|
||||||
@ -111,14 +122,17 @@ fn strings() {
|
|||||||
assert.strictEqual(bar.name(), "foo-baz-3");
|
assert.strictEqual(bar.name(), "foo-baz-3");
|
||||||
bar.free();
|
bar.free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exceptions() {
|
fn exceptions() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -152,8 +166,11 @@ fn exceptions() {
|
|||||||
B {}
|
B {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import { A, B } from "./out";
|
import { A, B } from "./out";
|
||||||
|
|
||||||
@ -173,17 +190,23 @@ fn exceptions() {
|
|||||||
d.free();
|
d.free();
|
||||||
c.free();
|
c.free();
|
||||||
};
|
};
|
||||||
"#)
|
"#,
|
||||||
.file("test.d.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.d.ts",
|
||||||
|
r#"
|
||||||
export function test(): void;
|
export function test(): void;
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pass_one_to_another() {
|
fn pass_one_to_another() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -215,8 +238,11 @@ fn pass_one_to_another() {
|
|||||||
B {}
|
B {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { A, B } from "./out";
|
import { A, B } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
@ -226,14 +252,17 @@ fn pass_one_to_another() {
|
|||||||
a.bar(b);
|
a.bar(b);
|
||||||
a.free();
|
a.free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pass_into_js() {
|
fn pass_into_js() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -259,8 +288,11 @@ fn pass_into_js() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
take_foo(Foo(13));
|
take_foo(Foo(13));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run, Foo } from "./out";
|
import { run, Foo } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -273,14 +305,17 @@ fn pass_into_js() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn issue_27() {
|
fn issue_27() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -309,21 +344,27 @@ fn issue_27() {
|
|||||||
pub fn context() -> Context {
|
pub fn context() -> Context {
|
||||||
Context {}
|
Context {}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { context } from "./out";
|
import { context } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
context();
|
context();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pass_into_js_as_js_class() {
|
fn pass_into_js_as_js_class() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -349,8 +390,11 @@ fn pass_into_js_as_js_class() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
take_foo(Foo(13).into());
|
take_foo(Foo(13).into());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run, Foo } from "./out";
|
import { run, Foo } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -363,14 +407,17 @@ fn pass_into_js_as_js_class() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn constructors() {
|
fn constructors() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -416,8 +463,11 @@ fn constructors() {
|
|||||||
self.number + self.number2
|
self.number + self.number2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import { Foo, Bar, cross_item_construction } from "./out";
|
import { Foo, Bar, cross_item_construction } from "./out";
|
||||||
|
|
||||||
@ -440,7 +490,8 @@ fn constructors() {
|
|||||||
|
|
||||||
assert.strictEqual(cross_item_construction().get_sum(), 15);
|
assert.strictEqual(cross_item_construction().get_sum(), 15);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +499,9 @@ fn constructors() {
|
|||||||
fn empty_structs() {
|
fn empty_structs() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -463,14 +516,18 @@ fn empty_structs() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl Other { pub fn return_a_value() -> MissingClass { MissingClass {} } }
|
impl Other { pub fn return_a_value() -> MissingClass { MissingClass {} } }
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { Other } from "./out";
|
import { Other } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
Other.return_a_value();
|
Other.return_a_value();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +535,9 @@ fn empty_structs() {
|
|||||||
fn public_fields() {
|
fn public_fields() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -500,8 +559,11 @@ fn public_fields() {
|
|||||||
Foo::default()
|
Foo::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { Foo } from "./out";
|
import { Foo } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -523,7 +585,8 @@ fn public_fields() {
|
|||||||
a.d = 3.3;
|
a.d = 3.3;
|
||||||
assert.strictEqual(a.d, 3);
|
assert.strictEqual(a.d, 3);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,7 +594,9 @@ fn public_fields() {
|
|||||||
fn using_self() {
|
fn using_self() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -548,14 +613,18 @@ fn using_self() {
|
|||||||
Foo {}
|
Foo {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { Foo } from "./out";
|
import { Foo } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
Foo.new().free();
|
Foo.new().free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +632,9 @@ fn using_self() {
|
|||||||
fn readonly_fields() {
|
fn readonly_fields() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -583,8 +654,11 @@ fn readonly_fields() {
|
|||||||
Foo::default()
|
Foo::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { Foo } from "./out";
|
import { Foo } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -594,6 +668,7 @@ fn readonly_fields() {
|
|||||||
assert.throws(() => (a as any).a = 3, /has only a getter/);
|
assert.throws(() => (a as any).a = 3, /has only a getter/);
|
||||||
a.free();
|
a.free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -25,8 +27,11 @@ fn works() {
|
|||||||
|
|
||||||
assert_eq!(thread(&|a| a + 1), 3);
|
assert_eq!(thread(&|a| a + 1), 3);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function call(a: any) {
|
export function call(a: any) {
|
||||||
@ -40,14 +45,17 @@ fn works() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cannot_reuse() {
|
fn cannot_reuse() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -66,8 +74,11 @@ fn cannot_reuse() {
|
|||||||
call(&|| {});
|
call(&|| {});
|
||||||
assert!(call_again().is_err());
|
assert!(call_again().is_err());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
let CACHE: any = null;
|
let CACHE: any = null;
|
||||||
@ -83,14 +94,17 @@ fn cannot_reuse() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn long_lived() {
|
fn long_lived() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -125,8 +139,11 @@ fn long_lived() {
|
|||||||
}
|
}
|
||||||
assert!(hit.get());
|
assert!(hit.get());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function call1(a: any) {
|
export function call1(a: any) {
|
||||||
@ -140,14 +157,17 @@ fn long_lived() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn many_arity() {
|
fn many_arity() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -219,8 +239,11 @@ fn many_arity() {
|
|||||||
assert_eq!((a, b, c, d, e, f, g), (1, 2, 3, 4, 5, 6, 7))
|
assert_eq!((a, b, c, d, e, f, g), (1, 2, 3, 4, 5, 6, 7))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function call1(a: any) { a() }
|
export function call1(a: any) { a() }
|
||||||
@ -235,14 +258,17 @@ fn many_arity() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn long_lived_dropping() {
|
fn long_lived_dropping() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -270,8 +296,11 @@ fn long_lived_dropping() {
|
|||||||
drop(a);
|
drop(a);
|
||||||
assert!(call().is_err());
|
assert!(call().is_err());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
let CACHE: any = null;
|
let CACHE: any = null;
|
||||||
@ -282,14 +311,17 @@ fn long_lived_dropping() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn long_fnmut_recursive() {
|
fn long_fnmut_recursive() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -311,8 +343,11 @@ fn long_fnmut_recursive() {
|
|||||||
cache(&a);
|
cache(&a);
|
||||||
assert!(call().is_ok());
|
assert!(call().is_ok());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
let CACHE: any = null;
|
let CACHE: any = null;
|
||||||
@ -323,14 +358,17 @@ fn long_fnmut_recursive() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fnmut() {
|
fn fnmut() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -356,8 +394,11 @@ fn fnmut() {
|
|||||||
}), 3);
|
}), 3);
|
||||||
assert!(x);
|
assert!(x);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function call(a: any) {
|
export function call(a: any) {
|
||||||
@ -371,14 +412,17 @@ fn fnmut() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fnmut_bad() {
|
fn fnmut_bad() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -408,8 +452,11 @@ fn fnmut_bad() {
|
|||||||
|
|
||||||
assert!(again(true).is_err());
|
assert!(again(true).is_err());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
let F: any = null;
|
let F: any = null;
|
||||||
@ -426,14 +473,17 @@ fn fnmut_bad() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_arguments() {
|
fn string_arguments() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -454,8 +504,11 @@ fn string_arguments() {
|
|||||||
});
|
});
|
||||||
assert!(x);
|
assert!(x);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function call(a: any) {
|
export function call(a: any) {
|
||||||
@ -465,14 +518,17 @@ fn string_arguments() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_ret() {
|
fn string_ret() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -495,8 +551,11 @@ fn string_ret() {
|
|||||||
});
|
});
|
||||||
assert!(x);
|
assert!(x);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -508,7 +567,7 @@ fn string_ret() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
let mut p = project();
|
let mut p = project();
|
||||||
p.file("src/lib.rs", r#"
|
p.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -33,24 +35,27 @@ fn works() {
|
|||||||
self.a.clone()
|
self.a.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#);
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
let (root, target) = p.cargo_build();
|
let (root, target) = p.cargo_build();
|
||||||
p.gen_bindings(&root, &target);
|
p.gen_bindings(&root, &target);
|
||||||
let js = p.read_js();
|
let js = p.read_js();
|
||||||
let comments = extract_doc_comments(&js);
|
let comments = extract_doc_comments(&js);
|
||||||
assert!(comments.iter().all(|c| c == "This comment should exist"));
|
assert!(comments.iter().all(|c| c == "This comment should exist"));
|
||||||
}
|
}
|
||||||
/// Pull out all lines in a js string that start with
|
/// Pull out all lines in a js string that start with
|
||||||
/// '* ', all other lines will either be comment start, comment
|
/// '* ', all other lines will either be comment start, comment
|
||||||
/// end or actual js lines.
|
/// end or actual js lines.
|
||||||
fn extract_doc_comments(js: &str) -> Vec<String> {
|
fn extract_doc_comments(js: &str) -> Vec<String> {
|
||||||
js.lines().filter_map(|l| {
|
js.lines()
|
||||||
let trimmed = l.trim();
|
.filter_map(|l| {
|
||||||
if trimmed.starts_with("* ") {
|
let trimmed = l.trim();
|
||||||
Some(trimmed[2..].to_owned())
|
if trimmed.starts_with("* ") {
|
||||||
} else {
|
Some(trimmed[2..].to_owned())
|
||||||
None
|
} else {
|
||||||
}
|
None
|
||||||
}).collect()
|
}
|
||||||
}
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn c_style_enum() {
|
fn c_style_enum() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -25,8 +27,11 @@ fn c_style_enum() {
|
|||||||
Color::Red => Color::Green,
|
Color::Red => Color::Green,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -38,14 +43,17 @@ fn c_style_enum() {
|
|||||||
|
|
||||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn c_style_enum_with_custom_values() {
|
fn c_style_enum_with_custom_values() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -73,8 +81,11 @@ fn c_style_enum_with_custom_values() {
|
|||||||
Color::Red => Color::Green,
|
Color::Red => Color::Green,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -86,6 +97,7 @@ fn c_style_enum_with_custom_values() {
|
|||||||
|
|
||||||
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
assert.strictEqual(wasm.cycle(wasm.Color.Green), wasm.Color.Yellow);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -27,8 +29,11 @@ fn simple() {
|
|||||||
#[wasm_bindgen(js_namespace = Math)]
|
#[wasm_bindgen(js_namespace = Math)]
|
||||||
fn log(a: f64) -> f64;
|
fn log(a: f64) -> f64;
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -36,14 +41,17 @@ fn simple() {
|
|||||||
wasm.get_random();
|
wasm.get_random();
|
||||||
assert.strictEqual(wasm.do_log(1.0), Math.log(1.0));
|
assert.strictEqual(wasm.do_log(1.0), Math.log(1.0));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn import_class() {
|
fn import_class() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -60,8 +68,11 @@ fn import_class() {
|
|||||||
pub fn baz() {
|
pub fn baz() {
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { baz } from "./out";
|
import { baz } from "./out";
|
||||||
import { called } from "./another";
|
import { called } from "./another";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
@ -70,8 +81,11 @@ fn import_class() {
|
|||||||
baz();
|
baz();
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
export let called = false;
|
export let called = false;
|
||||||
|
|
||||||
export class Foo {
|
export class Foo {
|
||||||
@ -79,14 +93,17 @@ fn import_class() {
|
|||||||
called = true;
|
called = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn construct() {
|
fn construct() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -113,8 +130,11 @@ fn construct() {
|
|||||||
f.append_to_internal_string(" foo");
|
f.append_to_internal_string(" foo");
|
||||||
f.assert_internal_string("this foo");
|
f.assert_internal_string("this foo");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
import { called } from "./another";
|
import { called } from "./another";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
@ -123,8 +143,11 @@ fn construct() {
|
|||||||
run();
|
run();
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
export let called = false;
|
export let called = false;
|
||||||
@ -151,14 +174,17 @@ fn construct() {
|
|||||||
called = true;
|
called = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_constructors() {
|
fn new_constructors() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -179,15 +205,21 @@ fn new_constructors() {
|
|||||||
let f = Foo::new(1);
|
let f = Foo::new(1);
|
||||||
assert_eq!(f.get(), 2);
|
assert_eq!(f.get(), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
export class Foo {
|
export class Foo {
|
||||||
constructor(private field: number) {
|
constructor(private field: number) {
|
||||||
}
|
}
|
||||||
@ -196,14 +228,17 @@ fn new_constructors() {
|
|||||||
return this.field + 1;
|
return this.field + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn switch_methods() {
|
fn switch_methods() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -233,8 +268,11 @@ fn switch_methods() {
|
|||||||
pub fn b() {
|
pub fn b() {
|
||||||
Foo::new().b();
|
Foo::new().b();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { a, b } from "./out";
|
import { a, b } from "./out";
|
||||||
import { Foo, called } from "./another";
|
import { Foo, called } from "./another";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
@ -259,8 +297,11 @@ fn switch_methods() {
|
|||||||
b();
|
b();
|
||||||
assert.strictEqual(called.a, true);
|
assert.strictEqual(called.a, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
export let called = { a: false };
|
export let called = { a: false };
|
||||||
|
|
||||||
export class Foo {
|
export class Foo {
|
||||||
@ -275,14 +316,17 @@ fn switch_methods() {
|
|||||||
called.a = true;
|
called.a = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn properties() {
|
fn properties() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -310,15 +354,21 @@ fn properties() {
|
|||||||
a.set_a(2);
|
a.set_a(2);
|
||||||
assert_eq!(a.a(), 2);
|
assert_eq!(a.a(), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
export class Foo {
|
export class Foo {
|
||||||
constructor(private num: number) {
|
constructor(private num: number) {
|
||||||
this.num = 1;
|
this.num = 1;
|
||||||
@ -332,14 +382,17 @@ fn properties() {
|
|||||||
this.num = val;
|
this.num = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rename_setter_getter() {
|
fn rename_setter_getter() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -367,15 +420,21 @@ fn rename_setter_getter() {
|
|||||||
a.another(2);
|
a.another(2);
|
||||||
assert_eq!(a.test(), 2);
|
assert_eq!(a.test(), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("another.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"another.ts",
|
||||||
|
r#"
|
||||||
export class Foo {
|
export class Foo {
|
||||||
constructor(private num: number) {
|
constructor(private num: number) {
|
||||||
this.num = 1;
|
this.num = 1;
|
||||||
@ -389,6 +448,7 @@ fn rename_setter_getter() {
|
|||||||
this.num = val;
|
this.num = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -37,8 +39,11 @@ fn simple() {
|
|||||||
pub fn get_the_object() -> JsValue {
|
pub fn get_the_object() -> JsValue {
|
||||||
return_object()
|
return_object()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -78,14 +83,17 @@ fn simple() {
|
|||||||
|
|
||||||
assert.strictEqual(wasm.get_the_object(), SYM);
|
assert.strictEqual(wasm.get_the_object(), SYM);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unused() {
|
fn unused() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
@ -100,8 +108,11 @@ fn unused() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn bar() {}
|
pub fn bar() {}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function debug_print() {}
|
export function debug_print() {}
|
||||||
@ -109,14 +120,17 @@ fn unused() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
wasm.bar();
|
wasm.bar();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_ret() {
|
fn string_ret() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -132,8 +146,11 @@ fn string_ret() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
assert_eq!(foo(), "bar");
|
assert_eq!(foo(), "bar");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function foo(): string {
|
export function foo(): string {
|
||||||
@ -143,14 +160,17 @@ fn string_ret() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
wasm.run();
|
wasm.run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn strings() {
|
fn strings() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -171,8 +191,11 @@ fn strings() {
|
|||||||
pub fn bar2(a: String) -> String {
|
pub fn bar2(a: String) -> String {
|
||||||
foo(a)
|
foo(a)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -184,14 +207,17 @@ fn strings() {
|
|||||||
assert.strictEqual(wasm.bar('a'), 'ab');
|
assert.strictEqual(wasm.bar('a'), 'ab');
|
||||||
assert.strictEqual(wasm.bar2('a'), 'ab');
|
assert.strictEqual(wasm.bar2('a'), 'ab');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exceptions() {
|
fn exceptions() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -217,8 +243,11 @@ fn exceptions() {
|
|||||||
assert!(baz().is_err());
|
assert!(baz().is_err());
|
||||||
bar();
|
bar();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run, run2 } from "./out";
|
import { run, run2 } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -242,14 +271,17 @@ fn exceptions() {
|
|||||||
run2();
|
run2();
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exn_caught() {
|
fn exn_caught() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -266,8 +298,11 @@ fn exn_caught() {
|
|||||||
pub fn run() -> JsValue {
|
pub fn run() -> JsValue {
|
||||||
foo().unwrap_err()
|
foo().unwrap_err()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -280,14 +315,17 @@ fn exn_caught() {
|
|||||||
assert.strictEqual(obj instanceof Error, true);
|
assert.strictEqual(obj instanceof Error, true);
|
||||||
assert.strictEqual(obj.message, 'error!');
|
assert.strictEqual(obj.message, 'error!');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn free_imports() {
|
fn free_imports() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -303,14 +341,18 @@ fn free_imports() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
assert_eq!(parseInt("3"), 3);
|
assert_eq!(parseInt("3"), 3);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +360,9 @@ fn free_imports() {
|
|||||||
fn import_a_field() {
|
fn import_a_field() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -334,8 +378,11 @@ fn import_a_field() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
assert_eq!(IMPORT.as_f64(), Some(1.0));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export const IMPORT = 1.0;
|
export const IMPORT = 1.0;
|
||||||
@ -343,14 +390,17 @@ fn import_a_field() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rename() {
|
fn rename() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -367,8 +417,11 @@ fn rename() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -382,14 +435,17 @@ fn rename() {
|
|||||||
wasm.run();
|
wasm.run();
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn versions() {
|
fn versions() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -405,8 +461,11 @@ fn versions() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const assert = require("assert");
|
const assert = require("assert");
|
||||||
|
|
||||||
@ -426,14 +485,17 @@ fn versions() {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rust_keyword() {
|
fn rust_keyword() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -450,8 +512,11 @@ fn rust_keyword() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
assert_eq!(foo(), 2);
|
assert_eq!(foo(), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export function self() {
|
export function self() {
|
||||||
@ -461,7 +526,8 @@ fn rust_keyword() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,7 +535,9 @@ fn rust_keyword() {
|
|||||||
fn rust_keyword2() {
|
fn rust_keyword2() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -487,8 +555,11 @@ fn rust_keyword2() {
|
|||||||
pub fn run() {
|
pub fn run() {
|
||||||
assert_eq!(FOO.as_f64(), Some(3.0));
|
assert_eq!(FOO.as_f64(), Some(3.0));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
export const bar = {
|
export const bar = {
|
||||||
@ -498,6 +569,7 @@ fn rust_keyword2() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn filter() {
|
fn filter() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -17,8 +19,11 @@ fn filter() {
|
|||||||
array.filter(&mut |x, _, _| x.as_f64().is_some())
|
array.filter(&mut |x, _, _| x.as_f64().is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -31,14 +36,17 @@ fn filter() {
|
|||||||
assert.deepStrictEqual(wasm.keep_numbers(numbers), numbers);
|
assert.deepStrictEqual(wasm.keep_numbers(numbers), numbers);
|
||||||
assert.deepStrictEqual(wasm.keep_numbers(mixed), [1, 2]);
|
assert.deepStrictEqual(wasm.keep_numbers(mixed), [1, 2]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index_of() {
|
fn index_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -50,8 +58,11 @@ fn index_of() {
|
|||||||
this.index_of(value, from_index)
|
this.index_of(value, from_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -69,14 +80,17 @@ fn index_of() {
|
|||||||
assert.equal(withFromIndex, 2);
|
assert.equal(withFromIndex, 2);
|
||||||
assert.equal(withFromIndexNotFound, -1);
|
assert.equal(withFromIndexNotFound, -1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_array() {
|
fn is_array() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -87,8 +101,11 @@ fn is_array() {
|
|||||||
pub fn is_array(value: &JsValue) -> bool {
|
pub fn is_array(value: &JsValue) -> bool {
|
||||||
js::Array::is_array(value)
|
js::Array::is_array(value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -109,14 +126,17 @@ fn is_array() {
|
|||||||
assert(!wasm.is_array(false));
|
assert(!wasm.is_array(false));
|
||||||
assert(!wasm.is_array({ __proto__: Array.prototype }));
|
assert(!wasm.is_array({ __proto__: Array.prototype }));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sort() {
|
fn sort() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -128,8 +148,11 @@ fn sort() {
|
|||||||
this.sort()
|
this.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -139,7 +162,8 @@ fn sort() {
|
|||||||
|
|
||||||
assert.deepStrictEqual(sorted, [1, 2, 3, 6])
|
assert.deepStrictEqual(sorted, [1, 2, 3, 6])
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +201,9 @@ fn some() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn last_index_of() {
|
fn last_index_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -189,8 +215,11 @@ fn last_index_of() {
|
|||||||
this.last_index_of(value, from_index)
|
this.last_index_of(value, from_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -208,14 +237,17 @@ fn last_index_of() {
|
|||||||
assert.equal(withFromIndex, 1);
|
assert.equal(withFromIndex, 1);
|
||||||
assert.equal(withFromIndexNotFound, -1);
|
assert.equal(withFromIndexNotFound, -1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn join() {
|
fn join() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -227,8 +259,11 @@ fn join() {
|
|||||||
this.join(delimiter)
|
this.join(delimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -240,14 +275,17 @@ fn join() {
|
|||||||
let withForwardSlash = wasm.join_array(characters, "/");
|
let withForwardSlash = wasm.join_array(characters, "/");
|
||||||
assert.equal("a/c/x/n", withForwardSlash);
|
assert.equal("a/c/x/n", withForwardSlash);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn slice() {
|
fn slice() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -258,8 +296,11 @@ fn slice() {
|
|||||||
pub fn create_slice(this: &js::Array, start: u32, end: u32) -> js::Array {
|
pub fn create_slice(this: &js::Array, start: u32, end: u32) -> js::Array {
|
||||||
this.slice(start, end)
|
this.slice(start, end)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -270,14 +311,17 @@ fn slice() {
|
|||||||
assert.equal(subset[0], "c");
|
assert.equal(subset[0], "c");
|
||||||
assert.equal(subset[1], "x");
|
assert.equal(subset[1], "x");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fill() {
|
fn fill() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -288,8 +332,11 @@ fn fill() {
|
|||||||
pub fn fill_with(this: &js::Array, value: JsValue, start: u32, end: u32) -> js::Array {
|
pub fn fill_with(this: &js::Array, value: JsValue, start: u32, end: u32) -> js::Array {
|
||||||
this.fill(value, start, end)
|
this.fill(value, start, end)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -300,7 +347,8 @@ fn fill() {
|
|||||||
assert.equal(subset[0], 0);
|
assert.equal(subset[0], 0);
|
||||||
assert.equal(subset[4], 1);
|
assert.equal(subset[4], 1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +389,9 @@ fn copy_within() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn pop() {
|
fn pop() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -353,8 +403,11 @@ fn pop() {
|
|||||||
this.pop()
|
this.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -364,15 +417,17 @@ fn pop() {
|
|||||||
assert.equal(item, 2);
|
assert.equal(item, 2);
|
||||||
assert.equal(characters.length, 5);
|
assert.equal(characters.length, 5);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn push() {
|
fn push() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -384,8 +439,11 @@ fn push() {
|
|||||||
this.push(value)
|
this.push(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -395,14 +453,17 @@ fn push() {
|
|||||||
assert.equal(length, 7);
|
assert.equal(length, 7);
|
||||||
assert.equal(characters[6], "a");
|
assert.equal(characters[6], "a");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reverse() {
|
fn reverse() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -414,8 +475,11 @@ fn reverse() {
|
|||||||
this.reverse()
|
this.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -425,14 +489,17 @@ fn reverse() {
|
|||||||
assert.equal(reversed[0], 2);
|
assert.equal(reversed[0], 2);
|
||||||
assert.equal(reversed[5], 8);
|
assert.equal(reversed[5], 8);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shift() {
|
fn shift() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -444,8 +511,11 @@ fn shift() {
|
|||||||
this.shift()
|
this.shift()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -456,14 +526,17 @@ fn shift() {
|
|||||||
assert.equal(shiftedItem, 8);
|
assert.equal(shiftedItem, 8);
|
||||||
assert.equal(characters.length, 5);
|
assert.equal(characters.length, 5);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unshift() {
|
fn unshift() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -475,8 +548,11 @@ fn unshift() {
|
|||||||
this.unshift(value)
|
this.unshift(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -487,14 +563,17 @@ fn unshift() {
|
|||||||
assert.equal(length, 7);
|
assert.equal(length, 7);
|
||||||
assert.equal(characters[0], "abba");
|
assert.equal(characters[0], "abba");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -506,8 +585,11 @@ fn to_string() {
|
|||||||
this.to_string()
|
this.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -517,15 +599,17 @@ fn to_string() {
|
|||||||
|
|
||||||
assert.equal(arrayString, "8,5,4,3,1,2");
|
assert.equal(arrayString, "8,5,4,3,1,2");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn includes() {
|
fn includes() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -537,8 +621,11 @@ fn includes() {
|
|||||||
this.includes(value, from_index)
|
this.includes(value, from_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -553,14 +640,17 @@ fn includes() {
|
|||||||
let isThreeIncluded = wasm.array_includes(characters, 3, 4);
|
let isThreeIncluded = wasm.array_includes(characters, 3, 4);
|
||||||
assert.ok(!isThreeIncluded);
|
assert.ok(!isThreeIncluded);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concat() {
|
fn concat() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -572,8 +662,11 @@ fn concat() {
|
|||||||
this.concat(arr)
|
this.concat(arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -584,14 +677,17 @@ fn concat() {
|
|||||||
let new_array = wasm.array_concat(arr1, arr2)
|
let new_array = wasm.array_concat(arr1, arr2)
|
||||||
assert.deepStrictEqual(new_array, [1, 2, 3, 4, 5, 6]);
|
assert.deepStrictEqual(new_array, [1, 2, 3, 4, 5, 6]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length() {
|
fn length() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -603,8 +699,11 @@ fn length() {
|
|||||||
this.length()
|
this.length()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -617,14 +716,17 @@ fn length() {
|
|||||||
let emptyLength = wasm.array_length(empty);
|
let emptyLength = wasm.array_length(empty);
|
||||||
assert.equal(emptyLength, 0);
|
assert.equal(emptyLength, 0);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn every() {
|
fn every() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -635,8 +737,11 @@ fn every() {
|
|||||||
pub fn array_every_number_is_even(array: &js::Array) -> bool {
|
pub fn array_every_number_is_even(array: &js::Array) -> bool {
|
||||||
array.every(&mut |el, _, _| el.as_f64().unwrap() % 2f64 == 0f64)
|
array.every(&mut |el, _, _| el.as_f64().unwrap() % 2f64 == 0f64)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -649,6 +754,7 @@ fn every() {
|
|||||||
assert(!wasm.array_every_number_is_even(arrayOdd));
|
assert(!wasm.array_every_number_is_even(arrayOdd));
|
||||||
assert(!wasm.array_every_number_is_even(arrayMixed));
|
assert(!wasm.array_every_number_is_even(arrayMixed));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn keys() {
|
fn keys() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -17,8 +19,11 @@ fn keys() {
|
|||||||
this.keys()
|
this.keys()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -30,14 +35,17 @@ fn keys() {
|
|||||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||||
assert.equal(Array.from(iterator)[0], Array.from(wasmIterator)[0]);
|
assert.equal(Array.from(iterator)[0], Array.from(wasmIterator)[0]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn entries() {
|
fn entries() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -49,8 +57,11 @@ fn entries() {
|
|||||||
this.entries()
|
this.entries()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -64,6 +75,7 @@ fn entries() {
|
|||||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||||
assert.equal(jsItem.value[1], wasmItem.value[1]);
|
assert.equal(jsItem.value[1], wasmItem.value[1]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new_undefined() {
|
fn new_undefined() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,22 +18,28 @@ fn new_undefined() {
|
|||||||
pub fn new_boolean() -> js::Boolean {
|
pub fn new_boolean() -> js::Boolean {
|
||||||
js::Boolean::new(JsValue::undefined())
|
js::Boolean::new(JsValue::undefined())
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.new_boolean().valueOf(), false);
|
assert.equal(wasm.new_boolean().valueOf(), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_truely() {
|
fn new_truely() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,14 +50,18 @@ fn new_truely() {
|
|||||||
pub fn new_boolean() -> js::Boolean {
|
pub fn new_boolean() -> js::Boolean {
|
||||||
js::Boolean::new(JsValue::from("foo"))
|
js::Boolean::new(JsValue::from("foo"))
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.new_boolean().valueOf(), true);
|
assert.equal(wasm.new_boolean().valueOf(), true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new() {
|
fn new() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,22 +18,28 @@ fn new() {
|
|||||||
pub fn new_date() -> Date {
|
pub fn new_date() -> Date {
|
||||||
Date::new()
|
Date::new()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(typeof wasm.new_date(), "object");
|
assert.equal(typeof wasm.new_date(), "object");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_date_string() {
|
fn to_date_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,8 +50,11 @@ fn to_date_string() {
|
|||||||
pub fn to_date_string(this: &Date) -> JsString {
|
pub fn to_date_string(this: &Date) -> JsString {
|
||||||
this.to_date_string()
|
this.to_date_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -52,14 +63,17 @@ fn to_date_string() {
|
|||||||
|
|
||||||
assert.equal(wasm.to_date_string(date), 'Wed Jul 28 1993');
|
assert.equal(wasm.to_date_string(date), 'Wed Jul 28 1993');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_iso_string() {
|
fn to_iso_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -70,8 +84,11 @@ fn to_iso_string() {
|
|||||||
pub fn to_iso_string(this: &Date) -> JsString {
|
pub fn to_iso_string(this: &Date) -> JsString {
|
||||||
this.to_iso_string()
|
this.to_iso_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -80,14 +97,17 @@ fn to_iso_string() {
|
|||||||
|
|
||||||
assert.equal(wasm.to_iso_string(date), '2011-10-05T14:48:00.000Z');
|
assert.equal(wasm.to_iso_string(date), '2011-10-05T14:48:00.000Z');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_json() {
|
fn to_json() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -98,8 +118,11 @@ fn to_json() {
|
|||||||
pub fn to_json(this: &Date) -> JsString {
|
pub fn to_json(this: &Date) -> JsString {
|
||||||
this.to_json()
|
this.to_json()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -108,7 +131,8 @@ fn to_json() {
|
|||||||
|
|
||||||
assert.equal(wasm.to_json(date), '1975-08-19T23:15:30.000Z');
|
assert.equal(wasm.to_json(date), '1975-08-19T23:15:30.000Z');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +197,9 @@ fn to_locale_string() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn to_locale_time_string() {
|
fn to_locale_time_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -184,8 +210,11 @@ fn to_locale_time_string() {
|
|||||||
pub fn to_locale_time_string(this: &Date, locale: JsString) -> JsString {
|
pub fn to_locale_time_string(this: &Date, locale: JsString) -> JsString {
|
||||||
this.to_locale_time_string(locale)
|
this.to_locale_time_string(locale)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -193,14 +222,17 @@ fn to_locale_time_string() {
|
|||||||
let date = new Date('August 19, 1975 23:15:30');
|
let date = new Date('August 19, 1975 23:15:30');
|
||||||
assert.equal(wasm.to_locale_time_string(date, 'en-US'), "11:15:30 PM");
|
assert.equal(wasm.to_locale_time_string(date, 'en-US'), "11:15:30 PM");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -211,8 +243,11 @@ fn to_string() {
|
|||||||
pub fn to_string(this: &Date) -> JsString {
|
pub fn to_string(this: &Date) -> JsString {
|
||||||
this.to_string()
|
this.to_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -220,14 +255,17 @@ fn to_string() {
|
|||||||
let date = new Date('August 19, 1975 23:15:30');
|
let date = new Date('August 19, 1975 23:15:30');
|
||||||
assert.equal(wasm.to_string(date).substring(0, 15), "Tue Aug 19 1975");
|
assert.equal(wasm.to_string(date).substring(0, 15), "Tue Aug 19 1975");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_time_string() {
|
fn to_time_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -238,8 +276,11 @@ fn to_time_string() {
|
|||||||
pub fn to_time_string(this: &Date) -> JsString {
|
pub fn to_time_string(this: &Date) -> JsString {
|
||||||
this.to_time_string()
|
this.to_time_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -247,14 +288,17 @@ fn to_time_string() {
|
|||||||
let date = new Date('August 19, 1975 23:15:30');
|
let date = new Date('August 19, 1975 23:15:30');
|
||||||
assert.equal(wasm.to_time_string(date).substring(0, 8), "23:15:30");
|
assert.equal(wasm.to_time_string(date).substring(0, 8), "23:15:30");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_utc_string() {
|
fn to_utc_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -265,8 +309,11 @@ fn to_utc_string() {
|
|||||||
pub fn to_utc_string(this: &Date) -> JsString {
|
pub fn to_utc_string(this: &Date) -> JsString {
|
||||||
this.to_utc_string()
|
this.to_utc_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -274,14 +321,17 @@ fn to_utc_string() {
|
|||||||
let date = new Date('14 Jun 2017 00:00:00 PDT');
|
let date = new Date('14 Jun 2017 00:00:00 PDT');
|
||||||
assert.equal(wasm.to_utc_string(date), "Wed, 14 Jun 2017 07:00:00 GMT");
|
assert.equal(wasm.to_utc_string(date), "Wed, 14 Jun 2017 07:00:00 GMT");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn value_of() {
|
fn value_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -292,8 +342,11 @@ fn value_of() {
|
|||||||
pub fn js_value_of(this: &Date) -> Date {
|
pub fn js_value_of(this: &Date) -> Date {
|
||||||
this.value_of()
|
this.value_of()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -301,6 +354,7 @@ fn value_of() {
|
|||||||
let date = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
|
let date = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
|
||||||
assert.equal(wasm.js_value_of(date), 823230245000);
|
assert.equal(wasm.js_value_of(date), 823230245000);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn apply() {
|
fn apply() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,8 +18,11 @@ fn apply() {
|
|||||||
pub fn apply(this: &js::Function, context: &JsValue, args: &js::Array) -> js::Function {
|
pub fn apply(this: &js::Function, context: &JsValue, args: &js::Array) -> js::Function {
|
||||||
this.apply(context, args)
|
this.apply(context, args)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -28,14 +33,17 @@ fn apply() {
|
|||||||
wasm.apply(Array.prototype.push, arr, [3]);
|
wasm.apply(Array.prototype.push, arr, [3]);
|
||||||
assert.equal(arr[2], 3);
|
assert.equal(arr[2], 3);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn length() {
|
fn length() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -46,8 +54,11 @@ fn length() {
|
|||||||
pub fn fn_length(this: &js::Function) -> u32 {
|
pub fn fn_length(this: &js::Function) -> u32 {
|
||||||
this.length()
|
this.length()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -68,14 +79,17 @@ fn length() {
|
|||||||
assert.equal(wasm.fn_length(fn1), 1);
|
assert.equal(wasm.fn_length(fn1), 1);
|
||||||
assert.equal(wasm.fn_length(fn2), 2);
|
assert.equal(wasm.fn_length(fn2), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn name() {
|
fn name() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -86,8 +100,11 @@ fn name() {
|
|||||||
pub fn fn_name(this: &js::Function) -> js::JsString {
|
pub fn fn_name(this: &js::Function) -> js::JsString {
|
||||||
this.name()
|
this.name()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -109,14 +126,17 @@ fn name() {
|
|||||||
const closure = () => {};
|
const closure = () => {};
|
||||||
assert.equal(wasm.fn_name(closure), 'closure');
|
assert.equal(wasm.fn_name(closure), 'closure');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -127,8 +147,11 @@ fn to_string() {
|
|||||||
pub fn get_source_code(this: &js::Function) -> js::JsString {
|
pub fn get_source_code(this: &js::Function) -> js::JsString {
|
||||||
this.to_string()
|
this.to_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -139,6 +162,7 @@ fn to_string() {
|
|||||||
assert.equal(wasm.get_source_code(fn1), 'function fn1(a, b) { return a + b; }');
|
assert.equal(wasm.get_source_code(fn1), 'function fn1(a, b) { return a + b; }');
|
||||||
assert.equal(wasm.get_source_code(fn2), 'function (a) { return console.log(a); }');
|
assert.equal(wasm.get_source_code(fn2), 'function (a) { return console.log(a); }');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn length() {
|
fn length() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -17,8 +19,11 @@ fn length() {
|
|||||||
this.length()
|
this.length()
|
||||||
}
|
}
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -29,14 +34,17 @@ fn length() {
|
|||||||
let empty = '';
|
let empty = '';
|
||||||
assert.equal(wasm.string_length(empty), 0);
|
assert.equal(wasm.string_length(empty), 0);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn char_at() {
|
fn char_at() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -47,8 +55,11 @@ fn char_at() {
|
|||||||
pub fn string_char_at(this: &js::JsString, index: u32) -> js::JsString {
|
pub fn string_char_at(this: &js::JsString, index: u32) -> js::JsString {
|
||||||
this.char_at(index)
|
this.char_at(index)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -58,14 +69,17 @@ fn char_at() {
|
|||||||
assert.equal(wasm.string_char_at(anyString, 0), "B");
|
assert.equal(wasm.string_char_at(anyString, 0), "B");
|
||||||
assert.equal(wasm.string_char_at(anyString, 999), "");
|
assert.equal(wasm.string_char_at(anyString, 999), "");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn char_code_at() {
|
fn char_code_at() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -76,8 +90,11 @@ fn char_code_at() {
|
|||||||
pub fn string_char_code_at(this: &js::JsString, index: u32) -> js::Number {
|
pub fn string_char_code_at(this: &js::JsString, index: u32) -> js::Number {
|
||||||
this.char_code_at(index)
|
this.char_code_at(index)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -87,14 +104,17 @@ fn char_code_at() {
|
|||||||
assert.equal(wasm.string_char_code_at(anyString, 0), 66);
|
assert.equal(wasm.string_char_code_at(anyString, 0), 66);
|
||||||
assert.ok(isNaN(wasm.string_char_code_at(anyString, 999)));
|
assert.ok(isNaN(wasm.string_char_code_at(anyString, 999)));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn code_point_at() {
|
fn code_point_at() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -105,8 +125,11 @@ fn code_point_at() {
|
|||||||
pub fn string_code_point_at(this: &js::JsString, pos: u32) -> JsValue {
|
pub fn string_code_point_at(this: &js::JsString, pos: u32) -> JsValue {
|
||||||
this.code_point_at(pos)
|
this.code_point_at(pos)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -115,14 +138,17 @@ fn code_point_at() {
|
|||||||
assert.equal(wasm.string_code_point_at('\uD800\uDC00', 0), 65536);
|
assert.equal(wasm.string_code_point_at('\uD800\uDC00', 0), 65536);
|
||||||
assert.equal(wasm.string_code_point_at('XYZ', 42), undefined);
|
assert.equal(wasm.string_code_point_at('XYZ', 42), undefined);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concat() {
|
fn concat() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -133,8 +159,11 @@ fn concat() {
|
|||||||
pub fn string_concat(this: &js::JsString, string_2: &js::JsString) -> js::JsString {
|
pub fn string_concat(this: &js::JsString, string_2: &js::JsString) -> js::JsString {
|
||||||
this.concat(string_2)
|
this.concat(string_2)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -147,7 +176,8 @@ fn concat() {
|
|||||||
assert.equal(wasm.string_concat('foo', true), 'footrue');
|
assert.equal(wasm.string_concat('foo', true), 'footrue');
|
||||||
assert.equal(wasm.string_concat('foo', 1234), 'foo1234');
|
assert.equal(wasm.string_concat('foo', 1234), 'foo1234');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +258,9 @@ fn index_of() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn slice() {
|
fn slice() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -239,8 +271,11 @@ fn slice() {
|
|||||||
pub fn create_slice(this: &js::JsString, start: u32, end: u32) -> js::JsString {
|
pub fn create_slice(this: &js::JsString, start: u32, end: u32) -> js::JsString {
|
||||||
this.slice(start, end)
|
this.slice(start, end)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -250,7 +285,8 @@ fn slice() {
|
|||||||
|
|
||||||
assert.equal(subset, "cx");
|
assert.equal(subset, "cx");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +399,9 @@ fn substr() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -374,8 +412,11 @@ fn to_string() {
|
|||||||
pub fn string_to_string(this: &js::JsString) -> js::JsString {
|
pub fn string_to_string(this: &js::JsString) -> js::JsString {
|
||||||
this.to_string()
|
this.to_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -383,14 +424,17 @@ fn to_string() {
|
|||||||
let greeting = 'Hello world!';
|
let greeting = 'Hello world!';
|
||||||
assert.equal(wasm.string_to_string(greeting), 'Hello world!');
|
assert.equal(wasm.string_to_string(greeting), 'Hello world!');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trim() {
|
fn trim() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -401,8 +445,11 @@ fn trim() {
|
|||||||
pub fn string_trim(this: &js::JsString) -> js::JsString {
|
pub fn string_trim(this: &js::JsString) -> js::JsString {
|
||||||
this.trim()
|
this.trim()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -411,14 +458,17 @@ fn trim() {
|
|||||||
// Another example of .trim() removing whitespace from just one side.
|
// Another example of .trim() removing whitespace from just one side.
|
||||||
assert.equal(wasm.string_trim('foo '), 'foo');
|
assert.equal(wasm.string_trim('foo '), 'foo');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trim_end_and_trim_right() {
|
fn trim_end_and_trim_right() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -434,8 +484,11 @@ fn trim_end_and_trim_right() {
|
|||||||
pub fn string_trim_right(this: &js::JsString) -> js::JsString {
|
pub fn string_trim_right(this: &js::JsString) -> js::JsString {
|
||||||
this.trim_right()
|
this.trim_right()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -445,14 +498,17 @@ fn trim_end_and_trim_right() {
|
|||||||
assert.equal(wasm.string_trim_end(greeting), trimmed);
|
assert.equal(wasm.string_trim_end(greeting), trimmed);
|
||||||
assert.equal(wasm.string_trim_right(greeting), trimmed);
|
assert.equal(wasm.string_trim_right(greeting), trimmed);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trim_start_and_trim_left() {
|
fn trim_start_and_trim_left() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -468,8 +524,11 @@ fn trim_start_and_trim_left() {
|
|||||||
pub fn string_trim_left(this: &js::JsString) -> js::JsString {
|
pub fn string_trim_left(this: &js::JsString) -> js::JsString {
|
||||||
this.trim_left()
|
this.trim_left()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -479,14 +538,17 @@ fn trim_start_and_trim_left() {
|
|||||||
assert.equal(wasm.string_trim_start(greeting), trimmed);
|
assert.equal(wasm.string_trim_start(greeting), trimmed);
|
||||||
assert.equal(wasm.string_trim_left(greeting), trimmed);
|
assert.equal(wasm.string_trim_left(greeting), trimmed);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn value_of() {
|
fn value_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -497,8 +559,11 @@ fn value_of() {
|
|||||||
pub fn string_value_of(this: &js::JsString) -> js::JsString {
|
pub fn string_value_of(this: &js::JsString) -> js::JsString {
|
||||||
this.value_of()
|
this.value_of()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -506,6 +571,7 @@ fn value_of() {
|
|||||||
let greeting = new String('Hello world!');
|
let greeting = new String('Hello world!');
|
||||||
assert.equal(wasm.string_value_of(greeting), 'Hello world!');
|
assert.equal(wasm.string_value_of(greeting), 'Hello world!');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
use super::project;
|
use super::project;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn abs() {
|
fn abs() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -17,8 +18,11 @@ fn abs() {
|
|||||||
pub fn abs(number: i32) -> js::Number {
|
pub fn abs(number: i32) -> js::Number {
|
||||||
js::Math::abs(number)
|
js::Math::abs(number)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -26,14 +30,17 @@ fn abs() {
|
|||||||
assert.equal(wasm.abs(-32), Math.abs(-32));
|
assert.equal(wasm.abs(-32), Math.abs(-32));
|
||||||
assert.equal(wasm.abs(32), 32);
|
assert.equal(wasm.abs(32), 32);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn acos() {
|
fn acos() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -44,22 +51,28 @@ fn acos() {
|
|||||||
pub fn acos(adjacent: i32, hypotenuse: i32) -> js::Number {
|
pub fn acos(adjacent: i32, hypotenuse: i32) -> js::Number {
|
||||||
js::Math::acos(adjacent, hypotenuse)
|
js::Math::acos(adjacent, hypotenuse)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.acos(-1, 1), Math.PI);
|
assert.equal(wasm.acos(-1, 1), Math.PI);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn acosh() {
|
fn acosh() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -70,8 +83,11 @@ fn acosh() {
|
|||||||
pub fn acosh(number: i32) -> js::Number {
|
pub fn acosh(number: i32) -> js::Number {
|
||||||
js::Math::acosh(number)
|
js::Math::acosh(number)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -79,14 +95,17 @@ fn acosh() {
|
|||||||
assert.equal(wasm.acosh(1), 0);
|
assert.equal(wasm.acosh(1), 0);
|
||||||
assert.equal(wasm.acosh(2), Math.acosh(2));
|
assert.equal(wasm.acosh(2), Math.acosh(2));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn asin() {
|
fn asin() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -97,22 +116,28 @@ fn asin() {
|
|||||||
pub fn asin(opposite: i32, hypotenuse: i32) -> js::Number {
|
pub fn asin(opposite: i32, hypotenuse: i32) -> js::Number {
|
||||||
js::Math::asin(opposite / hypotenuse)
|
js::Math::asin(opposite / hypotenuse)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.asin(1, 1), Math.asin(1));
|
assert.equal(wasm.asin(1, 1), Math.asin(1));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn asinh() {
|
fn asinh() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -123,22 +148,28 @@ fn asinh() {
|
|||||||
pub fn asinh(number: i32) -> js::Number {
|
pub fn asinh(number: i32) -> js::Number {
|
||||||
js::Math::asinh(number)
|
js::Math::asinh(number)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.asinh(1), Math.asinh(1));
|
assert.equal(wasm.asinh(1), Math.asinh(1));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn atan() {
|
fn atan() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -149,22 +180,28 @@ fn atan() {
|
|||||||
pub fn atan(number: i32) -> js::Number {
|
pub fn atan(number: i32) -> js::Number {
|
||||||
js::Math::atan(number)
|
js::Math::atan(number)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.atan(1), Math.atan(1));
|
assert.equal(wasm.atan(1), Math.atan(1));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn atan2() {
|
fn atan2() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -175,22 +212,28 @@ fn atan2() {
|
|||||||
pub fn atan2(x: i32, y: i32) -> js::Number {
|
pub fn atan2(x: i32, y: i32) -> js::Number {
|
||||||
js::Math::atan2(x, y)
|
js::Math::atan2(x, y)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.atan2(1, 2), Math.atan2(1, 2));
|
assert.equal(wasm.atan2(1, 2), Math.atan2(1, 2));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn atanh() {
|
fn atanh() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -201,22 +244,28 @@ fn atanh() {
|
|||||||
pub fn atanh(x: i32) -> js::Number {
|
pub fn atanh(x: i32) -> js::Number {
|
||||||
js::Math::atanh(x)
|
js::Math::atanh(x)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.atanh(1), Math.atanh(1));
|
assert.equal(wasm.atanh(1), Math.atanh(1));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cbrt() {
|
fn cbrt() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -227,22 +276,28 @@ fn cbrt() {
|
|||||||
pub fn cbrt(x: i32) -> js::Number {
|
pub fn cbrt(x: i32) -> js::Number {
|
||||||
js::Math::cbrt(x)
|
js::Math::cbrt(x)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.cbrt(27), 3);
|
assert.equal(wasm.cbrt(27), 3);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ceil() {
|
fn ceil() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -253,8 +308,11 @@ fn ceil() {
|
|||||||
pub fn ceil(x: f32) -> js::Number {
|
pub fn ceil(x: f32) -> js::Number {
|
||||||
js::Math::ceil(x)
|
js::Math::ceil(x)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -262,14 +320,17 @@ fn ceil() {
|
|||||||
assert.equal(wasm.ceil(1.1), 2);
|
assert.equal(wasm.ceil(1.1), 2);
|
||||||
assert.equal(wasm.ceil(-1.1), -1);
|
assert.equal(wasm.ceil(-1.1), -1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn clz32() {
|
fn clz32() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -280,8 +341,11 @@ fn clz32() {
|
|||||||
pub fn clz32(x: i32) -> js::Number {
|
pub fn clz32(x: i32) -> js::Number {
|
||||||
js::Math::clz32(x)
|
js::Math::clz32(x)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -289,14 +353,17 @@ fn clz32() {
|
|||||||
assert.equal(wasm.clz32(1), 31);
|
assert.equal(wasm.clz32(1), 31);
|
||||||
assert.equal(wasm.clz32(1000), 22);
|
assert.equal(wasm.clz32(1000), 22);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn floor() {
|
fn floor() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -307,8 +374,11 @@ fn floor() {
|
|||||||
pub fn floor(x: f32) -> js::Number {
|
pub fn floor(x: f32) -> js::Number {
|
||||||
js::Math::floor(x)
|
js::Math::floor(x)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -316,6 +386,7 @@ fn floor() {
|
|||||||
assert.equal(wasm.floor(5.95), 5);
|
assert.equal(wasm.floor(5.95), 5);
|
||||||
assert.equal(wasm.floor(-5.05), -6);
|
assert.equal(wasm.floor(-5.05), -6);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use super::project;
|
use super::project;
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_locale_string() {
|
fn to_locale_string() {
|
||||||
project()
|
project()
|
||||||
@ -36,7 +35,9 @@ fn to_locale_string() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn to_precision() {
|
fn to_precision() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -52,8 +53,11 @@ fn to_precision() {
|
|||||||
};
|
};
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -61,14 +65,17 @@ fn to_precision() {
|
|||||||
assert.equal(wasm.to_precision(0.1, 3), "0.100");
|
assert.equal(wasm.to_precision(0.1, 3), "0.100");
|
||||||
assert.equal(wasm.to_precision(10, 101), "RangeError");
|
assert.equal(wasm.to_precision(10, 101), "RangeError");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -84,8 +91,11 @@ fn to_string() {
|
|||||||
};
|
};
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -95,14 +105,17 @@ fn to_string() {
|
|||||||
assert.equal(wasm.to_string(233, 16), "e9");
|
assert.equal(wasm.to_string(233, 16), "e9");
|
||||||
assert.equal(wasm.to_string(number, 100), "RangeError");
|
assert.equal(wasm.to_string(number, 100), "RangeError");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn value_of() {
|
fn value_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -113,8 +126,11 @@ fn value_of() {
|
|||||||
pub fn js_value_of(this: &js::Number) -> js::Number {
|
pub fn js_value_of(this: &js::Number) -> js::Number {
|
||||||
this.value_of()
|
this.value_of()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -123,14 +139,17 @@ fn value_of() {
|
|||||||
assert.equal(wasm.js_value_of(number), 42);
|
assert.equal(wasm.js_value_of(number), 42);
|
||||||
assert.equal(typeof wasm.js_value_of(number), "number");
|
assert.equal(typeof wasm.js_value_of(number), "number");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_fixed() {
|
fn to_fixed() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -146,8 +165,11 @@ fn to_fixed() {
|
|||||||
};
|
};
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -155,14 +177,17 @@ fn to_fixed() {
|
|||||||
assert.equal(wasm.to_fixed(123.456, 2), "123.46");
|
assert.equal(wasm.to_fixed(123.456, 2), "123.46");
|
||||||
assert.equal(wasm.to_fixed(10, 101), "RangeError");
|
assert.equal(wasm.to_fixed(10, 101), "RangeError");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_exponential() {
|
fn to_exponential() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -178,8 +203,11 @@ fn to_exponential() {
|
|||||||
};
|
};
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -187,6 +215,7 @@ fn to_exponential() {
|
|||||||
assert.equal(wasm.to_exponential(123456, 2), "1.23e+5");
|
assert.equal(wasm.to_exponential(123456, 2), "1.23e+5");
|
||||||
assert.equal(wasm.to_exponential(10, 101), "RangeError");
|
assert.equal(wasm.to_exponential(10, 101), "RangeError");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new() {
|
fn new() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,22 +18,28 @@ fn new() {
|
|||||||
pub fn new_object() -> js::Object {
|
pub fn new_object() -> js::Object {
|
||||||
js::Object::new()
|
js::Object::new()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(typeof wasm.new_object(), "object");
|
assert.equal(typeof wasm.new_object(), "object");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn has_own_property() {
|
fn has_own_property() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,8 +50,11 @@ fn has_own_property() {
|
|||||||
pub fn has_own_foo_property(obj: &js::Object, property: &JsValue) -> bool {
|
pub fn has_own_foo_property(obj: &js::Object, property: &JsValue) -> bool {
|
||||||
obj.has_own_property(&property)
|
obj.has_own_property(&property)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -55,14 +66,17 @@ fn has_own_property() {
|
|||||||
const s = Symbol();
|
const s = Symbol();
|
||||||
assert(wasm.has_own_foo_property({ [s]: "foo" }, s));
|
assert(wasm.has_own_foo_property({ [s]: "foo" }, s));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_string() {
|
fn to_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -79,8 +93,11 @@ fn to_string() {
|
|||||||
let object = js::Object::new();
|
let object = js::Object::new();
|
||||||
assert_eq!(String::from(object.to_string()), "[object Object]");
|
assert_eq!(String::from(object.to_string()), "[object Object]");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -88,14 +105,17 @@ fn to_string() {
|
|||||||
assert.equal(wasm.to_string({ foo: 42 }), "[object Object]");
|
assert.equal(wasm.to_string({ foo: 42 }), "[object Object]");
|
||||||
wasm.test();
|
wasm.test();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_prototype_of() {
|
fn is_prototype_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -106,8 +126,11 @@ fn is_prototype_of() {
|
|||||||
pub fn obj_is_prototype_of_value(obj: &js::Object, value: &JsValue) -> bool {
|
pub fn obj_is_prototype_of_value(obj: &js::Object, value: &JsValue) -> bool {
|
||||||
obj.is_prototype_of(&value)
|
obj.is_prototype_of(&value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -119,14 +142,17 @@ fn is_prototype_of() {
|
|||||||
assert(wasm.obj_is_prototype_of_value(Foo.prototype, foo));
|
assert(wasm.obj_is_prototype_of_value(Foo.prototype, foo));
|
||||||
assert(!wasm.obj_is_prototype_of_value(Bar.prototype, foo));
|
assert(!wasm.obj_is_prototype_of_value(Bar.prototype, foo));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn keys() {
|
fn keys() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -137,8 +163,11 @@ fn keys() {
|
|||||||
pub fn keys(obj: &js::Object) -> js::Array {
|
pub fn keys(obj: &js::Object) -> js::Array {
|
||||||
js::Object::keys(obj)
|
js::Object::keys(obj)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -146,14 +175,17 @@ fn keys() {
|
|||||||
const obj = { a: 1, b: 2, c: 3 };
|
const obj = { a: 1, b: 2, c: 3 };
|
||||||
assert.deepStrictEqual(wasm.keys(obj), ["a", "b", "c"]);
|
assert.deepStrictEqual(wasm.keys(obj), ["a", "b", "c"]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn property_is_enumerable() {
|
fn property_is_enumerable() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -164,8 +196,11 @@ fn property_is_enumerable() {
|
|||||||
pub fn property_is_enumerable(obj: &js::Object, property: &JsValue) -> bool {
|
pub fn property_is_enumerable(obj: &js::Object, property: &JsValue) -> bool {
|
||||||
obj.property_is_enumerable(&property)
|
obj.property_is_enumerable(&property)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -181,7 +216,8 @@ fn property_is_enumerable() {
|
|||||||
const s = Symbol();
|
const s = Symbol();
|
||||||
assert.ok(wasm.property_is_enumerable({ [s]: true }, s));
|
assert.ok(wasm.property_is_enumerable({ [s]: true }, s));
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +275,9 @@ fn seal() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn to_locale_string() {
|
fn to_locale_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -251,22 +289,28 @@ fn to_locale_string() {
|
|||||||
let object = js::Object::new();
|
let object = js::Object::new();
|
||||||
object.to_locale_string()
|
object.to_locale_string()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.to_locale_string(), "[object Object]");
|
assert.equal(wasm.to_locale_string(), "[object Object]");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn value_of() {
|
fn value_of() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -277,8 +321,11 @@ fn value_of() {
|
|||||||
pub fn value_of(obj: &js::Object) -> js::Object {
|
pub fn value_of(obj: &js::Object) -> js::Object {
|
||||||
obj.value_of()
|
obj.value_of()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -287,6 +334,7 @@ fn value_of() {
|
|||||||
assert.strictEqual(wasm.value_of(obj), obj);
|
assert.strictEqual(wasm.value_of(obj), obj);
|
||||||
assert.notStrictEqual(wasm.value_of(obj), { foo: 42 });
|
assert.notStrictEqual(wasm.value_of(obj), { foo: 42 });
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new_undefined() {
|
fn new_undefined() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,22 +18,28 @@ fn new_undefined() {
|
|||||||
pub fn new_array() -> js::Uint8Array {
|
pub fn new_array() -> js::Uint8Array {
|
||||||
js::Uint8Array::new(JsValue::undefined())
|
js::Uint8Array::new(JsValue::undefined())
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.new_array().length, 0);
|
assert.equal(wasm.new_array().length, 0);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_length() {
|
fn new_length() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,15 +50,19 @@ fn new_length() {
|
|||||||
pub fn new_array() -> js::Uint8Array {
|
pub fn new_array() -> js::Uint8Array {
|
||||||
js::Uint8Array::new(JsValue::from_f64(4.0))
|
js::Uint8Array::new(JsValue::from_f64(4.0))
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(wasm.new_array().length, 4);
|
assert.equal(wasm.new_array().length, 4);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new() {
|
fn new() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,23 +18,28 @@ fn new() {
|
|||||||
pub fn new_weak_map() -> js::WeakMap {
|
pub fn new_weak_map() -> js::WeakMap {
|
||||||
js::WeakMap::new()
|
js::WeakMap::new()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(typeof wasm.new_weak_map(), "object");
|
assert.equal(typeof wasm.new_weak_map(), "object");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get() {
|
fn get() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -43,8 +50,11 @@ fn get() {
|
|||||||
pub fn get_value(this: &js::WeakMap, key: js::Object) -> JsValue {
|
pub fn get_value(this: &js::WeakMap, key: js::Object) -> JsValue {
|
||||||
this.get(key)
|
this.get(key)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -57,14 +67,17 @@ fn get() {
|
|||||||
let undef = "unexisting_key";
|
let undef = "unexisting_key";
|
||||||
assert.equal(typeof wasm.get_value(map, undef), "undefined");
|
assert.equal(typeof wasm.get_value(map, undef), "undefined");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set() {
|
fn set() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -75,8 +88,11 @@ fn set() {
|
|||||||
pub fn set_value(this: &js::WeakMap, key: js::Object, value: JsValue) -> js::WeakMap {
|
pub fn set_value(this: &js::WeakMap, key: js::Object, value: JsValue) -> js::WeakMap {
|
||||||
this.set(key, value)
|
this.set(key, value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -86,14 +102,17 @@ fn set() {
|
|||||||
wasm.set_value(map, key, "value");
|
wasm.set_value(map, key, "value");
|
||||||
assert.equal(map.get(key), "value");
|
assert.equal(map.get(key), "value");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn has() {
|
fn has() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -104,8 +123,11 @@ fn has() {
|
|||||||
pub fn has_value(this: &js::WeakMap, key: js::Object) -> bool {
|
pub fn has_value(this: &js::WeakMap, key: js::Object) -> bool {
|
||||||
this.has(key)
|
this.has(key)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -118,14 +140,17 @@ fn has() {
|
|||||||
let undef = "unexisting_key";
|
let undef = "unexisting_key";
|
||||||
assert.equal(wasm.has_value(map, undef), false);
|
assert.equal(wasm.has_value(map, undef), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete() {
|
fn delete() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -136,8 +161,11 @@ fn delete() {
|
|||||||
pub fn delete_key(this: &js::WeakMap, key: js::Object) -> bool {
|
pub fn delete_key(this: &js::WeakMap, key: js::Object) -> bool {
|
||||||
this.delete(key)
|
this.delete(key)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -149,6 +177,7 @@ fn delete() {
|
|||||||
assert.equal(map.has(key), false);
|
assert.equal(map.has(key), false);
|
||||||
assert.equal(wasm.delete_key(map, key), false);
|
assert.equal(wasm.delete_key(map, key), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@ use project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn new() {
|
fn new() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -16,22 +18,28 @@ fn new() {
|
|||||||
pub fn new_weak_set() -> js::WeakSet {
|
pub fn new_weak_set() -> js::WeakSet {
|
||||||
js::WeakSet::new()
|
js::WeakSet::new()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.equal(typeof wasm.new_weak_set(), "object");
|
assert.equal(typeof wasm.new_weak_set(), "object");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn has() {
|
fn has() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,8 +50,11 @@ fn has() {
|
|||||||
pub fn has_value(this: &js::WeakSet, value: js::Object) -> bool {
|
pub fn has_value(this: &js::WeakSet, value: js::Object) -> bool {
|
||||||
this.has(value)
|
this.has(value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -56,14 +67,17 @@ fn has() {
|
|||||||
let nonex = {nonexistent: "value"};
|
let nonex = {nonexistent: "value"};
|
||||||
assert.equal(wasm.has_value(set, nonex), false);
|
assert.equal(wasm.has_value(set, nonex), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add() {
|
fn add() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -74,8 +88,11 @@ fn add() {
|
|||||||
pub fn add_value(this: &js::WeakSet, value: js::Object) -> js::WeakSet {
|
pub fn add_value(this: &js::WeakSet, value: js::Object) -> js::WeakSet {
|
||||||
this.add(value)
|
this.add(value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -91,14 +108,17 @@ fn add() {
|
|||||||
assert.throws(() => { wasm.add_value(set, null) }, TypeError);
|
assert.throws(() => { wasm.add_value(set, null) }, TypeError);
|
||||||
assert.throws(() => { wasm.add_value(set, undefined) }, TypeError);
|
assert.throws(() => { wasm.add_value(set, undefined) }, TypeError);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete() {
|
fn delete() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -109,8 +129,11 @@ fn delete() {
|
|||||||
pub fn delete_value(this: &js::WeakSet, value: js::Object) -> bool {
|
pub fn delete_value(this: &js::WeakSet, value: js::Object) -> bool {
|
||||||
this.delete(value)
|
this.delete(value)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -128,6 +151,7 @@ fn delete() {
|
|||||||
assert.equal(wasm.delete_value(set, null), false);
|
assert.equal(wasm.delete_value(set, null), false);
|
||||||
assert.equal(wasm.delete_value(set, undefined), false);
|
assert.equal(wasm.delete_value(set, undefined), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,21 @@ mod Date;
|
|||||||
mod Function;
|
mod Function;
|
||||||
mod JsString;
|
mod JsString;
|
||||||
mod Math;
|
mod Math;
|
||||||
mod WeakMap;
|
|
||||||
mod WeakSet;
|
|
||||||
mod Number;
|
mod Number;
|
||||||
mod Object;
|
mod Object;
|
||||||
mod Set;
|
mod Set;
|
||||||
mod SetIterator;
|
mod SetIterator;
|
||||||
mod TypedArray;
|
mod TypedArray;
|
||||||
|
mod WeakMap;
|
||||||
|
mod WeakSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn decode_uri() {
|
fn decode_uri() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -37,7 +39,8 @@ fn decode_uri() {
|
|||||||
|
|
||||||
assert!(js::decode_uri("%E0%A4%A").is_err());
|
assert!(js::decode_uri("%E0%A4%A").is_err());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +48,9 @@ fn decode_uri() {
|
|||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn encode_uri() {
|
fn encode_uri() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -57,14 +62,17 @@ fn encode_uri() {
|
|||||||
let x = js::encode_uri("ABC abc 123");
|
let x = js::encode_uri("ABC abc 123");
|
||||||
assert_eq!(String::from(x), "ABC%20abc%20123");
|
assert_eq!(String::from(x), "ABC%20abc%20123");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn eval() {
|
fn eval() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -81,6 +89,7 @@ fn eval() {
|
|||||||
.expect("eval should throw");
|
.expect("eval should throw");
|
||||||
assert_eq!(err.as_f64().unwrap(), 42.0);
|
assert_eq!(err.as_f64().unwrap(), 42.0);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn simple() {
|
fn simple() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -19,8 +21,11 @@ fn simple() {
|
|||||||
pub fn bar(s: &JsValue) {
|
pub fn bar(s: &JsValue) {
|
||||||
foo(s);
|
foo(s);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -37,14 +42,17 @@ fn simple() {
|
|||||||
wasm.bar(sym);
|
wasm.bar(sym);
|
||||||
assert.strictEqual(ARG, sym);
|
assert.strictEqual(ARG, sym);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn owned() {
|
fn owned() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -60,8 +68,11 @@ fn owned() {
|
|||||||
pub fn bar(s: JsValue) {
|
pub fn bar(s: JsValue) {
|
||||||
foo(s);
|
foo(s);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -78,14 +89,17 @@ fn owned() {
|
|||||||
wasm.bar(sym);
|
wasm.bar(sym);
|
||||||
assert.strictEqual(ARG, sym);
|
assert.strictEqual(ARG, sym);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn clone() {
|
fn clone() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -109,8 +123,11 @@ fn clone() {
|
|||||||
foo4(&s);
|
foo4(&s);
|
||||||
foo5(s);
|
foo5(s);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -125,14 +142,17 @@ fn clone() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
wasm.bar(ARG);
|
wasm.bar(ARG);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn promote() {
|
fn promote() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -154,8 +174,11 @@ fn promote() {
|
|||||||
foo3(s);
|
foo3(s);
|
||||||
foo4(s.clone());
|
foo4(s.clone());
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -169,14 +192,17 @@ fn promote() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
wasm.bar(ARG);
|
wasm.bar(ARG);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn returning_vector() {
|
fn returning_vector() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -196,8 +222,11 @@ fn returning_vector() {
|
|||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -207,14 +236,17 @@ fn returning_vector() {
|
|||||||
const result = wasm.bar();
|
const result = wasm.bar();
|
||||||
assert.strictEqual(result.length, 10);
|
assert.strictEqual(result.length, 10);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn another_vector_return() {
|
fn another_vector_return() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -233,15 +265,19 @@ fn another_vector_return() {
|
|||||||
JsValue::from(6),
|
JsValue::from(6),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { get_array } from "./out";
|
import { get_array } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
assert.deepStrictEqual(get_array(), [1, 2, 3, 4, 5, 6]);
|
assert.deepStrictEqual(get_array(), [1, 2, 3, 4, 5, 6]);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +287,9 @@ fn serde() {
|
|||||||
.serde(true)
|
.serde(true)
|
||||||
.depend("serde = '1.0'")
|
.depend("serde = '1.0'")
|
||||||
.depend("serde_derive = '1.0'")
|
.depend("serde_derive = '1.0'")
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -303,8 +341,11 @@ fn serde() {
|
|||||||
let s = j.into_serde::<String>().unwrap();
|
let s = j.into_serde::<String>().unwrap();
|
||||||
assert_eq!(s, "bar");
|
assert_eq!(s, "bar");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { run, parse } from "./out";
|
import { run, parse } from "./out";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -328,6 +369,7 @@ fn serde() {
|
|||||||
run();
|
run();
|
||||||
parse('bar');
|
parse('bar');
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -411,15 +411,19 @@ impl Project {
|
|||||||
|
|
||||||
self.gen_bindings(&root, &target_dir);
|
self.gen_bindings(&root, &target_dir);
|
||||||
let mut wasm = Vec::new();
|
let mut wasm = Vec::new();
|
||||||
File::open(root.join("out_bg.wasm")).unwrap()
|
File::open(root.join("out_bg.wasm"))
|
||||||
.read_to_end(&mut wasm).unwrap();
|
.unwrap()
|
||||||
|
.read_to_end(&mut wasm)
|
||||||
|
.unwrap();
|
||||||
let obj = cli::wasm2es6js::Config::new()
|
let obj = cli::wasm2es6js::Config::new()
|
||||||
.base64(true)
|
.base64(true)
|
||||||
.generate(&wasm)
|
.generate(&wasm)
|
||||||
.expect("failed to convert wasm to js");
|
.expect("failed to convert wasm to js");
|
||||||
|
|
||||||
File::create(root.join("out_bg.d.ts")).unwrap()
|
File::create(root.join("out_bg.d.ts"))
|
||||||
.write_all(obj.typescript().as_bytes()).unwrap();
|
.unwrap()
|
||||||
|
.write_all(obj.typescript().as_bytes())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// move files from the root into each test, it looks like this may be
|
// move files from the root into each test, it looks like this may be
|
||||||
// needed for webpack to work well when invoked concurrently.
|
// needed for webpack to work well when invoked concurrently.
|
||||||
@ -473,7 +477,6 @@ impl Project {
|
|||||||
}
|
}
|
||||||
panic!("failed");
|
panic!("failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
fn read_js(&self) -> String {
|
fn read_js(&self) -> String {
|
||||||
let path = root().join("out.js");
|
let path = root().join("out.js");
|
||||||
@ -522,12 +525,14 @@ mod api;
|
|||||||
mod char;
|
mod char;
|
||||||
mod classes;
|
mod classes;
|
||||||
mod closures;
|
mod closures;
|
||||||
|
mod comments;
|
||||||
mod dependencies;
|
mod dependencies;
|
||||||
mod enums;
|
mod enums;
|
||||||
mod import_class;
|
mod import_class;
|
||||||
mod imports;
|
mod imports;
|
||||||
|
#[cfg(feature = "js_globals")]
|
||||||
|
mod js_globals;
|
||||||
mod jsobjects;
|
mod jsobjects;
|
||||||
#[cfg(feature = "js_globals")] mod js_globals;
|
|
||||||
mod math;
|
mod math;
|
||||||
mod node;
|
mod node;
|
||||||
mod non_debug;
|
mod non_debug;
|
||||||
@ -536,6 +541,5 @@ mod simple;
|
|||||||
mod slice;
|
mod slice;
|
||||||
mod structural;
|
mod structural;
|
||||||
mod u64;
|
mod u64;
|
||||||
mod webidl;
|
|
||||||
mod comments;
|
|
||||||
mod validate_prt;
|
mod validate_prt;
|
||||||
|
mod webidl;
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn auto_bind_math() {
|
fn auto_bind_math() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -64,14 +66,17 @@ fn auto_bind_math() {
|
|||||||
(a % (b as f32))) as f64) +
|
(a % (b as f32))) as f64) +
|
||||||
(b + 2.0f64.powf(a as f64))
|
(b + 2.0f64.powf(a as f64))
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import { math } from "./out";
|
import { math } from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
math(1.0, 2.0);
|
math(1.0, 2.0);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ use super::project;
|
|||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.node(true)
|
.node(true)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -111,8 +113,11 @@ fn works() {
|
|||||||
(a % (b as f32))) as f64) +
|
(a % (b as f32))) as f64) +
|
||||||
(b + 2.0f64.powf(a as f64))
|
(b + 2.0f64.powf(a as f64))
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
var called = false;
|
var called = false;
|
||||||
@ -149,6 +154,7 @@ fn works() {
|
|||||||
math(1.0, 2.0);
|
math(1.0, 2.0);
|
||||||
};
|
};
|
||||||
|
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ use super::project;
|
|||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.debug(false)
|
.debug(false)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -26,8 +28,11 @@ fn works() {
|
|||||||
drop(a.clone());
|
drop(a.clone());
|
||||||
a.clone()
|
a.clone()
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -37,6 +42,7 @@ fn works() {
|
|||||||
let a = wasm.A.new();
|
let a = wasm.A.new();
|
||||||
a.free();
|
a.free();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
|
use super::{project, run};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use super::{run, project};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
let mut p = project();
|
let mut p = project();
|
||||||
let name = p.crate_name();
|
let name = p.crate_name();
|
||||||
p
|
p.rlib(true)
|
||||||
.rlib(true)
|
.file(
|
||||||
.file("src/lib.rs", r#"
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -54,8 +55,12 @@ fn works() {
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn baz(_: JsValue) {
|
pub fn baz(_: JsValue) {
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("tests/foo.rs", &format!("
|
)
|
||||||
|
.file(
|
||||||
|
"tests/foo.rs",
|
||||||
|
&format!(
|
||||||
|
"
|
||||||
extern crate {} as mytest;
|
extern crate {} as mytest;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -63,8 +68,14 @@ fn works() {
|
|||||||
mytest::foo(false);
|
mytest::foo(false);
|
||||||
mytest::A::new().foo();
|
mytest::A::new().foo();
|
||||||
}}
|
}}
|
||||||
", name))
|
",
|
||||||
.file("benches/foo.rs", &format!("
|
name
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"benches/foo.rs",
|
||||||
|
&format!(
|
||||||
|
"
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
extern crate test;
|
extern crate test;
|
||||||
extern crate {} as mytest;
|
extern crate {} as mytest;
|
||||||
@ -73,14 +84,18 @@ fn works() {
|
|||||||
fn foo(b: &mut test::Bencher) {{
|
fn foo(b: &mut test::Bencher) {{
|
||||||
b.iter(|| mytest::foo(false));
|
b.iter(|| mytest::foo(false));
|
||||||
}}
|
}}
|
||||||
", name));
|
",
|
||||||
|
name
|
||||||
|
),
|
||||||
|
);
|
||||||
let (root, target_dir) = p.build();
|
let (root, target_dir) = p.build();
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = Command::new("cargo");
|
||||||
cmd.arg("test")
|
cmd.arg("test")
|
||||||
.arg("--test").arg("foo")
|
.arg("--test")
|
||||||
.arg("--bench").arg("foo")
|
.arg("foo")
|
||||||
|
.arg("--bench")
|
||||||
|
.arg("foo")
|
||||||
.current_dir(&root)
|
.current_dir(&root)
|
||||||
.env("CARGO_TARGET_DIR", &target_dir);
|
.env("CARGO_TARGET_DIR", &target_dir);
|
||||||
run(&mut cmd, "cargo");
|
run(&mut cmd, "cargo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn add() {
|
fn add() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -37,8 +39,11 @@ fn add() {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -49,14 +54,17 @@ fn add() {
|
|||||||
assert.strictEqual(wasm.get2(true), 2);
|
assert.strictEqual(wasm.get2(true), 2);
|
||||||
assert.strictEqual(wasm.return_and_take_bool(true, false), false);
|
assert.strictEqual(wasm.return_and_take_bool(true, false), false);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn string_arguments() {
|
fn string_arguments() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -73,22 +81,28 @@ fn string_arguments() {
|
|||||||
pub fn assert_foo(a: &str) {
|
pub fn assert_foo(a: &str) {
|
||||||
assert_eq!(a, "foo");
|
assert_eq!(a, "foo");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
wasm.assert_foo("foo");
|
wasm.assert_foo("foo");
|
||||||
wasm.assert_foo_and_bar("foo2", "bar");
|
wasm.assert_foo_and_bar("foo2", "bar");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn return_a_string() {
|
fn return_a_string() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -104,8 +118,11 @@ fn return_a_string() {
|
|||||||
pub fn concat(a: &str, b: &str, c: i8) -> String {
|
pub fn concat(a: &str, b: &str, c: i8) -> String {
|
||||||
format!("{} {} {}", a, b, c)
|
format!("{} {} {}", a, b, c)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -115,14 +132,17 @@ fn return_a_string() {
|
|||||||
assert.strictEqual(wasm.concat("a", "b", 3), "a b 3");
|
assert.strictEqual(wasm.concat("a", "b", 3), "a b 3");
|
||||||
assert.strictEqual(wasm.concat("c", "d", -2), "c d -2");
|
assert.strictEqual(wasm.concat("c", "d", -2), "c d -2");
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exceptions() {
|
fn exceptions() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -134,8 +154,11 @@ fn exceptions() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn bar(_a: &str) {}
|
pub fn bar(_a: &str) {}
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -143,10 +166,14 @@ fn exceptions() {
|
|||||||
assert.throws(() => wasm.foo('a'), /expected a number argument/);
|
assert.throws(() => wasm.foo('a'), /expected a number argument/);
|
||||||
assert.throws(() => wasm.bar(3), /expected a string argument/);
|
assert.throws(() => wasm.bar(3), /expected a string argument/);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.d.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.d.ts",
|
||||||
|
r#"
|
||||||
export function test(): void;
|
export function test(): void;
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,18 +214,24 @@ fn exceptions() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn other_exports() {
|
fn other_exports() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn foo(_a: u32) {
|
pub extern fn foo(_a: u32) {
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out_bg";
|
import * as wasm from "./out_bg";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
wasm.foo(2);
|
wasm.foo(2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +239,9 @@ fn other_exports() {
|
|||||||
fn no_std() {
|
fn no_std() {
|
||||||
project()
|
project()
|
||||||
.no_std(true)
|
.no_std(true)
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
@ -229,28 +264,37 @@ fn no_std() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn foo(_a: u32) {}
|
pub fn foo(_a: u32) {}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out_bg";
|
import * as wasm from "./out_bg";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
// mostly just testing the project compiles here
|
// mostly just testing the project compiles here
|
||||||
wasm.foo(1);
|
wasm.foo(1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("foo.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"foo.js",
|
||||||
|
r#"
|
||||||
export class Js {
|
export class Js {
|
||||||
init() {
|
init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_std_class() {
|
fn no_std_class() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
@ -282,14 +326,18 @@ fn no_std_class() {
|
|||||||
pub fn foo(&self) {}
|
pub fn foo(&self) {}
|
||||||
pub fn bar(&mut self) {}
|
pub fn bar(&mut self) {}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as wasm from "./out_bg";
|
import * as wasm from "./out_bg";
|
||||||
|
|
||||||
export function test() {
|
export function test() {
|
||||||
// mostly just testing the project compiles here
|
// mostly just testing the project compiles here
|
||||||
wasm.foo(1);
|
wasm.foo(1);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn export() {
|
fn export() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -24,8 +26,11 @@ fn export() {
|
|||||||
|
|
||||||
|
|
||||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -76,14 +81,17 @@ fn export() {
|
|||||||
f64[1] = 2;
|
f64[1] = 2;
|
||||||
assert_arrays_equal(wasm.f64(f64), f64);
|
assert_arrays_equal(wasm.f64(f64), f64);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn import() {
|
fn import() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -118,8 +126,11 @@ fn import() {
|
|||||||
(rust_f32, js_f32, f32)
|
(rust_f32, js_f32, f32)
|
||||||
(rust_f64, js_f64, f64)
|
(rust_f64, js_f64, f64)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -225,14 +236,17 @@ fn import() {
|
|||||||
f64[1] = 2;
|
f64[1] = 2;
|
||||||
assert_arrays_equal(wasm.rust_f64(f64), f64);
|
assert_arrays_equal(wasm.rust_f64(f64), f64);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pass_array_works() {
|
fn pass_array_works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -261,8 +275,11 @@ fn pass_array_works() {
|
|||||||
(rust_f32, f32)
|
(rust_f32, f32)
|
||||||
(rust_f64, f64)
|
(rust_f64, f64)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
const wasm = require("./out");
|
const wasm = require("./out");
|
||||||
|
|
||||||
module.exports.test = function() {
|
module.exports.test = function() {
|
||||||
@ -275,14 +292,17 @@ fn pass_array_works() {
|
|||||||
wasm.rust_f32([1, 2]);
|
wasm.rust_f32([1, 2]);
|
||||||
wasm.rust_f64([1, 2]);
|
wasm.rust_f64([1, 2]);
|
||||||
};
|
};
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn import_mut() {
|
fn import_mut() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -328,8 +348,11 @@ fn import_mut() {
|
|||||||
(rust_f32, js_f32, f32)
|
(rust_f32, js_f32, f32)
|
||||||
(rust_f64, js_f64, f64)
|
(rust_f64, js_f64, f64)
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -353,14 +376,17 @@ fn import_mut() {
|
|||||||
export function test() {
|
export function test() {
|
||||||
wasm.run();
|
wasm.run();
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn export_mut() {
|
fn export_mut() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section)]
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -383,8 +409,11 @@ fn export_mut() {
|
|||||||
|
|
||||||
|
|
||||||
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
doit! { i8 u8 i16 u16 i32 u32 f32 f64 }
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -412,14 +441,17 @@ fn export_mut() {
|
|||||||
run(new Float32Array(3), wasm.f32);
|
run(new Float32Array(3), wasm.f32);
|
||||||
run(new Float64Array(3), wasm.f64);
|
run(new Float64Array(3), wasm.f64);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn return_vec_ok() {
|
fn return_vec_ok() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
@ -461,8 +493,11 @@ fn return_vec_ok() {
|
|||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import * as wasm from "./out";
|
import * as wasm from "./out";
|
||||||
|
|
||||||
@ -485,7 +520,7 @@ fn return_vec_ok() {
|
|||||||
assert.strictEqual(bad[8], 9);
|
assert.strictEqual(bad[8], 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
|
|
||||||
@ -28,8 +30,11 @@ fn works() {
|
|||||||
a.set_baz(2);
|
a.set_baz(2);
|
||||||
assert_eq!(a.baz(), 2);
|
assert_eq!(a.baz(), 2);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
.file("test.ts", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
import { run } from "./out";
|
import { run } from "./out";
|
||||||
|
|
||||||
@ -41,8 +46,7 @@ fn works() {
|
|||||||
});
|
});
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ use super::project;
|
|||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.requires_bigint()
|
.requires_bigint()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
|
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
@ -42,8 +44,11 @@ fn works() {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn u64_slice(a: &[u64]) -> Vec<u64> { a.to_vec() }
|
pub fn u64_slice(a: &[u64]) -> Vec<u64> { a.to_vec() }
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
import * as wasm from './out';
|
import * as wasm from './out';
|
||||||
|
|
||||||
function assertEq(a, b) {
|
function assertEq(a, b) {
|
||||||
@ -95,6 +100,7 @@ fn works() {
|
|||||||
|
|
||||||
export function js_i64_round(a) { return a; }
|
export function js_i64_round(a) { return a; }
|
||||||
export function js_u64_round(a) { return a; }
|
export function js_u64_round(a) { return a; }
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ use super::project;
|
|||||||
#[test]
|
#[test]
|
||||||
fn works() {
|
fn works() {
|
||||||
project()
|
project()
|
||||||
.file("src/lib.rs", r#"
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
@ -26,8 +28,11 @@ fn works() {
|
|||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn eat(_fruit: Fruit) { }
|
pub fn eat(_fruit: Fruit) { }
|
||||||
"#)
|
"#,
|
||||||
.file("test.js", r#"
|
)
|
||||||
|
.file(
|
||||||
|
"test.js",
|
||||||
|
r#"
|
||||||
import * as wasm from './out';
|
import * as wasm from './out';
|
||||||
const targetMessage = 'Attempt to use a moved value';
|
const targetMessage = 'Attempt to use a moved value';
|
||||||
function assertEq(a, b) {
|
function assertEq(a, b) {
|
||||||
@ -64,6 +69,7 @@ fn works() {
|
|||||||
assertEq(e.message, targetMessage);
|
assertEq(e.message, targetMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#)
|
"#,
|
||||||
|
)
|
||||||
.test();
|
.test();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user