Skip to content

Use html5ever’s BytesParser. - #9677

Closed
SimonSapin wants to merge 4 commits into
masterfrom
html5ever-bytes
Closed

SimonSapin wants to merge 4 commits into
masterfrom
html5ever-bytes

Conversation

@SimonSapin

Copy link
Copy Markdown
Member

This fixes the encoding issue in #9670, though it uncovers a font selection issue (at least for me).

screenshot from 2016-02-17 12-53-31

Review on Reviewable

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Feb 17, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit b080c4a with merge 2927c1e...

bors-servo pushed a commit that referenced this pull request Feb 17, 2016
Use html5ever’s BytesParser.

This fixes the encoding issue in #9670, though it uncovers a font selection issue (at least for me).

![screenshot from 2016-02-17 12-53-31](https://cloud.githubusercontent.com/assets/291359/13108773/7a35e196-d575-11e5-934f-71b3c6dda2ef.png)
ignore_missing_rules: true,
.. Default::default()
let html5ever_parser = parse_document(sink, Default::default()).from_bytes(BytesOpts {
// FIXME: get this from Hyper

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-css

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Feb 17, 2016
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Feb 17, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

Enabled some more tests, some of which are fixed by this code change.

@jdm jdm added the S-tests-failed The changes caused existing tests to fail. label Feb 17, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

Ok, so the problem in these failing tests is that html5ever::driver::BytesParser buffers up to 1024 bytes at the start of the input before it begins parsing. This is to be able to detect the encoding from a byte order mark and (when it’ll be implemented) <meta charset>.

/css-flexbox-1_dev/html/display_flex_exist.htm for example is 930 bytes and gets read in one chunk. Since that’s less than 1024, parsing doesn’t start until BytesParser::finish (saying that there is no more input) is called.

I don’t know yet why this timing difference causes a panic, but reverting just that fixes it. I’ll look into it tomorrow, but I’d take any idea in the mean time. The panic is in script/dom/document.rs:

    pub fn set_pending_parsing_blocking_script(&self, script: Option<&HTMLScriptElement>) {
        assert!(self.get_pending_parsing_blocking_script().is_none() || script.is_none());
        self.pending_parsing_blocking_script.set(script);
    }

The assertion fails because both options are Some.

@Ms2ger

Ms2ger commented Feb 18, 2016

Copy link
Copy Markdown
Contributor

Can you check which of the three script elements in that file are involved?

@Ms2ger Ms2ger self-assigned this Feb 18, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

I get the assertion error on the second call to set_pending_parsing_blocking_script, fwiw.

This fixes the encoding issue in
#9670,
though it uncovers a font selection issue (at least for me).
@SimonSapin

Copy link
Copy Markdown
Member Author

@Ms2ger pointed out on IRC that html5ever::driver::BytesParser has:

    fn finish(self) -> Self::Output {
        match self.state {
            BytesParserState::Initial { parser } => parser.finish(),
            BytesParserState::Buffering { parser, buffer } => {
                let encoding = detect_encoding(&buffer, &self.opts);
                let mut decoder = LossyDecoder::new(encoding, parser);
                decoder.process(buffer);
                decoder.finish()
            },
            BytesParserState::Parsing { decoder } => decoder.finish(),
            BytesParserState::Transient => unreachable!(),
        }
    }

For small document, we’re in the Buffering case. If buffer contains a blocking <script> element that should suspend parsing, decoder.process will return and expect to be called again after that script has been fetched and executed. But BytesParser happily ignores that and calls finish, forcing parsing to continue.

On a high level, we need a way to suspend and resume parsing (possibly multiple times) after the end of the input has been signaled.

IRC again:

Ms2ger: I feel like having the suspending code in servo rather than h5e is not sustainable

It does sound to me that some architecture needs to change here, but that’s a much bigger task than I was expected to get when I started working on this PR. I’m gonna move on to something else for now, anyone feel free to take this over.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Feb 18, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Feb 23, 2016
@jdm jdm added the S-needs-new-owner The PR has been abandoned by the original author. label Feb 23, 2016
@jdm jdm closed this Feb 23, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

#198 should work around the issue. I updated this PR to include it. @jdm, are you ok with landing this PR with that work-around, and leave the underlying issue (servo/html5ever#198) for later?

@bors-servo try

bors-servo pushed a commit that referenced this pull request Feb 23, 2016
@SimonSapin

Copy link
Copy Markdown
Member Author

Looks like I can’t reopen a PR if I force-pushed to its branch while it was closed, so #9730.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed. S-needs-new-owner The PR has been abandoned by the original author. S-needs-rebase There are merge conflict errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants