Skip to content

Comments

Add parsing of double values in style attributes#10608

Merged
bors-servo merged 1 commit intoservo:masterfrom
KiChjang:parse-double
Apr 26, 2016
Merged

Add parsing of double values in style attributes#10608
bors-servo merged 1 commit intoservo:masterfrom
KiChjang:parse-double

Conversation

@KiChjang
Copy link
Contributor

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/attr.rs
  • @KiChjang: components/script/dom/htmlfontelement.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 14, 2016
@KiChjang
Copy link
Contributor Author

$ bash etc/ci/check_no_unwrap.sh

components/compositing/constellation.rs:870:                          LoadData::new(Url::parse("about:failure").unwrap()));

components/compositing/constellation.rs:953:                .unwrap_or_else(|| Url::parse("about:blank").unwrap());

The command "bash etc/ci/check_no_unwrap.sh" exited with 1.

Not my fault!

@jdm
Copy link
Member

jdm commented Apr 14, 2016

Yep, #10610 clears that up.


/// Parse a floating-point number according to
/// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-floating-point-number-values>
pub fn parse_double(string: &DOMString) -> Option<f64> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could it return Result<f64, ()> instead?

@nox
Copy link
Contributor

nox commented Apr 15, 2016

Shouldn't that make new tests pass?

-S-awaiting-review +S-needs-code-changes


Reviewed 7 of 7 files at r1.
Review status: all files reviewed at latest revision, 7 unresolved discussions.


components/servo/Cargo.lock, line 2193 [r1] (raw file):
You should probably use ./mach cargo-update, I'm pretty sure more lock files need to change.


components/style/attr.rs, line 82 [r1] (raw file):
Just use trim_matches to skip whitespace.


components/style/attr.rs, line 106 [r1] (raw file):
No need to recreate the iterator.


components/util/str.rs, line 166 [r1] (raw file):
Nit: can you make this a char?


components/util/str.rs, line 170 [r1] (raw file):
Why not just do c == '.' btw?


components/util/str.rs, line 196 [r1] (raw file):
Why do we need to return the number of digits which were read?


Comments from Reviewable

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 15, 2016
@KiChjang
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 7 unresolved discussions.


components/style/attr.rs, line 79 [r1] (raw file):
Should I change parse_integer as well then?


components/style/attr.rs, line 106 [r1] (raw file):
Can't do that, the read_* functions take ownership of the iterator.


components/util/str.rs, line 196 [r1] (raw file):
Because these functions take ownership of the iterator, and so I need to keep track of where it stopped parsing.


Comments from Reviewable

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Apr 15, 2016
@nox
Copy link
Contributor

nox commented Apr 18, 2016

-S-awaiting-review +S-needs-code-changes


Reviewed 5 of 5 files at r2.
Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


components/style/attr.rs, line 79 [r1] (raw file):
Would be nice yes.


components/style/attr.rs, line 106 [r1] (raw file):
Well, just pass &mut Peekable<I>, no?


components/util/str.rs, line 196 [r1] (raw file):
Just make them take &mut Peekable<I>.


components/util/str.rs, line 170 [r2] (raw file):
Nit: char.


Comments from Reviewable

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 18, 2016
@KiChjang
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


components/style/attr.rs, line 106 [r1] (raw file):
Ack, this actually causes my parsing to fail, because take_while() consumes the first element that doesn't satisfy the condition. I could use take_while_ref offered by the itertools crate though, should I use that?


Comments from Reviewable

@KiChjang
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 5 unresolved discussions, some commit checks failed.


components/style/attr.rs, line 106 [r1] (raw file):
Doesn't seem to work either, the iterator needs to be cloneable in order to use .take_while_ref().


Comments from Reviewable

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Apr 18, 2016
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #10745) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Apr 20, 2016
@nox
Copy link
Contributor

nox commented Apr 21, 2016

Reviewed 3 of 3 files at r3.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/style/attr.rs, line 106 [r1] (raw file):
I don't see a take_while call anywhere so I'm confused.

Anyway I don't think having to decode a string multiple times should be needed to just parse an integer string.


components/style/attr.rs, line 66 [r3] (raw file):
Shouldn't do_parse_integer return a Result itself? Feel free to file an E-Easy about that.


Comments from Reviewable

@KiChjang
Copy link
Contributor Author

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/style/attr.rs, line 106 [r1] (raw file):
take_while is what's being used in read_integers and read_fractions. I don't think it's necessary either but due to the design of take_while, I can't track the last character that wasn't a digit.


Comments from Reviewable

@KiChjang KiChjang removed the S-needs-rebase There are merge conflict errors. label Apr 24, 2016
@nox
Copy link
Contributor

nox commented Apr 26, 2016

Seems good enough. Please file an issue about do_parse_integers' return type and take_while being used.

No WPT test?

-S-awaiting-review +S-awaiting-answer


Reviewed 10 of 10 files at r4.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@nox nox added S-awaiting-answer Someone asked a question that requires an answer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 26, 2016
@nox
Copy link
Contributor

nox commented Apr 26, 2016

Seems good enough. Please file an issue about do_parse_integers' return type and take_while being used.

No WPT test?

-S-awaiting-review +S-awaiting-answer


Reviewed 10 of 10 files at r4.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


Comments from Reviewable

@KiChjang
Copy link
Contributor Author

I have another branch that actually utilizes the parse_double utility function (it's for parsing HTMLInputElement doubles), but for this PR, I've added a unit test instead since it's only a util crate modification.

@KiChjang
Copy link
Contributor Author

Filed #10860 and #10861.

@bors-servo r=nox

@bors-servo
Copy link
Contributor

📌 Commit 48b2e9c has been approved by nox

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-answer Someone asked a question that requires an answer. labels Apr 26, 2016
@bors-servo
Copy link
Contributor

⌛ Testing commit 48b2e9c with merge ccba2d6...

bors-servo pushed a commit that referenced this pull request Apr 26, 2016
Add parsing of double values in style attributes

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10608)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt

@bors-servo bors-servo merged commit 48b2e9c into servo:master Apr 26, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 26, 2016
@KiChjang KiChjang deleted the parse-double branch April 26, 2016 20:21
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.

5 participants