mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add binding for keys method
This commit is contained in:
parent
0b29721194
commit
4cc73877a6
10
src/js.rs
10
src/js.rs
@ -195,5 +195,15 @@ extern {
|
||||
/// 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;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type ArrayIterator;
|
||||
|
||||
/// The keys() method returns a new Array Iterator object that contains the keys for each index in the array.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn keys(this: &Array) -> ArrayIterator;
|
||||
}
|
34
tests/all/js_globals/ArrayIterator.rs
Normal file
34
tests/all/js_globals/ArrayIterator.rs
Normal file
@ -0,0 +1,34 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use project;
|
||||
|
||||
#[test]
|
||||
fn keys() {
|
||||
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 get_keys(this: &js::Array) -> js::ArrayIterator {
|
||||
this.keys()
|
||||
}
|
||||
|
||||
"#)
|
||||
.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 iterator = characters.keys();
|
||||
let wasmIterator = wasm.get_keys(characters);
|
||||
|
||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
@ -4,6 +4,7 @@ use super::project;
|
||||
|
||||
mod Object;
|
||||
mod Array;
|
||||
mod ArrayIterator;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "std")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user