mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
feat(Map): add Map.set
This commit is contained in:
parent
27ee57175a
commit
6f90bd677b
@ -338,6 +338,13 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Map;
|
||||
|
||||
/// The set() method adds or updates an element with a specified key
|
||||
/// and value to a Map object.
|
||||
///
|
||||
/// 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;
|
||||
}
|
||||
|
||||
// Math
|
||||
|
@ -152,4 +152,33 @@ fn new() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set() {
|
||||
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 set(this: &js::Map, key: &JsValue, value: &JsValue) -> js::Map {
|
||||
this.set(key, value)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const map = new Map();
|
||||
const newMap = wasm.set(map, 'foo', 'bar');
|
||||
assert.equal(map.has('foo'), true);
|
||||
assert.equal(newMap.has('foo'), true);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user