[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:
Josh Groves
2020-02-26 19:00:11 -03:30
committed by GitHub
parent d26068dc6c
commit 99c59a771e
24 changed files with 1387 additions and 792 deletions

View File

@ -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,

View File

@ -13,3 +13,4 @@ pub mod namespace;
pub mod no_interface;
pub mod simple;
pub mod throws;
pub mod unstable;

View File

@ -0,0 +1,13 @@
global.GetUnstableInterface = class {
static get() {
return {
enum_value(dict) {
if (!dict) {
return 0;
}
return dict.unstableEnum === "a" ? 1 : 2;
}
}
}
}

View 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
View 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();
};