diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/js-sys/tests/wasm/Proxy.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-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/Proxy.rs')
-rw-r--r-- | vendor/js-sys/tests/wasm/Proxy.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/js-sys/tests/wasm/Proxy.rs b/vendor/js-sys/tests/wasm/Proxy.rs new file mode 100644 index 000000000..3aca98084 --- /dev/null +++ b/vendor/js-sys/tests/wasm/Proxy.rs @@ -0,0 +1,45 @@ +use js_sys::*; +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; + +#[wasm_bindgen(module = "tests/wasm/Proxy.js")] +extern "C" { + fn proxy_target() -> JsValue; + fn proxy_handler() -> Object; + + type Custom; + #[wasm_bindgen(method, getter, structural, catch)] + fn a(this: &Custom) -> Result<u32, JsValue>; + #[wasm_bindgen(method, getter, structural, catch)] + fn b(this: &Custom) -> Result<u32, JsValue>; + + type RevocableResult; + #[wasm_bindgen(method, getter, structural)] + fn proxy(this: &RevocableResult) -> JsValue; + #[wasm_bindgen(method, getter, structural)] + fn revoke(this: &RevocableResult) -> Function; +} + +#[wasm_bindgen_test] +fn new() { + let proxy = Proxy::new(&proxy_target(), &proxy_handler()); + let proxy = Custom::from(JsValue::from(proxy)); + assert_eq!(proxy.a().unwrap(), 100); + assert_eq!(proxy.b().unwrap(), 37); +} + +#[wasm_bindgen_test] +fn revocable() { + let result = Proxy::revocable(&proxy_target(), &proxy_handler()); + let result = RevocableResult::from(JsValue::from(result)); + let proxy = result.proxy(); + let revoke = result.revoke(); + + let obj = Custom::from(proxy); + assert_eq!(obj.a().unwrap(), 100); + assert_eq!(obj.b().unwrap(), 37); + revoke.apply(&JsValue::undefined(), &Array::new()).unwrap(); + assert!(obj.a().is_err()); + assert!(obj.b().is_err()); + assert!(JsValue::from(obj).is_object()); +} |