mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
feat(Map/MapIterator): add Map.keys
This commit is contained in:
parent
228abaa4ae
commit
fc131ee97e
@ -367,6 +367,13 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn entries(this: &Map) -> MapIterator;
|
pub fn entries(this: &Map) -> MapIterator;
|
||||||
|
|
||||||
|
/// The keys() method returns a new Iterator object that contains the
|
||||||
|
/// keys for each element in the Map object in insertion order.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn keys(this: &Map) -> MapIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
|
@ -34,3 +34,35 @@ fn entries() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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::Map) -> js::MapIterator {
|
||||||
|
this.keys()
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.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_keys(map);
|
||||||
|
map.set('foo', 'bar');
|
||||||
|
map.set('bar', 'baz');
|
||||||
|
|
||||||
|
assert.equal(iterator.toString(), wasmIterator.toString());
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user