mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
feat(Map): add Map.size
This commit is contained in:
parent
6f90bd677b
commit
ea19775639
@ -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
|
||||
|
@ -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()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user