Debian Codegraph @

.cargo/vendor/wasm-bindgen/tests/wasm/vendor_prefix.rs

raw
1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3
4 #[wasm_bindgen(module = "tests/wasm/vendor_prefix.js")]
5 extern "C" {
6 fn import_me(x: &str);
7 }
8
9 #[wasm_bindgen]
10 extern "C" {
11 #[wasm_bindgen(vendor_prefix = webkit)]
12 type MySpecialApi;
13 #[wasm_bindgen(constructor)]
14 fn new() -> MySpecialApi;
15 #[wasm_bindgen(method)]
16 fn foo(this: &MySpecialApi) -> u32;
17
18 #[wasm_bindgen(vendor_prefix = webkit)]
19 type MySpecialApi2;
20 #[wasm_bindgen(constructor)]
21 fn new() -> MySpecialApi2;
22 #[wasm_bindgen(method)]
23 fn foo(this: &MySpecialApi2) -> u32;
24
25 #[wasm_bindgen(vendor_prefix = a, vendor_prefix = b)]
26 type MySpecialApi3;
27 #[wasm_bindgen(constructor)]
28 fn new() -> MySpecialApi3;
29 #[wasm_bindgen(method)]
30 fn foo(this: &MySpecialApi3) -> u32;
31
32 // This API does not exist at all;
33 // test that Rust gets a chance to catch the error (#2437)
34 #[wasm_bindgen(vendor_prefix = a, vendor_prefix = b)]
35 type MyMissingApi;
36 #[wasm_bindgen(constructor, catch)]
37 fn new() -> Result<MyMissingApi, JsValue>;
38 }
39
40 #[wasm_bindgen_test]
41 pub fn polyfill_works() {
42 import_me("foo");
43
44 assert_eq!(MySpecialApi::new().foo(), 123);
45 assert_eq!(MySpecialApi2::new().foo(), 124);
46 assert_eq!(MySpecialApi3::new().foo(), 125);
47 assert!(MyMissingApi::new().is_err());
48 }