feat(Map): add Map.size

This commit is contained in:
Jannik Keye 2018-06-28 21:56:49 +02:00
parent 6f90bd677b
commit ea19775639
2 changed files with 37 additions and 0 deletions

View File

@ -345,6 +345,14 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set
#[wasm_bindgen(method)]
pub fn set(this: &Map, key: &JsValue, value: &JsValue) -> Map;
/// The value of size is an integer representing how many entries
/// the Map object has. A set accessor function for size is undefined;
/// you can not change this property.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
#[wasm_bindgen(method, getter, structural)]
pub fn size(this: &Map) -> Number;
}
// Math

View File

@ -181,4 +181,33 @@ fn set() {
}
"#)
.test()
}
#[test]
fn size() {
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 map_size(this: &js::Map) -> js::Number {
this.size()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
const map = new Map();
map.set('foo', 'bar');
map.set('bar', 'baz');
assert.equal(wasm.map_size(map), 2);
}
"#)
.test()
}