Skip to content

Support WebIDL constants #470

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

Merged
merged 7 commits into from Jul 14, 2018
Merged

Support WebIDL constants #470

merged 7 commits into from Jul 14, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 13, 2018

Fix #259

@fitzgen fitzgen requested a review from ohanar July 13, 2018 18:29
Copy link
Member

@ohanar ohanar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Most of my comments are minor nickpicks, so I'm going to merge this now and just address them myself in #460, which changes a lot of the same code.

pub struct Const {
pub vis: syn::Visibility,
pub name: Ident,
pub interface_name: Ident,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use class here, rather than interface_name, and made the value an Option<String>. It is more consist with the function import.

@@ -42,6 +42,7 @@ pub enum ImportKind {
Static(ImportStatic),
Type(ImportType),
Enum(ImportEnum),
Const(Const),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really an import, constants are not really importing anything. This constants should really be a field in the program.


#[wasm_bindgen]
pub fn test() {
assert_eq!(foo::floats::F, 0.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this 0.0_f32 to insure that F isn't accidentally a f64 .

assert!(foo::floats::INF.is_sign_positive());
assert!(foo::floats::NAN.is_nan());

assert_eq!(foo::doubles::D, 0.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And 0.0_f64 here.

const unsigned long long umin = 0;
// bug in webidl
// https://github.com/sgodwincs/webidl-rs/issues/15
//const unsigned long long umax = 18446744073709551615;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunate. Upon scanning the docs, it doesn't look like weedle has this bug (it seems to preserve the literal string). I've wondered if we should use weedle instead since its dependencies are much more aligned with our own.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also let us skip lalrpop, which is an incredible crate, but a long build time to hoist on to downstream users :-/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was already fixed, that was fast

fn webidl_parse(
&self,
program: &mut backend::ast::Program,
interface_name: &'a str,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe self_name here to be more consistent with the other impls.

@ohanar ohanar merged commit 696678b into rustwasm:master Jul 14, 2018
ohanar added a commit to ohanar/wasm-bindgen that referenced this pull request Jul 14, 2018
@ghost ghost deleted the webidl-const branch July 14, 2018 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants