mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add binding for pop
This commit is contained in:
parent
2f6f734216
commit
73081180cd
@ -139,4 +139,10 @@ extern {
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin
|
||||
#[wasm_bindgen(method, js_name = copyWithin)]
|
||||
pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
|
||||
|
||||
/// The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn pop(this: &Array) -> JsValue;
|
||||
}
|
@ -203,3 +203,33 @@ fn copy_within() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pop() {
|
||||
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 pop_in_it(this: &js::Array) -> JsValue {
|
||||
this.pop()
|
||||
}
|
||||
|
||||
"#)
|
||||
.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 item = wasm.pop_in_it(characters);
|
||||
assert.equal(item, 2);
|
||||
assert.equal(characters.length, 5);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user