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

parse_floating_point_number does not conform to spec #32269

Closed
sagudev opened this issue May 11, 2024 · 4 comments · Fixed by #32272
Closed

parse_floating_point_number does not conform to spec #32269

sagudev opened this issue May 11, 2024 · 4 comments · Fixed by #32272

Comments

@sagudev
Copy link
Member

sagudev commented May 11, 2024

As noted in #32230 (comment)

SPEC: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values

@sagudev
Copy link
Member Author

sagudev commented May 11, 2024

Will you do this @shanehandley?

@shanehandley
Copy link
Contributor

I will take a look! Thank you.

@shanehandley
Copy link
Contributor

shanehandley commented May 11, 2024

I was wrong 🙇 . parse_floating_point_number is probably correct, my mistake was using it when I should have used set_best_representation_of_the_floating_point_number, which is the one we need to touch up 👍

This comment in the WPT tests repo clarified things for me: web-platform-tests/wpt#44315 (comment)

the best represetation of the number n as a floating point number, referenced from the setter, that relies on the ECMAScript ToString, itself dictating that the number -0 is stringified to 0

We have a DOMString::set_best_representation_of_the_floating_point_number(), It is not called from anywhere in the codebase currently, and it uses the plain rust conversion to_string() without applying any logic in the spec. It looks like it was originally added with the <range> logic, but fell out of use.

It seems the work required is:

  1. Improve the implementation of set_best_representation_of_the_floating_point_number to be more compliant with the ECMAScript ToString spec
  2. Use it in place of parse_floating_point_number for affected elements: <meter>, <progress>, <input type="number"> and <input type="range">.

For 1., there is a lot of overlap between the ECMAScript and HTML specs for parsing floats (with radix omitted) - so maybe we can pluck out the some key steps and mostly fall back to it?

@sagudev
Copy link
Member Author

sagudev commented May 11, 2024

Oh, you're right, I also completely missed best represetation of the number n as a floating point number part.

ECMAScript parsing of floats is implemented in SM (I think), so we would need conversions it might be better to just do some pre/post processing like it's done in parse_floating_point_number on top of rust's to_string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants