Skip to content
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

UiEvent.pageX does not exixt #1095

Closed
chinedufn opened this issue Dec 9, 2018 · 6 comments
Closed

UiEvent.pageX does not exixt #1095

chinedufn opened this issue Dec 9, 2018 · 6 comments

Comments

@chinedufn
Copy link
Contributor

This code panics when I mouse over my canvas

 let on_mouse_move = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
      web_sys::console::log_1(&"mouse moved".into());
      let x = event.page_x();
      let y = event.page_y();
  }) as Box<FnMut(_)>);

  canvas.add_event_listener_with_callback(
      "mousemove",
      on_mouse_move.as_ref().unchecked_ref(),
  )?;

  on_mouse_move.forget();

image

I have the MouseEvent and UiEvent features enabled.

I'm using wasm-bindgen 0.2.29

@alexcrichton
Copy link
Contributor

Hm interesting! Looks like on Firefox Object.getOwnPropertyDescriptor(UIEvent.prototype, 'pageX') returns a descriptor, whereas on Chrome it does not. Are you using chrome perchance?

@chinedufn
Copy link
Contributor Author

chinedufn commented Dec 10, 2018

FWIW I switched to offset_x which works fine for my use case (I just needed some relative coordinates..)

Yup I was indeed using Chrome and I didn't check Firefox so that could be the problem!

@limira
Copy link
Contributor

limira commented Dec 11, 2018

I look in the docs. It says that (emphasis added by me)

This property was never part of any standard, and was only implemented across a subset of browsers, and only for a limited number of versions. A standardized version of pageX was added to the MouseEvent interface, however, and is well-supported. You should not expect to find pageX on any non-mouse events. Do not look for pageX on any non-mouse events in new code and update existing code as soon as possible.

And in the Specifications Section:

This property is not part of any specification. See MouseEvent.pageX instead.

So may be just access MouseEvent.pageX directly, not via UiEvent.

@limira
Copy link
Contributor

limira commented Dec 11, 2018

@chinedufn, I guess you import these things yourself (not using web-sys)??. I do a search on web-sys docs and it seems that page_x only available for UiEvent!

I think this is still an issue in web-sys!

@chinedufn chinedufn reopened this Dec 11, 2018
@chinedufn
Copy link
Contributor Author

chinedufn commented Dec 11, 2018

I'm using web-sys but I thought you were suggesting that people should write their own extern block for this - haha sorry! Re-opened!

@alexcrichton
Copy link
Contributor

Hm ok now that I look into this I think it's a bug that we're still using the old "structural" intepretation of field accesses throughout web-sys. After #1019 it's intended that web-sys switched over to just accessing properties directly, and not doing so is a bug we forgot to fix! I'll submit a fix for this shortly.

alexcrichton added a commit to alexcrichton/wasm-bindgen that referenced this issue Dec 17, 2018
This was an intended change from rustwasm#1019, but we forgot to apply it!

Closes rustwasm#1095
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

No branches or pull requests

3 participants