From 95cbf1a885da6125665b73ab1829ac229e6db822 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 22 Nov 2016 09:08:14 -0800 Subject: [PATCH] Address review comments --- components/script/dom/cssstylesheet.rs | 1 + components/style/stylesheets.rs | 27 ++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/components/script/dom/cssstylesheet.rs b/components/script/dom/cssstylesheet.rs index 8ebe11b8d98..2e2ac45d867 100644 --- a/components/script/dom/cssstylesheet.rs +++ b/components/script/dom/cssstylesheet.rs @@ -54,6 +54,7 @@ impl CSSStyleSheetMethods for CSSStyleSheet { // https://drafts.csswg.org/cssom/#dom-cssstylesheet-cssrules fn CssRules(&self) -> Root { // XXXManishearth check origin clean flag + // https://github.com/servo/servo/issues/14327 self.rulelist() } diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index ba5e5a43989..6e057e26f37 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -74,13 +74,15 @@ impl CssRules { // Provides the parser state at a given insertion index pub fn state_at_index(rules: &[CssRule], at: usize) -> State { let mut state = State::Start; - for rule in rules.iter().take(at) { - state = match *rule { - // CssRule::Charset(..) => State::Start, - // CssRule::Import(..) => State::Imports, - CssRule::Namespace(..) => State::Namespaces, - _ => State::Body, - }; + if at > 0 { + if let Some(rule) = rules.get(at - 1) { + state = match *rule { + // CssRule::Charset(..) => State::Start, + // CssRule::Import(..) => State::Imports, + CssRule::Namespace(..) => State::Namespaces, + _ => State::Body, + }; + } } state } @@ -89,16 +91,16 @@ impl CssRules { // searching in reverse. If inserting at this index, the parser // must not be in a state greater than this post-insertion. pub fn state_at_index_rev(rules: &[CssRule], at: usize) -> State { - let mut state = State::Body; - for rule in rules.iter().skip(at).rev() { - state = match *rule { + if let Some(rule) = rules.get(at) { + match *rule { // CssRule::Charset(..) => State::Start, // CssRule::Import(..) => State::Imports, CssRule::Namespace(..) => State::Namespaces, _ => State::Body, - }; + } + } else { + State::Body } - state } } @@ -193,6 +195,7 @@ impl CssRule { // nested rules are in the body state let state = state.unwrap_or(State::Body); let mut rule_parser = TopLevelRuleParser { + stylesheet_origin: origin, context: context, state: Cell::new(state), namespaces: &mut namespaces,