-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add webidl optional
support to web-sys
#502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Unfortunately #[wasm_bindgen]
extern {
fn count();
#[wasm_bindgen(js_name = count)]
fn count2(label: &str);
} So perhaps new names could be manufactured for invocations with optional arguments specified? |
This also ties into dealing with function overloading, which we need to deal with for proper support of WebIDL (in particular, web-sys needs it for constructors). I think what @alexcrichton suggests is basically what rust-bindgen does right now for C++ (see also rust-lang/rust-bindgen#334). |
What rust-bindgen does is pretty sucky, and I hope we can come up with something better. Even just a better mangling algorithm would be an improvement, eg #[wasm_bindgen]
extern {
fn count();
#[wasm_bindgen(js_name = count)]
fn count_label(label: &str); // concatenate each optional argument's name to the method name
} |
I can do this for now. I'm doing the console API, and maybe having a concrete implementation to see will aid bikeshedding. |
Currently
optional
parameters are forced. I think they should be anOption<T>
.This depends on #14 to generate the correct glue code, provided the way options are represented in the end is compatible with these APIs.
Also, in the spec,
optional
parameters can have a default. This doesn't really affect the rust function, but it could be mentioned in some generated documentation, perhaps.WebIDL snippet from the Console api (
console.*
):EDITS
The text was updated successfully, but these errors were encountered: