aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/cssstyledeclaration.rs5
-rw-r--r--tests/wpt/mozilla/tests/mozilla/getComputedStyle.html6
2 files changed, 11 insertions, 0 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index 99e70f9c387..180a356dd90 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -99,6 +99,11 @@ impl<'a> PrivateCSSStyleDeclarationHelpers for &'a CSSStyleDeclaration {
fn get_computed_style(self, property: &Atom) -> Option<DOMString> {
let owner = self.owner.root();
let node = NodeCast::from_ref(owner.r());
+ if !node.is_in_doc() {
+ // TODO: Node should be matched against the style rules of this window.
+ // Firefox is currently the only browser to implement this.
+ return None;
+ }
let addr = node.to_trusted_node_address();
window_from_node(owner.r()).resolved_style_query(addr, self.pseudo.clone(), property)
}
diff --git a/tests/wpt/mozilla/tests/mozilla/getComputedStyle.html b/tests/wpt/mozilla/tests/mozilla/getComputedStyle.html
index 410a8fd79c6..b3b3a3c8112 100644
--- a/tests/wpt/mozilla/tests/mozilla/getComputedStyle.html
+++ b/tests/wpt/mozilla/tests/mozilla/getComputedStyle.html
@@ -40,6 +40,12 @@
assert_equals(getComputedStyle(div, '::after').getPropertyValue("color"), "");
}, "Missing :after pseudoelement");
+ test(function() {
+ var div = document.createElement("div");
+ div.id = "foo";
+ assert_equals(getComputedStyle(div).getPropertyValue("width"), "");
+ }, "Blank style for elements not in a document");
+
</script>
</body>
</html>