mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 17:31:06 +00:00
feat(Map): add Map.clear
This commit is contained in:
parent
c608d46a56
commit
ab0546963b
12
src/js.rs
12
src/js.rs
@ -302,6 +302,18 @@ extern {
|
|||||||
pub fn to_string(this: &Function) -> JsString;
|
pub fn to_string(this: &Function) -> JsString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
pub type Map;
|
||||||
|
|
||||||
|
/// The clear() method removes all elements from a Map object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn clear(this: &Map);
|
||||||
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern {
|
||||||
|
35
tests/all/js_globals/Map.rs
Normal file
35
tests/all/js_globals/Map.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
use project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn clear() {
|
||||||
|
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_clear(this: &js::Map) {
|
||||||
|
this.clear();
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.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(map.size, 2);
|
||||||
|
wasm.map_clear(map);
|
||||||
|
assert.equal(map.size, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
@ -8,6 +8,7 @@ mod Boolean;
|
|||||||
mod Date;
|
mod Date;
|
||||||
mod Function;
|
mod Function;
|
||||||
mod JsString;
|
mod JsString;
|
||||||
|
mod Map;
|
||||||
mod Math;
|
mod Math;
|
||||||
mod WeakMap;
|
mod WeakMap;
|
||||||
mod WeakSet;
|
mod WeakSet;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user