From e0b399643aa42e15462b1aaddb2b30233fe3dfd5 Mon Sep 17 00:00:00 2001
From: Jannik Keye <jannik.keye@gmail.com>
Date: Thu, 28 Jun 2018 21:53:20 +0200
Subject: [PATCH] feat(Map): add Map.get

---
 src/js.rs                   |  6 ++++++
 tests/all/js_globals/Map.rs | 31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/src/js.rs b/src/js.rs
index b6a55114..e53ae6da 100644
--- a/src/js.rs
+++ b/src/js.rs
@@ -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
diff --git a/tests/all/js_globals/Map.rs b/tests/all/js_globals/Map.rs
index a8a7ace3..1279c482 100644
--- a/tests/all/js_globals/Map.rs
+++ b/tests/all/js_globals/Map.rs
@@ -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()
 }
\ No newline at end of file