mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
add binding for entries method
This commit is contained in:
parent
4cc73877a6
commit
a95476a8ee
@ -197,6 +197,7 @@ extern {
|
||||
pub fn includes(this: &Array, value: JsValue, from_index: i32) -> bool;
|
||||
}
|
||||
|
||||
// Array Iterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type ArrayIterator;
|
||||
@ -206,4 +207,10 @@ extern {
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn keys(this: &Array) -> ArrayIterator;
|
||||
|
||||
/// The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn entries(this: &Array) -> ArrayIterator;
|
||||
}
|
@ -28,6 +28,41 @@ fn keys() {
|
||||
let wasmIterator = wasm.get_keys(characters);
|
||||
|
||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||
assert.equal(Array.from(iterator)[0], Array.from(wasmIterator)[0]);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entries() {
|
||||
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_entries(this: &js::Array) -> js::ArrayIterator {
|
||||
this.entries()
|
||||
}
|
||||
|
||||
"#)
|
||||
.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.entries();
|
||||
let wasmIterator = wasm.get_entries(characters);
|
||||
let jsItem = iterator.next();
|
||||
let wasmItem = wasmIterator.next();
|
||||
|
||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||
assert.equal(jsItem.value[1], wasmItem.value[1]);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
|
Loading…
Reference in New Issue
Block a user