1 use wasm_bindgen::prelude::*; 2 use wasm_bindgen_test::*; 3 4 #[wasm_bindgen(module = "tests/wasm/vendor_prefix.js")] 5 extern "C" { import_me(x: &str)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)] new() -> MySpecialApi14 fn new() -> MySpecialApi; 15 #[wasm_bindgen(method)] foo(this: &MySpecialApi) -> u3216 fn foo(this: &MySpecialApi) -> u32; 17 18 #[wasm_bindgen(vendor_prefix = webkit)] 19 type MySpecialApi2; 20 #[wasm_bindgen(constructor)] new() -> MySpecialApi221 fn new() -> MySpecialApi2; 22 #[wasm_bindgen(method)] foo(this: &MySpecialApi2) -> u3223 fn foo(this: &MySpecialApi2) -> u32; 24 25 #[wasm_bindgen(vendor_prefix = a, vendor_prefix = b)] 26 type MySpecialApi3; 27 #[wasm_bindgen(constructor)] new() -> MySpecialApi328 fn new() -> MySpecialApi3; 29 #[wasm_bindgen(method)] foo(this: &MySpecialApi3) -> u3230 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)] new() -> Result<MyMissingApi, JsValue>37 fn new() -> Result<MyMissingApi, JsValue>; 38 } 39 40 #[wasm_bindgen_test] polyfill_works()41pub 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 } 49