mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 04:21:21 +00:00
[WIP] Add support for unstable WebIDL (#1997)
* Re-enable WebGPU WebIDL as experimental * Add `web_sys_unstable_apis` attribute * Add test for unstable WebIDL * Include unstable WebIDL in docs.rs builds * Add docs and doc comment for unstable APIs * Add unstable API checks to CI
This commit is contained in:
@ -11,13 +11,22 @@ fn main() {
|
||||
let idls = fs::read_dir(".")
|
||||
.unwrap()
|
||||
.map(|f| f.unwrap().path())
|
||||
.filter(|f| f.extension().and_then(|s| s.to_str()) == Some("webidl"))
|
||||
.map(|f| (fs::read_to_string(&f).unwrap(), f));
|
||||
.filter(|path| path.extension().and_then(|s| s.to_str()) == Some("webidl"))
|
||||
.map(|path| {
|
||||
let unstable = path.file_name().and_then(|s| s.to_str()) == Some("unstable.webidl");
|
||||
let file = fs::read_to_string(&path).unwrap();
|
||||
(file, path, unstable)
|
||||
});
|
||||
|
||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
for (i, (idl, path)) in idls.enumerate() {
|
||||
for (i, (idl, path, unstable)) in idls.enumerate() {
|
||||
println!("processing {:?}", path);
|
||||
let mut generated_rust = wasm_bindgen_webidl::compile(&idl, None).unwrap();
|
||||
let (stable_source, experimental_source) = if unstable {
|
||||
(String::new(), idl)
|
||||
} else {
|
||||
(idl, String::new())
|
||||
};
|
||||
let mut generated_rust = wasm_bindgen_webidl::compile(&stable_source, &experimental_source, None).unwrap();
|
||||
|
||||
generated_rust.insert_str(
|
||||
0,
|
||||
|
@ -13,3 +13,4 @@ pub mod namespace;
|
||||
pub mod no_interface;
|
||||
pub mod simple;
|
||||
pub mod throws;
|
||||
pub mod unstable;
|
||||
|
13
crates/webidl-tests/unstable.js
Normal file
13
crates/webidl-tests/unstable.js
Normal file
@ -0,0 +1,13 @@
|
||||
global.GetUnstableInterface = class {
|
||||
static get() {
|
||||
return {
|
||||
enum_value(dict) {
|
||||
if (!dict) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return dict.unstableEnum === "a" ? 1 : 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
crates/webidl-tests/unstable.rs
Normal file
17
crates/webidl-tests/unstable.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/unstable.rs"));
|
||||
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
#[wasm_bindgen_test]
|
||||
fn can_use_unstable_apis() {
|
||||
let unstable_interface = GetUnstableInterface::get();
|
||||
assert_eq!(0u32, unstable_interface.enum_value());
|
||||
|
||||
let mut dict = UnstableDictionary::new();
|
||||
dict.unstable_enum(UnstableEnum::B);
|
||||
assert_eq!(
|
||||
2u32,
|
||||
unstable_interface.enum_value_with_unstable_dictionary(&dict)
|
||||
);
|
||||
}
|
19
crates/webidl-tests/unstable.webidl
vendored
Normal file
19
crates/webidl-tests/unstable.webidl
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
enum UnstableEnum {
|
||||
"a",
|
||||
"b"
|
||||
};
|
||||
|
||||
dictionary UnstableDictionary {
|
||||
UnstableEnum unstableEnum;
|
||||
};
|
||||
|
||||
typedef unsigned long UnstableTypedef;
|
||||
|
||||
[NoInterfaceObject]
|
||||
partial interface UnstableInterface {
|
||||
UnstableTypedef enum_value(optional UnstableDictionary unstableDictionary = {});
|
||||
};
|
||||
|
||||
interface GetUnstableInterface {
|
||||
static UnstableInterface get();
|
||||
};
|
Reference in New Issue
Block a user