mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
feat(Map/MapIterator): add Map.entries
This commit is contained in:
parent
ea19775639
commit
228abaa4ae
14
src/js.rs
14
src/js.rs
@ -355,6 +355,20 @@ extern {
|
||||
pub fn size(this: &Map) -> Number;
|
||||
}
|
||||
|
||||
// Map Iterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type MapIterator;
|
||||
|
||||
/// The entries() method returns a new Iterator object that contains
|
||||
/// the [key, value] pairs for each element in the Map object in
|
||||
/// insertion order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn entries(this: &Map) -> MapIterator;
|
||||
}
|
||||
|
||||
// Math
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
|
36
tests/all/js_globals/MapIterator.rs
Normal file
36
tests/all/js_globals/MapIterator.rs
Normal file
@ -0,0 +1,36 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use project;
|
||||
|
||||
|
||||
#[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::Map) -> js::MapIterator {
|
||||
this.entries()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const map = new Map();
|
||||
const iterator = map.entries();
|
||||
const wasmIterator = wasm.get_entries(map);
|
||||
map.set('foo', 'bar');
|
||||
map.set('bar', 'baz');
|
||||
|
||||
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
@ -9,6 +9,7 @@ mod Date;
|
||||
mod Function;
|
||||
mod JsString;
|
||||
mod Map;
|
||||
mod MapIterator;
|
||||
mod Math;
|
||||
mod WeakMap;
|
||||
mod WeakSet;
|
||||
|
Loading…
Reference in New Issue
Block a user