diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index 427593c8500..28c5e86b6b5 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -6,6 +6,7 @@ use document_loader::LoadType; use dom::bindings::inheritance::Castable; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::DomObject; +use dom::document::Document; use dom::element::Element; use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; @@ -78,6 +79,8 @@ pub struct StylesheetContext { metadata: Option, /// The response body received to date. data: Vec, + /// The node document for elem when the load was initiated. + document: Trusted, } impl PreInvoke for StylesheetContext {} @@ -103,7 +106,7 @@ impl FetchResponseListener for StylesheetContext { fn process_response_eof(&mut self, status: Result<(), NetworkError>) { let elem = self.elem.root(); - let document = document_from_node(&*elem); + let document = self.document.root(); let mut successful = false; if status.is_ok() { @@ -192,15 +195,15 @@ impl<'a> StylesheetLoader<'a> { impl<'a> StylesheetLoader<'a> { pub fn load(&self, source: StylesheetContextSource) { let url = source.url(); + let document = document_from_node(self.elem); let context = Arc::new(Mutex::new(StylesheetContext { elem: Trusted::new(&*self.elem), source: source, metadata: None, data: vec![], + document: Trusted::new(&*document), })); - let document = document_from_node(self.elem); - let (action_sender, action_receiver) = ipc::channel().unwrap(); let listener = NetworkListener { context: context, diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 36abb2d5adb..c77dd130e6b 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6474,6 +6474,18 @@ "url": "/_mozilla/mozilla/sslfail.html" } ], + "mozilla/stylesheet-adopt-panic.html": [ + { + "path": "mozilla/stylesheet-adopt-panic.html", + "references": [ + [ + "/_mozilla/mozilla/stylesheet-adopt-panic-ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/stylesheet-adopt-panic.html" + } + ], "mozilla/svg/svg.html": [ { "path": "mozilla/svg/svg.html", @@ -21756,6 +21768,18 @@ "url": "/_mozilla/mozilla/sslfail.html" } ], + "mozilla/stylesheet-adopt-panic.html": [ + { + "path": "mozilla/stylesheet-adopt-panic.html", + "references": [ + [ + "/_mozilla/mozilla/stylesheet-adopt-panic-ref.html", + "==" + ] + ], + "url": "/_mozilla/mozilla/stylesheet-adopt-panic.html" + } + ], "mozilla/svg/svg.html": [ { "path": "mozilla/svg/svg.html", diff --git a/tests/wpt/mozilla/tests/mozilla/adopt-panic.css b/tests/wpt/mozilla/tests/mozilla/adopt-panic.css new file mode 100644 index 00000000000..182d72fa7fd --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/adopt-panic.css @@ -0,0 +1,3 @@ +body { + background-color: green; +} \ No newline at end of file diff --git a/tests/wpt/mozilla/tests/mozilla/blank.html b/tests/wpt/mozilla/tests/mozilla/blank.html new file mode 100644 index 00000000000..39654855a82 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/blank.html @@ -0,0 +1,2 @@ + +Blank document diff --git a/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic-ref.html b/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic-ref.html new file mode 100644 index 00000000000..b47617e4249 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic-ref.html @@ -0,0 +1,8 @@ + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic.html b/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic.html new file mode 100644 index 00000000000..df3b48291e0 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic.html @@ -0,0 +1,13 @@ + + +Verify that adopting a stylesheet with an import applies its styles and doesn't panic + + +