summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/WeakMap.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/js-sys/tests/wasm/WeakMap.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/js-sys/tests/wasm/WeakMap.rs')
-rw-r--r--vendor/js-sys/tests/wasm/WeakMap.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/js-sys/tests/wasm/WeakMap.rs b/vendor/js-sys/tests/wasm/WeakMap.rs
new file mode 100644
index 000000000..1eab1cb9d
--- /dev/null
+++ b/vendor/js-sys/tests/wasm/WeakMap.rs
@@ -0,0 +1,61 @@
+use js_sys::*;
+use wasm_bindgen::prelude::*;
+use wasm_bindgen::JsCast;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen]
+extern "C" {
+ type SomeKey;
+ #[wasm_bindgen(method, setter, structural)]
+ fn set_some(this: &SomeKey, val: JsValue);
+}
+
+fn some_key() -> Object {
+ let key = SomeKey::from(JsValue::from(Object::new()));
+ key.set_some("key".into());
+ Object::from(JsValue::from(key))
+}
+
+#[wasm_bindgen_test]
+fn new() {
+ assert!(JsValue::from(WeakMap::new()).is_object());
+}
+
+#[wasm_bindgen_test]
+fn get_and_set() {
+ let map = WeakMap::new();
+ let key = some_key();
+ map.set(&key, &"value".into());
+ assert_eq!(map.get(&key), "value");
+ assert_eq!(map.get(&Object::new()), JsValue::undefined());
+ assert_eq!(map.get(&some_key()), JsValue::undefined());
+}
+
+#[wasm_bindgen_test]
+fn has() {
+ let map = WeakMap::new();
+ let key = some_key();
+ map.set(&key, &"value".into());
+ assert!(map.has(&key));
+ assert!(!map.has(&Object::new()));
+ assert!(!map.has(&some_key()));
+}
+
+#[wasm_bindgen_test]
+fn delete() {
+ let map = WeakMap::new();
+ let key = some_key();
+ assert!(!map.has(&key));
+ map.set(&key, &"value".into());
+ assert!(map.has(&key));
+ map.delete(&key);
+ assert!(!map.has(&key));
+}
+
+#[wasm_bindgen_test]
+fn weakmap_inheritance() {
+ let map = WeakMap::new();
+ assert!(map.is_instance_of::<WeakMap>());
+ assert!(map.is_instance_of::<Object>());
+ let _: &Object = map.as_ref();
+}