feat(Map/MapIterator): add Map.values

This commit is contained in:
Jannik Keye 2018-06-28 22:00:02 +02:00
parent fc131ee97e
commit e0a70417ce
2 changed files with 39 additions and 0 deletions

View File

@ -374,6 +374,13 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
#[wasm_bindgen(method)]
pub fn keys(this: &Map) -> MapIterator;
/// The values() method returns a new Iterator object that contains the
/// values for each element in the Map object in insertion order.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values
#[wasm_bindgen(method)]
pub fn values(this: &Map) -> MapIterator;
}
// Math

View File

@ -65,4 +65,36 @@ fn keys() {
}
"#)
.test()
}
#[test]
fn values() {
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_values(this: &js::Map) -> js::MapIterator {
this.values()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
const map = new Map();
const iterator = map.keys();
const wasmIterator = wasm.get_values(map);
map.set('foo', 'bar');
map.set('bar', 'baz');
assert.equal(iterator.toString(), wasmIterator.toString());
}
"#)
.test()
}