mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add binding for toString
This commit is contained in:
parent
3cf522d2df
commit
eb6c2a239c
@ -171,4 +171,10 @@ extern {
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn unshift(this: &Array, value: JsValue) -> u32;
|
||||
|
||||
/// The toString() method returns a string representing the specified array and its elements.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
||||
#[wasm_bindgen(method, js_name = toString)]
|
||||
pub fn to_string(this: &Array) -> String;
|
||||
}
|
@ -355,4 +355,34 @@ fn unshift() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_string() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn array_to_string(this: &js::Array) -> String {
|
||||
this.to_string()
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let characters = [8, 5, 4, 3, 1, 2]
|
||||
let arrayString = wasm.array_to_string(characters);
|
||||
|
||||
assert.equal(arrayString, "8,5,4,3,1,2");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user