Skip to content

Commit

Permalink
Removing style element's styles when elements is removed from dom
Browse files Browse the repository at this point in the history
  • Loading branch information
zaynetro committed Jan 22, 2017
1 parent b3ce08f commit f0c72cb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
11 changes: 10 additions & 1 deletion components/script/dom/htmlstyleelement.rs
Expand Up @@ -15,7 +15,7 @@ use dom::document::Document;
use dom::element::{Element, ElementCreator};
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
use dom::node::{ChildrenMutation, Node, document_from_node, window_from_node};
use dom::node::{ChildrenMutation, Node, UnbindContext, document_from_node, window_from_node};
use dom::stylesheet::StyleSheet as DOMStyleSheet;
use dom::virtualmethods::VirtualMethods;
use html5ever_atoms::LocalName;
Expand Down Expand Up @@ -161,6 +161,15 @@ impl VirtualMethods for HTMLStyleElement {
self.parse_own_css();
}
}

fn unbind_from_tree(&self, context: &UnbindContext) {
if let Some(ref s) = self.super_type() {
s.unbind_from_tree(context);
}

let doc = document_from_node(self);
doc.invalidate_stylesheets();
}
}

impl StylesheetOwner for HTMLStyleElement {
Expand Down
24 changes: 24 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -6474,6 +6474,18 @@
"url": "/_mozilla/mozilla/remove_link_styles.html"
}
],
"mozilla/remove_style_styles.html": [
{
"path": "mozilla/remove_style_styles.html",
"references": [
[
"/_mozilla/mozilla/remove_style_styles_ref.html",
"=="
]
],
"url": "/_mozilla/mozilla/remove_style_styles.html"
}
],
"mozilla/reparse_style_elements.html": [
{
"path": "mozilla/reparse_style_elements.html",
Expand Down Expand Up @@ -21876,6 +21888,18 @@
"url": "/_mozilla/mozilla/remove_link_styles.html"
}
],
"mozilla/remove_style_styles.html": [
{
"path": "mozilla/remove_style_styles.html",
"references": [
[
"/_mozilla/mozilla/remove_style_styles_ref.html",
"=="
]
],
"url": "/_mozilla/mozilla/remove_style_styles.html"
}
],
"mozilla/reparse_style_elements.html": [
{
"path": "mozilla/reparse_style_elements.html",
Expand Down
20 changes: 20 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/remove_style_styles.html
@@ -0,0 +1,20 @@
<!doctype html>
<meta charset="utf-8">
<title>Removing style element should remove all associated styles</title>
<link rel="match" href="remove_style_styles_ref.html">
<body>
<style>
body {
background-color: red;
}
</style>

This text should be black and the background should not be red.

<script>
// Force restyling
window.getComputedStyle(document.body);
var s = document.querySelector('style');
s.parentNode.removeChild(s);
</script>
</body>
5 changes: 5 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/remove_style_styles_ref.html
@@ -0,0 +1,5 @@
<!doctype html>
<meta charset="utf-8">
<body>
This text should be black and the background should not be red.
</body>

0 comments on commit f0c72cb

Please sign in to comment.