mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-22 20:52:13 +00:00
add binding for push
This commit is contained in:
parent
73081180cd
commit
4611d7bdba
@ -145,4 +145,10 @@ extern {
|
|||||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
|
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn pop(this: &Array) -> JsValue;
|
pub fn pop(this: &Array) -> JsValue;
|
||||||
|
|
||||||
|
/// The push() method adds one or more elements to the end of an array and returns the new length of the array.
|
||||||
|
///
|
||||||
|
/// 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;
|
||||||
}
|
}
|
@ -233,3 +233,34 @@ fn pop() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn push() {
|
||||||
|
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 push_it_along(this: &js::Array, value: JsValue) -> u32 {
|
||||||
|
this.push(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
"#)
|
||||||
|
.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 length = wasm.push_it_along(characters, "a");
|
||||||
|
assert.equal(length, 7);
|
||||||
|
assert.equal(characters[6], "a");
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user