Auto merge of #26955 - gterzian:fix_parser_borrow, r=jdm

Do not trace pending parsers

<!-- Please describe your changes on the following line: -->

FIX https://github.com/servo/servo/issues/26857

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-06-17 23:20:45 -04:00 committed by GitHub
commit 429bb9e874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View file

@ -500,7 +500,7 @@ impl<'a> Iterator for DocumentsIter<'a> {
// which can trigger GC, and so we can end up tracing the script
// thread during parsing. For this reason, we don't trace the
// incomplete parser contexts during GC.
type IncompleteParserContexts = Vec<(PipelineId, ParserContext)>;
pub struct IncompleteParserContexts(RefCell<Vec<(PipelineId, ParserContext)>>);
unsafe_no_jsmanaged_fields!(TaskQueue<MainThreadScriptMsg>);
unsafe_no_jsmanaged_fields!(dyn BackgroundHangMonitorRegister);
@ -518,7 +518,7 @@ pub struct ScriptThread {
/// A list of data pertaining to loads that have not yet received a network response
incomplete_loads: DomRefCell<Vec<InProgressLoad>>,
/// A vector containing parser contexts which have not yet been fully processed
incomplete_parser_contexts: RefCell<IncompleteParserContexts>,
incomplete_parser_contexts: IncompleteParserContexts,
/// Image cache for this script thread.
image_cache: Arc<dyn ImageCache>,
/// A handle to the resource thread. This is an `Arc` to avoid running out of file descriptors if
@ -1257,7 +1257,7 @@ impl ScriptThread {
documents: DomRefCell::new(Documents::new()),
window_proxies: DomRefCell::new(HashMap::new()),
incomplete_loads: DomRefCell::new(vec![]),
incomplete_parser_contexts: RefCell::new(vec![]),
incomplete_parser_contexts: IncompleteParserContexts(RefCell::new(vec![])),
image_cache: state.image_cache.clone(),
image_cache_channel: image_cache_channel,
@ -3684,6 +3684,7 @@ impl ScriptThread {
let context = ParserContext::new(id, load_data.url);
self.incomplete_parser_contexts
.0
.borrow_mut()
.push((id, context));
@ -3710,7 +3711,7 @@ impl ScriptThread {
},
};
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.borrow_mut();
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.0.borrow_mut();
let parser = incomplete_parser_contexts
.iter_mut()
.find(|&&mut (pipeline_id, _)| pipeline_id == id);
@ -3720,7 +3721,7 @@ impl ScriptThread {
}
fn handle_fetch_chunk(&self, id: PipelineId, chunk: Vec<u8>) {
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.borrow_mut();
let mut incomplete_parser_contexts = self.incomplete_parser_contexts.0.borrow_mut();
let parser = incomplete_parser_contexts
.iter_mut()
.find(|&&mut (pipeline_id, _)| pipeline_id == id);
@ -3732,12 +3733,13 @@ impl ScriptThread {
fn handle_fetch_eof(&self, id: PipelineId, eof: Result<ResourceFetchTiming, NetworkError>) {
let idx = self
.incomplete_parser_contexts
.0
.borrow()
.iter()
.position(|&(pipeline_id, _)| pipeline_id == id);
if let Some(idx) = idx {
let (_, mut ctxt) = self.incomplete_parser_contexts.borrow_mut().remove(idx);
let (_, mut ctxt) = self.incomplete_parser_contexts.0.borrow_mut().remove(idx);
ctxt.process_response_eof(eof);
}
}