mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Auto merge of #16394 - mckaymatt:line_num_offset__issue_15693, r=SimonSapin
Support line number offsets for inline stylesheets <!-- Please describe your changes on the following line: --> This allows accurate line numbers when reporting stylesheet errors. @jdm This is going to require some effort to merge my changes with other recent changes to `ParserContext`. Because of that I would appreciate a quick sanity check before I put the time into performing the merge. For example, should I store the `offset` as a u64, or should it be an Option? --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15693 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16394) <!-- Reviewable:end -->
This commit is contained in:
commit
94397ff0b4
11 changed files with 87 additions and 37 deletions
|
@ -19,8 +19,12 @@ use style_traits::ToCss;
|
|||
pub struct CSSErrorReporterTest;
|
||||
|
||||
impl ParseErrorReporter for CSSErrorReporterTest {
|
||||
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str,
|
||||
_url: &ServoUrl) {
|
||||
fn report_error(&self,
|
||||
_input: &mut Parser,
|
||||
_position: SourcePosition,
|
||||
_message: &str,
|
||||
_url: &ServoUrl,
|
||||
_line_number_offset: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +37,7 @@ fn test_media_rule<F>(css: &str, callback: F)
|
|||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut rule_count = 0;
|
||||
let guard = stylesheet.shared_lock.read();
|
||||
media_queries(&guard, &stylesheet.rules.read_with(&guard).0, &mut |mq| {
|
||||
|
@ -62,7 +66,7 @@ fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
|
|||
let media_list = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let ss = Stylesheet::from_str(
|
||||
css, url, Origin::Author, media_list, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut rule_count = 0;
|
||||
ss.effective_style_rules(device, &ss.shared_lock.read(), |_| rule_count += 1);
|
||||
assert!(rule_count == expected_rule_count, css.to_owned());
|
||||
|
|
|
@ -16,9 +16,15 @@ use test::{self, Bencher};
|
|||
|
||||
struct ErrorringErrorReporter;
|
||||
impl ParseErrorReporter for ErrorringErrorReporter {
|
||||
fn report_error(&self, _input: &mut Parser, position: SourcePosition, message: &str,
|
||||
url: &ServoUrl) {
|
||||
panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message);
|
||||
fn report_error(&self,
|
||||
input: &mut Parser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl,
|
||||
line_number_offset: u64) {
|
||||
let location = input.source_location(position);
|
||||
let line_offset = location.line + line_number_offset as usize;
|
||||
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), line_offset, location.column, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +57,8 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
|
|||
media,
|
||||
lock,
|
||||
None,
|
||||
&ErrorringErrorReporter);
|
||||
&ErrorringErrorReporter,
|
||||
0u64);
|
||||
let guard = s.shared_lock.read();
|
||||
let rules = s.rules.read_with(&guard);
|
||||
rules.0.iter().filter_map(|rule| {
|
||||
|
|
|
@ -65,7 +65,7 @@ fn test_parse_stylesheet() {
|
|||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &CSSErrorReporterTest);
|
||||
None, &CSSErrorReporterTest, 0u64);
|
||||
let mut namespaces = Namespaces::default();
|
||||
namespaces.default = Some(ns!(html));
|
||||
let expected = Stylesheet {
|
||||
|
@ -293,16 +293,17 @@ impl ParseErrorReporter for CSSInvalidErrorReporterTest {
|
|||
input: &mut CssParser,
|
||||
position: SourcePosition,
|
||||
message: &str,
|
||||
url: &ServoUrl) {
|
||||
url: &ServoUrl,
|
||||
line_number_offset: u64) {
|
||||
|
||||
let location = input.source_location(position);
|
||||
let line_offset = location.line + line_number_offset as usize;
|
||||
|
||||
let mut errors = self.errors.lock().unwrap();
|
||||
|
||||
errors.push(
|
||||
CSSError{
|
||||
url: url.clone(),
|
||||
line: location.line,
|
||||
line: line_offset,
|
||||
column: location.column,
|
||||
message: message.to_owned()
|
||||
}
|
||||
|
@ -328,18 +329,18 @@ fn test_report_error_stylesheet() {
|
|||
let lock = SharedRwLock::new();
|
||||
let media = Arc::new(lock.wrap(MediaList::empty()));
|
||||
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, media, lock,
|
||||
None, &error_reporter);
|
||||
None, &error_reporter, 5u64);
|
||||
|
||||
let mut errors = errors.lock().unwrap();
|
||||
|
||||
let error = errors.pop().unwrap();
|
||||
assert_eq!("Unsupported property declaration: 'invalid: true;'", error.message);
|
||||
assert_eq!(5, error.line);
|
||||
assert_eq!(10, error.line);
|
||||
assert_eq!(9, error.column);
|
||||
|
||||
let error = errors.pop().unwrap();
|
||||
assert_eq!("Unsupported property declaration: 'display: invalid;'", error.message);
|
||||
assert_eq!(4, error.line);
|
||||
assert_eq!(9, error.line);
|
||||
assert_eq!(9, error.column);
|
||||
|
||||
// testing for the url
|
||||
|
|
|
@ -31,7 +31,8 @@ macro_rules! stylesheet {
|
|||
Arc::new($shared_lock.wrap(MediaList::empty())),
|
||||
$shared_lock,
|
||||
None,
|
||||
&$error_reporter
|
||||
&$error_reporter,
|
||||
0u64
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue