mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-24 18:43:33 +03:00
Add binding for concat
This commit is contained in:
parent
7825122feb
commit
99ee74d153
@ -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.
|
||||
///
|
||||
|
30
tests/all/js_globals/Array.rs
Normal file → Executable file
30
tests/all/js_globals/Array.rs
Normal file → Executable file
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user