Skip to content

Commit

Permalink
Auto merge of #19307 - avadacatavra:domrefcellpanic, r=<try>
Browse files Browse the repository at this point in the history
change parse_own_css to queue event not fire synchronously

<!-- Please describe your changes on the following line: -->
fixes a panic and aligns with spec

I've also added checks around each mutable borrow of the tokenizer to see if we can catch any other panics

---
<!-- 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 #18930 (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. -->

<!-- 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/19307)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 21, 2017
2 parents dc35457 + 0269db1 commit 167c884
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
7 changes: 7 additions & 0 deletions components/script/dom/document.rs
Expand Up @@ -1882,6 +1882,13 @@ impl Document {
self.current_parser.get()
}

pub fn can_invoke_script(&self) -> bool {
match self.get_current_parser() {
Some(parser) => parser.parser_is_not_active(),
None => true,
}
}

/// Iterate over all iframes in the document.
pub fn iter_iframes(&self) -> impl Iterator<Item=DomRoot<HTMLIFrameElement>> {
self.upcast::<Node>()
Expand Down
13 changes: 13 additions & 0 deletions components/script/dom/eventtarget.rs
Expand Up @@ -315,10 +315,23 @@ impl EventTarget {
pub fn dispatch_event_with_target(&self,
target: &EventTarget,
event: &Event) -> EventStatus {
match target.global().downcast::<Window>() {
Some(window) => if window.has_document() {
assert!(window.Document().can_invoke_script());
},
None => (),
};

event.dispatch(self, Some(target))
}

pub fn dispatch_event(&self, event: &Event) -> EventStatus {
match self.global().downcast::<Window>() {
Some(window) => if window.has_document() {
assert!(window.Document().can_invoke_script());
},
None => (),
};
event.dispatch(self, None)
}

Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/htmlstyleelement.rs
Expand Up @@ -12,7 +12,6 @@ use dom::bindings::root::{DomRoot, MutNullableDom};
use dom::cssstylesheet::CSSStyleSheet;
use dom::document::Document;
use dom::element::{Element, ElementCreator};
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{ChildrenMutation, Node, UnbindContext, document_from_node, window_from_node};
use dom::stylesheet::StyleSheet as DOMStyleSheet;
Expand Down Expand Up @@ -105,9 +104,10 @@ impl HTMLStyleElement {

let sheet = Arc::new(sheet);

// No subresource loads were triggered, just fire the load event now.
// No subresource loads were triggered, queue load event
if self.pending_loads.get() == 0 {
self.upcast::<EventTarget>().fire_event(atom!("load"));
let window = window_from_node(self);
window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"), &window);
}

self.set_stylesheet(sheet);
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/servoparser/mod.rs
Expand Up @@ -102,6 +102,10 @@ enum LastChunkState {
}

impl ServoParser {
pub fn parser_is_not_active(&self) -> bool {
self.tokenizer.try_borrow_mut().is_ok()
}

pub fn parse_html_document(document: &Document, input: DOMString, url: ServoUrl) {
let parser = if PREFS.get("dom.servoparser.async_html_tokenizer.enabled").as_boolean().unwrap() {
ServoParser::new(document,
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/window.rs
Expand Up @@ -1048,6 +1048,10 @@ impl Window {
self.navigation_start_precise.get()
}

pub fn has_document(&self) -> bool {
self.document.get().is_some()
}

/// Cancels all the tasks associated with that window.
///
/// This sets the current `ignore_further_async_events` sentinel value to
Expand Down

0 comments on commit 167c884

Please sign in to comment.