mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 17:51:33 +00:00
add binding for toString
This commit is contained in:
@ -171,4 +171,10 @@ extern {
|
|||||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
|
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn unshift(this: &Array, value: JsValue) -> u32;
|
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;
|
||||||
}
|
}
|
@ -356,3 +356,33 @@ fn unshift() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.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()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user