mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-27 22:52:15 +00:00
feat(Map): add Map.delete
This commit is contained in:
parent
ab0546963b
commit
f7e4019e72
@ -312,6 +312,12 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn clear(this: &Map);
|
pub fn clear(this: &Map);
|
||||||
|
|
||||||
|
/// The delete() method removes the specified element from a Map object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn delete(this: &Map, key: &str) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
|
@ -32,4 +32,36 @@ fn clear() {
|
|||||||
}
|
}
|
||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn delete() {
|
||||||
|
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_delete(this: &js::Map, key: &str) -> bool {
|
||||||
|
this.delete(key)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.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');
|
||||||
|
assert.equal(map.size, 1);
|
||||||
|
assert.equal(wasm.map_delete(map, 'foo'), true);
|
||||||
|
assert.equal(wasm.map_delete(map, 'bar'), false);
|
||||||
|
assert.equal(map.size, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user