mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-13 23:56:06 +00:00
feat(Map): add Map.has
This commit is contained in:
parent
e0b399643a
commit
07e61e1175
@ -324,6 +324,13 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn get(this: &Map, key: &JsValue) -> JsValue;
|
pub fn get(this: &Map, key: &JsValue) -> JsValue;
|
||||||
|
|
||||||
|
/// The has() method returns a boolean indicating whether an element with
|
||||||
|
/// the specified key exists or not.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn has(this: &Map, key: &JsValue) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
|
@ -96,3 +96,32 @@ fn get() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has() {
|
||||||
|
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 has(this: &js::Map, key: &JsValue) -> bool {
|
||||||
|
this.has(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(wasm.has(map, 'foo'), true);
|
||||||
|
assert.equal(wasm.has(map, 'bar'), false);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user