Skip to content

Commit 98d0fb2

Browse files
committed
Thread ParseError return values through CSS parsing.
1 parent 58e39bf commit 98d0fb2

111 files changed

Lines changed: 2075 additions & 1458 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ opt-level = 3
1919
# crate, add that here. Use the form:
2020
#
2121
# "<crate>:<version>" = { path = "/path/to/local/checkout" }
22+
"cssparser:0.13.7" = { git = 'https://github.com/jdm/rust-cssparser', branch = 'err2' }

components/script/dom/canvasgradient.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use canvas_traits::{CanvasGradientStop, FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle};
6-
use cssparser::{Parser, RGBA};
6+
use cssparser::{Parser, ParserInput, RGBA};
77
use cssparser::Color as CSSColor;
88
use dom::bindings::cell::DOMRefCell;
99
use dom::bindings::codegen::Bindings::CanvasGradientBinding;
@@ -53,7 +53,8 @@ impl CanvasGradientMethods for CanvasGradient {
5353
return Err(Error::IndexSize);
5454
}
5555

56-
let mut parser = Parser::new(&color);
56+
let mut input = ParserInput::new(&color);
57+
let mut parser = Parser::new(&mut input);
5758
let color = CSSColor::parse(&mut parser);
5859
let color = if parser.is_exhausted() {
5960
match color {

components/script/dom/canvasrenderingcontext2d.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use canvas_traits::{Canvas2dMsg, CanvasCommonMsg, CanvasMsg};
66
use canvas_traits::{CompositionOrBlending, FillOrStrokeStyle, FillRule};
77
use canvas_traits::{LineCapStyle, LineJoinStyle, LinearGradientStyle};
88
use canvas_traits::{RadialGradientStyle, RepetitionStyle, byte_swap_and_premultiply};
9-
use cssparser::{Parser, RGBA};
9+
use cssparser::{Parser, ParserInput, RGBA};
1010
use cssparser::Color as CSSColor;
1111
use dom::bindings::cell::DOMRefCell;
1212
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
@@ -463,7 +463,8 @@ impl CanvasRenderingContext2D {
463463
}
464464

465465
fn parse_color(&self, string: &str) -> Result<RGBA, ()> {
466-
let mut parser = Parser::new(&string);
466+
let mut input = ParserInput::new(string);
467+
let mut parser = Parser::new(&mut input);
467468
let color = CSSColor::parse(&mut parser);
468469
if parser.is_exhausted() {
469470
match color {
@@ -1314,7 +1315,8 @@ impl Drop for CanvasRenderingContext2D {
13141315
}
13151316

13161317
pub fn parse_color(string: &str) -> Result<RGBA, ()> {
1317-
let mut parser = Parser::new(&string);
1318+
let mut input = ParserInput::new(string);
1319+
let mut parser = Parser::new(&mut input);
13181320
match CSSColor::parse(&mut parser) {
13191321
Ok(CSSColor::RGBA(rgba)) => {
13201322
if parser.is_exhausted() {

components/script/dom/css.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use cssparser::{Parser, serialize_identifier};
5+
use cssparser::{Parser, ParserInput, serialize_identifier};
66
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
77
use dom::bindings::error::Fallible;
88
use dom::bindings::reflector::Reflector;
@@ -39,7 +39,8 @@ impl CSS {
3939

4040
/// https://drafts.csswg.org/css-conditional/#dom-css-supports
4141
pub fn Supports_(win: &Window, condition: DOMString) -> bool {
42-
let mut input = Parser::new(&condition);
42+
let mut input = ParserInput::new(&condition);
43+
let mut input = Parser::new(&mut input);
4344
let cond = parse_condition_or_declaration(&mut input);
4445
if let Ok(cond) = cond {
4546
let url = win.Document().url();

components/script/dom/csskeyframesrule.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use cssparser::Parser;
5+
use cssparser::{Parser, ParserInput};
66
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding;
77
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods;
88
use dom::bindings::error::ErrorResult;
@@ -58,7 +58,8 @@ impl CSSKeyframesRule {
5858

5959
/// Given a keyframe selector, finds the index of the first corresponding rule if any
6060
fn find_rule(&self, selector: &str) -> Option<usize> {
61-
let mut input = Parser::new(selector);
61+
let mut input = ParserInput::new(selector);
62+
let mut input = Parser::new(&mut input);
6263
if let Ok(sel) = KeyframeSelector::parse(&mut input) {
6364
let guard = self.cssrule.shared_lock().read();
6465
// This finds the *last* element matching a selector

components/script/dom/cssmediarule.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use cssparser::Parser;
5+
use cssparser::{Parser, ParserInput};
66
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding;
77
use dom::bindings::codegen::Bindings::CSSMediaRuleBinding::CSSMediaRuleMethods;
88
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
@@ -69,7 +69,8 @@ impl CSSMediaRule {
6969

7070
/// https://drafts.csswg.org/css-conditional-3/#the-cssmediarule-interface
7171
pub fn set_condition_text(&self, text: DOMString) {
72-
let mut input = Parser::new(&text);
72+
let mut input = ParserInput::new(&text);
73+
let mut input = Parser::new(&mut input);
7374
let global = self.global();
7475
let win = global.as_window();
7576
let url = win.get_url();

components/script/dom/csssupportsrule.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use cssparser::Parser;
5+
use cssparser::{Parser, ParserInput};
66
use dom::bindings::codegen::Bindings::CSSSupportsRuleBinding;
77
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
88
use dom::bindings::js::Root;
@@ -55,7 +55,8 @@ impl CSSSupportsRule {
5555

5656
/// https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
5757
pub fn set_condition_text(&self, text: DOMString) {
58-
let mut input = Parser::new(&text);
58+
let mut input = ParserInput::new(&text);
59+
let mut input = Parser::new(&mut input);
5960
let cond = SupportsCondition::parse(&mut input);
6061
if let Ok(cond) = cond {
6162
let global = self.global();

components/script/dom/element.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ impl ElementMethods for Element {
20612061
// https://dom.spec.whatwg.org/#dom-element-matches
20622062
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
20632063
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
2064-
Err(()) => Err(Error::Syntax),
2064+
Err(_) => Err(Error::Syntax),
20652065
Ok(selectors) => {
20662066
let mut ctx = MatchingContext::new(MatchingMode::Normal, None);
20672067
Ok(matches_selector_list(&selectors, &Root::from_ref(self), &mut ctx))
@@ -2077,7 +2077,7 @@ impl ElementMethods for Element {
20772077
// https://dom.spec.whatwg.org/#dom-element-closest
20782078
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
20792079
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
2080-
Err(()) => Err(Error::Syntax),
2080+
Err(_) => Err(Error::Syntax),
20812081
Ok(selectors) => {
20822082
let root = self.upcast::<Node>();
20832083
for element in root.inclusive_ancestors() {

components/script/dom/htmllinkelement.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use cssparser::Parser as CssParser;
5+
use cssparser::{Parser as CssParser, ParserInput};
66
use dom::attr::Attr;
77
use dom::bindings::cell::DOMRefCell;
88
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListBinding::DOMTokenListMethods;
@@ -278,7 +278,8 @@ impl HTMLLinkElement {
278278
None => "",
279279
};
280280

281-
let mut css_parser = CssParser::new(&mq_str);
281+
let mut input = ParserInput::new(&mq_str);
282+
let mut css_parser = CssParser::new(&mut input);
282283
let win = document.window();
283284
let doc_url = document.url();
284285
let context = CssParserContext::new_for_cssom(&doc_url, win.css_error_reporter(), Some(CssRuleType::Media),

0 commit comments

Comments
 (0)