diff --git a/src/js.rs b/src/js.rs index fae6379d..0b04b6d3 100644 --- a/src/js.rs +++ b/src/js.rs @@ -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 diff --git a/tests/all/js_globals/Map.rs b/tests/all/js_globals/Map.rs index 049b0df6..522e7fde 100644 --- a/tests/all/js_globals/Map.rs +++ b/tests/all/js_globals/Map.rs @@ -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() } \ No newline at end of file