diff --git a/src/js.rs b/src/js.rs index 52168b70..8c9e9deb 100644 --- a/src/js.rs +++ b/src/js.rs @@ -177,4 +177,11 @@ extern { /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString #[wasm_bindgen(method, js_name = toString)] pub fn to_string(this: &Array) -> String; + + /// The includes() method determines whether an array includes a certain element, returning true or false as appropriate. + /// + /// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes + #[wasm_bindgen(method)] + pub fn includes(this: &Array, value: JsValue, from_index: i32) -> bool; + } \ No newline at end of file diff --git a/tests/all/js_globals/Array.rs b/tests/all/js_globals/Array.rs index 44aa4ca4..ae6f893e 100644 --- a/tests/all/js_globals/Array.rs +++ b/tests/all/js_globals/Array.rs @@ -386,3 +386,39 @@ fn to_string() { "#) .test() } + + +#[test] +fn includes() { + 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_includes(this: &js::Array, value: JsValue, from_index: i32) -> bool { + this.includes(value, from_index) + } + + "#) + .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 isTwoIncluded = wasm.array_includes(characters, 2, 0); + let isNineIncluded = wasm.array_includes(characters, 9, 0); + + assert.ok(isTwoIncluded); + assert.ok(!isNineIncluded); + + let isThreeIncluded = wasm.array_includes(characters, 3, 4); + assert.ok(!isThreeIncluded); + } + "#) + .test() +}