feat(Map): add Map.set

This commit is contained in:
Jannik Keye 2018-06-28 21:55:55 +02:00
parent 27ee57175a
commit 6f90bd677b
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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()
}