mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
add binding for includes
This commit is contained in:
parent
eb6c2a239c
commit
a8cd428850
@ -177,4 +177,11 @@ extern {
|
|||||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
||||||
#[wasm_bindgen(method, js_name = toString)]
|
#[wasm_bindgen(method, js_name = toString)]
|
||||||
pub fn to_string(this: &Array) -> String;
|
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;
|
||||||
|
|
||||||
}
|
}
|
@ -386,3 +386,39 @@ fn to_string() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.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()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user