diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index ebffed13d01..cb89e707197 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -68,8 +68,9 @@ pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent, let mut iter = DeclarationListParser::new(input, parser); while let Some(declaration) = iter.next() { if let Err((error, slice)) = declaration { + let location = error.location; let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(slice, error); - context.log_css_error(error_context, iter.input.current_source_location(), error) + context.log_css_error(error_context, location, error) } } } diff --git a/components/style/font_face.rs b/components/style/font_face.rs index a4abd587363..15814274a7c 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -124,8 +124,9 @@ pub fn parse_font_face_block(context: &ParserContext, let mut iter = DeclarationListParser::new(input, parser); while let Some(declaration) = iter.next() { if let Err((error, slice)) = declaration { + let location = error.location; let error = ContextualParseError::UnsupportedFontFaceDescriptor(slice, error); - context.log_css_error(error_context, iter.input.current_source_location(), error) + context.log_css_error(error_context, location, error) } } } diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index 599ecd88717..72401166746 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -263,10 +263,11 @@ where }, Err(err) => { media_queries.push(MediaQuery::never_matching()); + let location = err.location; let error = ContextualParseError::InvalidMediaRule( input.slice_from(start_position), err); let error_context = ParserErrorContext { error_reporter }; - context.log_css_error(&error_context, input.current_source_location(), error); + context.log_css_error(&error_context, location, error); }, } diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index e5c14ef030d..47018122857 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1040,10 +1040,11 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaratio PropertyDeclaration::parse_into(declarations, id, name, &context, parser) .map_err(|e| e.into()) }).map_err(|err| { + let location = err.location; let error = ContextualParseError::UnsupportedPropertyDeclaration( parser.slice_from(start_position), err); let error_context = ParserErrorContext { error_reporter: error_reporter }; - context.log_css_error(&error_context, parser.current_source_location(), error); + context.log_css_error(&error_context, location, error); }) } @@ -1131,8 +1132,8 @@ pub fn parse_property_declaration_list(context: &ParserContext, continue; } + let location = error.location; let error = ContextualParseError::UnsupportedPropertyDeclaration(slice, error); - let location = iter.input.current_source_location(); context.log_css_error(error_context, location, error); } } diff --git a/components/style/stylesheets/font_feature_values_rule.rs b/components/style/stylesheets/font_feature_values_rule.rs index a8022ea32c2..cbb11515bce 100644 --- a/components/style/stylesheets/font_feature_values_rule.rs +++ b/components/style/stylesheets/font_feature_values_rule.rs @@ -276,8 +276,8 @@ macro_rules! font_feature_values_blocks { }); while let Some(result) = iter.next() { if let Err((error, slice)) = result { + let location = error.location; let error = ContextualParseError::UnsupportedRule(slice, error); - let location = iter.input.current_source_location(); context.log_css_error(error_context, location, error); } } @@ -430,10 +430,10 @@ macro_rules! font_feature_values_blocks { let mut iter = DeclarationListParser::new(input, parser); while let Some(declaration) = iter.next() { if let Err((error, slice)) = declaration { + let location = error.location; let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration( slice, error ); - let location = iter.input.current_source_location(); self.context.log_css_error(self.error_context, location, error); } } diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index 033ba4e049e..8d6d7d4a319 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -525,8 +525,9 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars }) }, Err(e) => { + let location = e.location; let error = ContextualParseError::InvalidKeyframeRule(input.slice_from(start_position), e.clone()); - self.context.log_css_error(self.error_context, input.current_source_location(), error); + self.context.log_css_error(self.error_context, location, error); Err(e) } } @@ -554,8 +555,9 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars } Err((error, slice)) => { iter.parser.declarations.clear(); + let location = error.location; let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(slice, error); - context.log_css_error(self.error_context, iter.input.current_source_location(), error); + context.log_css_error(self.error_context, location, error); } } // `parse_important` is not called here, `!important` is not allowed in keyframe blocks. diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index a8947a8e528..2368e670557 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -333,8 +333,8 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> { match result { Ok(rule) => rules.push(rule), Err((error, slice)) => { + let location = error.location; let error = ContextualParseError::UnsupportedRule(slice, error); - let location = iter.input.current_source_location(); self.context.log_css_error(self.error_context, location, error); } } diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index fe928024cf3..e8d22e19bb2 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -395,8 +395,8 @@ impl Stylesheet { } }, Err((error, slice)) => { + let location = error.location; let error = ContextualParseError::InvalidRule(slice, error); - let location = iter.input.current_source_location(); iter.parser.context.log_css_error(&iter.parser.error_context, location, error); } diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index 8e02d309fef..b150cdf6128 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -369,8 +369,9 @@ impl ViewportRule { } } Err((error, slice)) => { + let location = error.location; let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(slice, error); - context.log_css_error(error_context, parser.input.current_source_location(), error); + context.log_css_error(error_context, location, error); } } } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index b3e48809f0b..261569d2162 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -323,7 +323,7 @@ fn test_report_error_stylesheet() { background-image: linear-gradient(0deg, black, invalid, transparent); invalid: true; } - @media (min-width: invalid 1000px) {} + @media (min-width: 10px invalid 1000px) {} @font-face { src: url(), invalid, url(); } @counter-style foo { symbols: a 0invalid b } @font-feature-values Sans Sans { @foo {} @swash { foo: 1 invalid 2 } } @@ -342,26 +342,26 @@ fn test_report_error_stylesheet() { None, &error_reporter, QuirksMode::NoQuirks, 5); error_reporter.assert_messages_contain(&[ - (8, 26, "Unsupported property declaration: 'display: invalid;'"), - (9, 78, "Unsupported property declaration: 'background-image:"), - (10, 23, "Unsupported property declaration: 'invalid: true;'"), - (12, 40, "Invalid media rule"), - (13, 45, "Unsupported @font-face descriptor declaration"), + (8, 18, "Unsupported property declaration: 'display: invalid;'"), + (9, 27, "Unsupported property declaration: 'background-image:"), // FIXME: column should be around 56 + (10, 17, "Unsupported property declaration: 'invalid: true;'"), + (12, 28, "Invalid media rule"), + (13, 30, "Unsupported @font-face descriptor declaration"), // When @counter-style is supported, this should be replaced with two errors - (14, 25, "Invalid rule: '@counter-style "), + (14, 19, "Invalid rule: '@counter-style "), // When @font-feature-values is supported, this should be replaced with two errors - (15, 37, "Invalid rule: '@font-feature-values "), + (15, 25, "Invalid rule: '@font-feature-values "), // FIXME: the message of these two should be consistent - (16, 14, "Invalid rule: '@invalid'"), - (17, 30, "Unsupported rule: '@invalid'"), + (16, 13, "Invalid rule: '@invalid'"), + (17, 29, "Unsupported rule: '@invalid'"), - (18, 59, "Invalid rule: '@supports "), - (19, 35, "Invalid keyframe rule: 'from invalid '"), - (19, 63, "Unsupported keyframe property declaration: 'margin: 0 invalid 0;'"), - (20, 43, "Unsupported @viewport descriptor declaration: 'width: 320px invalid auto;'"), + (18, 34, "Invalid rule: '@supports "), + (19, 26, "Invalid keyframe rule: 'from invalid '"), + (19, 52, "Unsupported keyframe property declaration: 'margin: 0 invalid 0;'"), + (20, 29, "Unsupported @viewport descriptor declaration: 'width: 320px invalid auto;'"), ]); assert_eq!(error_reporter.errors.borrow()[0].url, url); @@ -385,7 +385,7 @@ fn test_no_report_unrecognized_vendor_properties() { None, &error_reporter, QuirksMode::NoQuirks, 0); error_reporter.assert_messages_contain(&[ - (4, 36, "Unsupported property declaration: '-moz-background-color: red;'"), + (4, 31, "Unsupported property declaration: '-moz-background-color: red;'"), ]); }