mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
feat(Map): add Map.get
This commit is contained in:
parent
f7e4019e72
commit
e0b399643a
@ -318,6 +318,12 @@ extern {
|
||||
/// 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;
|
||||
|
||||
/// The get() method returns a specified element from a Map object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn get(this: &Map, key: &JsValue) -> JsValue;
|
||||
}
|
||||
|
||||
// Math
|
||||
|
@ -64,4 +64,35 @@ fn delete() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
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_get(this: &js::Map, key: &JsValue) -> JsValue {
|
||||
this.get(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');
|
||||
map.set(1, 2)
|
||||
assert.equal(wasm.map_get(map, 'foo'), 'bar');
|
||||
assert.equal(wasm.map_get(map, 1), 2);
|
||||
assert.equal(wasm.map_get(map, 2), undefined);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user