File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,13 @@ extern {
205
205
#[ wasm_bindgen( method) ]
206
206
pub fn slice ( this : & Array , start : u32 , end : u32 ) -> Array ;
207
207
208
+ /// The some() method tests whether at least one element in the array passes the test implemented
209
+ /// by the provided function.
210
+ /// Note: This method returns false for any condition put on an empty array.
211
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
212
+ #[ wasm_bindgen( method) ]
213
+ pub fn some ( this : & Array , predicate : & mut FnMut ( JsValue ) -> bool ) -> bool ;
214
+
208
215
/// The sort() method sorts the elements of an array in place and returns
209
216
/// the array. The sort is not necessarily stable. The default sort
210
217
/// order is according to string Unicode code points.
Original file line number Diff line number Diff line change @@ -143,6 +143,37 @@ fn sort() {
143
143
. test ( )
144
144
}
145
145
146
+ #[ test]
147
+ fn some ( ) {
148
+ project ( )
149
+ . file ( "src/lib.rs" , r#"
150
+ #![feature(proc_macro, wasm_custom_section)]
151
+
152
+ extern crate wasm_bindgen;
153
+ use wasm_bindgen::prelude::*;
154
+ use wasm_bindgen::js;
155
+
156
+ #[wasm_bindgen]
157
+ pub fn has_elem(array: &js::Array, arg: JsValue) -> bool {
158
+ array.some(&mut |elem| arg == elem)
159
+ }
160
+
161
+ "# )
162
+ . file ( "test.ts" , r#"
163
+ import * as assert from "assert";
164
+ import * as wasm from "./out";
165
+
166
+ export function test() {
167
+ let elements = ["z", 1, "y", 2];
168
+
169
+ assert.deepStrictEqual(wasm.has_elem(elements, 2), true);
170
+ assert.deepStrictEqual(wasm.has_elem(elements, "y"), true);
171
+ assert.deepStrictEqual(wasm.has_elem(elements, "not an element"), false);
172
+ }
173
+ "# )
174
+ . test ( )
175
+ }
176
+
146
177
#[ test]
147
178
fn last_index_of ( ) {
148
179
project ( )
You can’t perform that action at this time.
0 commit comments