mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Merge pull request #327 from hjr3/issue-275-isArray
js: Implement bindings for Array.isArray
This commit is contained in:
commit
2ee39d0603
@ -131,6 +131,12 @@ extern {
|
||||
#[wasm_bindgen(method, js_name = indexOf)]
|
||||
pub fn index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
|
||||
|
||||
/// The Array.isArray() method determines whether the passed value is an Array.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
||||
#[wasm_bindgen(static_method_of = Array, js_name = isArray)]
|
||||
pub fn is_array(value: &JsValue) -> bool;
|
||||
|
||||
/// The join() method joins all elements of an array (or an array-like object)
|
||||
/// into a string and returns this string.
|
||||
///
|
||||
|
@ -73,6 +73,46 @@ fn index_of() {
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_array() {
|
||||
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 is_array(value: &JsValue) -> bool {
|
||||
js::Array::is_array(value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert(wasm.is_array([]));
|
||||
assert(wasm.is_array([1]));
|
||||
assert(wasm.is_array(new Array()));
|
||||
assert(wasm.is_array(new Array('a', 'b', 'c', 'd')));
|
||||
assert(wasm.is_array(new Array(3)));
|
||||
assert(wasm.is_array(Array.prototype));
|
||||
|
||||
assert(!wasm.is_array({}));
|
||||
assert(!wasm.is_array(null));
|
||||
assert(!wasm.is_array(undefined));
|
||||
assert(!wasm.is_array(17));
|
||||
assert(!wasm.is_array('Array'));
|
||||
assert(!wasm.is_array(true));
|
||||
assert(!wasm.is_array(false));
|
||||
assert(!wasm.is_array({ __proto__: Array.prototype }));
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort() {
|
||||
project()
|
||||
|
Loading…
x
Reference in New Issue
Block a user