mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add bindings for unshift
This commit is contained in:
parent
68acbeab25
commit
3cf522d2df
@ -165,4 +165,10 @@ extern {
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn shift(this: &Array) -> JsValue;
|
||||
|
||||
/// The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
|
||||
///
|
||||
/// 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;
|
||||
}
|
@ -324,4 +324,35 @@ fn shift() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unshift() {
|
||||
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 unshift_item(this: &js::Array, value: JsValue) -> u32 {
|
||||
this.unshift(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.unshift_item(characters, "abba");
|
||||
|
||||
assert.equal(length, 7);
|
||||
assert.equal(characters[0], "abba");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user