feat(Map/MapIterator): add Map.entries

This commit is contained in:
Jannik Keye 2018-06-28 21:58:34 +02:00
parent ea19775639
commit 228abaa4ae
3 changed files with 51 additions and 0 deletions

View File

@ -355,6 +355,20 @@ extern {
pub fn size(this: &Map) -> Number; 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 // Math
#[wasm_bindgen] #[wasm_bindgen]
extern { extern {

View 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()
}

View File

@ -9,6 +9,7 @@ mod Date;
mod Function; mod Function;
mod JsString; mod JsString;
mod Map; mod Map;
mod MapIterator;
mod Math; mod Math;
mod WeakMap; mod WeakMap;
mod WeakSet; mod WeakSet;