aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-06-08 12:50:22 -0400
committerGitHub <noreply@github.com>2018-06-08 12:50:22 -0400
commit527d874bc107039156d40d25b2a76f4a28eb639e (patch)
tree66653f44d488faea3c6484d667996d322b527fc4
parent385fa6f3c350668cc47bf6d8bd520cb0d173330d (diff)
parent40ea4c4946e913174c1c45486311c667d1bdcf7c (diff)
downloadservo-527d874bc107039156d40d25b2a76f4a28eb639e.tar.gz
servo-527d874bc107039156d40d25b2a76f4a28eb639e.zip
Auto merge of #21028 - asajeffrey:script-dont-trace-parsers, r=Manishearth
Fixed panic due to GC while parsing <!-- Please describe your changes on the following line: --> Don't trace the incomplete parsing contexts during GC, as parsing triggers GC while holding a mutable borrow of the context. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #21020 <!-- Either: --> - [X] These changes do not require tests because fixing a panic <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21028) <!-- Reviewable:end -->
-rw-r--r--components/script/script_thread.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 1852e467189..7fffe13e74d 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -104,6 +104,7 @@ use servo_atoms::Atom;
use servo_config::opts;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::cell::Cell;
+use std::cell::RefCell;
use std::collections::{hash_map, HashMap, HashSet};
use std::default::Default;
use std::ops::Deref;
@@ -384,6 +385,14 @@ impl<'a> Iterator for DocumentsIter<'a> {
}
}
+// We borrow the incomplete parser contexts mutably during parsing,
+// which is fine except that parsing can trigger evaluation,
+// 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)>;
+unsafe_no_jsmanaged_fields!(RefCell<IncompleteParserContexts>);
+
#[derive(JSTraceable)]
// ScriptThread instances are rooted on creation, so this is okay
#[allow(unrooted_must_root)]
@@ -396,7 +405,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: DomRefCell<Vec<(PipelineId, ParserContext)>>,
+ incomplete_parser_contexts: RefCell<IncompleteParserContexts>,
/// A map to store service worker registrations for a given origin
registration_map: DomRefCell<HashMap<ServoUrl, Dom<ServiceWorkerRegistration>>>,
/// A job queue for Service Workers keyed by their scope url
@@ -822,7 +831,7 @@ impl ScriptThread {
documents: DomRefCell::new(Documents::new()),
window_proxies: DomRefCell::new(HashMap::new()),
incomplete_loads: DomRefCell::new(vec!()),
- incomplete_parser_contexts: DomRefCell::new(vec!()),
+ incomplete_parser_contexts: RefCell::new(vec!()),
registration_map: DomRefCell::new(HashMap::new()),
job_queue_map: Rc::new(JobQueue::new()),