mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add binding for reverse
This commit is contained in:
parent
4611d7bdba
commit
d705cd8bbf
@ -151,4 +151,11 @@ extern {
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn push(this: &Array, value: JsValue) -> u32;
|
||||
|
||||
/// The reverse() method reverses an array in place.
|
||||
/// The first array element becomes the last, and the last array element becomes the first.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn reverse(this: &Array) -> Array;
|
||||
}
|
@ -263,4 +263,34 @@ fn push() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reverse() {
|
||||
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 reverse_array(this: &js::Array) -> js::Array {
|
||||
this.reverse()
|
||||
}
|
||||
|
||||
"#)
|
||||
.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 reversed = wasm.reverse_array(characters);
|
||||
assert.equal(reversed[0], 2);
|
||||
assert.equal(reversed[5], 8);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user