Add binding for concat

This commit is contained in:
Jonathan Sundqvist 2018-06-22 18:25:19 +02:00 committed by Nick Fitzgerald
parent 7825122feb
commit 99ee74d153
2 changed files with 37 additions and 0 deletions

View File

@ -79,6 +79,13 @@ extern {
#[wasm_bindgen(method, js_name = copyWithin)] #[wasm_bindgen(method, js_name = copyWithin)]
pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array; pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
///The concat() method is used to merge two or more arrays. This method
/// does not change the existing arrays, but instead returns a new array.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
#[wasm_bindgen(method)]
pub fn concat(this: &Array, array: &Array) -> Array;
/// The fill() method fills all the elements of an array from a start index to an /// The fill() method fills all the elements of an array from a start index to an
/// end index with a static value. The end index is not included. /// end index with a static value. The end index is not included.
/// ///

30
tests/all/js_globals/Array.rs Normal file → Executable file
View File

@ -453,6 +453,36 @@ fn includes() {
.test() .test()
} }
#[test]
fn concat() {
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_concat(this: &js::Array, arr: &js::Array) -> js::Array {
this.concat(arr)
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
let new_array = wasm.array_concat(arr1, arr2)
assert.deepStrictEqual(new_array, [1, 2, 3, 4, 5, 6]);
}
"#)
.test()
}
#[test] #[test]
fn length() { fn length() {