diff --git a/src/js.rs b/src/js.rs index 0e1ed628..56a4dd2c 100644 --- a/src/js.rs +++ b/src/js.rs @@ -79,6 +79,13 @@ extern { #[wasm_bindgen(method, js_name = copyWithin)] 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 /// end index with a static value. The end index is not included. /// diff --git a/tests/all/js_globals/Array.rs b/tests/all/js_globals/Array.rs old mode 100644 new mode 100755 index 71d11d61..8d2a0f1e --- a/tests/all/js_globals/Array.rs +++ b/tests/all/js_globals/Array.rs @@ -453,6 +453,36 @@ fn includes() { .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] fn length() {