mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
geckolib: Allow Servo_ComputeColor to report errors to the console.
This commit is contained in:
parent
7015d5b22e
commit
9a31d0d8d8
1 changed files with 34 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cssparser::{Parser, ParserInput};
|
use cssparser::{ParseErrorKind, Parser, ParserInput};
|
||||||
use cssparser::ToCss as ParserToCss;
|
use cssparser::ToCss as ParserToCss;
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
use malloc_size_of::MallocSizeOfOps;
|
use malloc_size_of::MallocSizeOfOps;
|
||||||
|
@ -23,7 +23,7 @@ use style::data::{ElementStyles, self};
|
||||||
use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
|
use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
|
||||||
use style::driver;
|
use style::driver;
|
||||||
use style::element_state::{DocumentState, ElementState};
|
use style::element_state::{DocumentState, ElementState};
|
||||||
use style::error_reporting::{NullReporter, ParseErrorReporter};
|
use style::error_reporting::{ContextualParseError, NullReporter, ParseErrorReporter};
|
||||||
use style::font_metrics::{FontMetricsProvider, get_metrics_provider_for_product};
|
use style::font_metrics::{FontMetricsProvider, get_metrics_provider_for_product};
|
||||||
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||||
use style::gecko::global_style_data::{GLOBAL_STYLE_DATA, GlobalStyleData, STYLE_THREAD_POOL};
|
use style::gecko::global_style_data::{GLOBAL_STYLE_DATA, GlobalStyleData, STYLE_THREAD_POOL};
|
||||||
|
@ -153,7 +153,7 @@ use style::values::distance::ComputeSquaredDistance;
|
||||||
use style::values::specified;
|
use style::values::specified;
|
||||||
use style::values::specified::gecko::IntersectionObserverRootMargin;
|
use style::values::specified::gecko::IntersectionObserverRootMargin;
|
||||||
use style::values::specified::source_size_list::SourceSizeList;
|
use style::values::specified::source_size_list::SourceSizeList;
|
||||||
use style_traits::{ParsingMode, ToCss};
|
use style_traits::{ParsingMode, StyleParseErrorKind, ToCss};
|
||||||
use super::error_reporter::ErrorReporter;
|
use super::error_reporter::ErrorReporter;
|
||||||
use super::stylesheet_loader::StylesheetLoader;
|
use super::stylesheet_loader::StylesheetLoader;
|
||||||
|
|
||||||
|
@ -4557,10 +4557,31 @@ pub unsafe extern "C" fn Servo_SelectorList_Drop(list: RawServoSelectorListOwned
|
||||||
let _ = list.into_box::<::selectors::SelectorList<SelectorImpl>>();
|
let _ = list.into_box::<::selectors::SelectorList<SelectorImpl>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_color(value: &str) -> Result<specified::Color, ()> {
|
fn parse_color(
|
||||||
|
value: &str,
|
||||||
|
error_reporter: Option<&ErrorReporter>,
|
||||||
|
) -> Result<specified::Color, ()> {
|
||||||
let mut input = ParserInput::new(value);
|
let mut input = ParserInput::new(value);
|
||||||
let mut parser = Parser::new(&mut input);
|
let mut parser = Parser::new(&mut input);
|
||||||
parser.parse_entirely(specified::Color::parse_color).map_err(|_| ())
|
let start_position = parser.position();
|
||||||
|
parser.parse_entirely(specified::Color::parse_color).map_err(|err| {
|
||||||
|
if let Some(error_reporter) = error_reporter {
|
||||||
|
match err.kind {
|
||||||
|
ParseErrorKind::Custom(StyleParseErrorKind::ValueError(..)) => {
|
||||||
|
let location = err.location.clone();
|
||||||
|
let error = ContextualParseError::UnsupportedValue(
|
||||||
|
parser.slice_from(start_position),
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
error_reporter.report(location, error);
|
||||||
|
}
|
||||||
|
// Ignore other kinds of errors that might be reported, such as
|
||||||
|
// ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken),
|
||||||
|
// since Gecko doesn't report those to the error console.
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -4568,7 +4589,7 @@ pub extern "C" fn Servo_IsValidCSSColor(
|
||||||
value: *const nsAString,
|
value: *const nsAString,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let value = unsafe { (*value).to_string() };
|
let value = unsafe { (*value).to_string() };
|
||||||
parse_color(&value).is_ok()
|
parse_color(&value, None).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -4578,6 +4599,7 @@ pub extern "C" fn Servo_ComputeColor(
|
||||||
value: *const nsAString,
|
value: *const nsAString,
|
||||||
result_color: *mut structs::nscolor,
|
result_color: *mut structs::nscolor,
|
||||||
was_current_color: *mut bool,
|
was_current_color: *mut bool,
|
||||||
|
loader: *mut Loader,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
use style::gecko;
|
use style::gecko;
|
||||||
|
|
||||||
|
@ -4585,7 +4607,12 @@ pub extern "C" fn Servo_ComputeColor(
|
||||||
let value = unsafe { (*value).to_string() };
|
let value = unsafe { (*value).to_string() };
|
||||||
let result_color = unsafe { result_color.as_mut().unwrap() };
|
let result_color = unsafe { result_color.as_mut().unwrap() };
|
||||||
|
|
||||||
match parse_color(&value) {
|
let reporter = unsafe { loader.as_mut() }.map(|loader| {
|
||||||
|
// Make an ErrorReporter that will report errors as being "from DOM".
|
||||||
|
ErrorReporter::new(ptr::null_mut(), loader, ptr::null_mut())
|
||||||
|
});
|
||||||
|
|
||||||
|
match parse_color(&value, reporter.as_ref()) {
|
||||||
Ok(specified_color) => {
|
Ok(specified_color) => {
|
||||||
let computed_color = match raw_data {
|
let computed_color = match raw_data {
|
||||||
Some(raw_data) => {
|
Some(raw_data) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue