geckolib: Allow an ErrorReporter to be created with null URL data.
draft
geckolib: Allow an ErrorReporter to be created with null URL data.
This allows us to create an ErrorReporter that will report errors as being
"from DOM" rather than a specific URL.
Also, factor out a method on ErrorReporter so that we don't need to pass in
a UrlExtraData reference.
MozReview-Commit-ID: 6V2VHdRfVEb
--- a/servo/ports/geckolib/error_reporter.rs
+++ b/servo/ports/geckolib/error_reporter.rs
@@ -11,33 +11,34 @@ use cssparser::{SourceLocation, ParseErr
use selectors::parser::SelectorParseErrorKind;
use std::ptr;
use style::error_reporting::{ParseErrorReporter, ContextualParseError};
use style::gecko_bindings::bindings::{Gecko_CreateCSSErrorReporter, Gecko_DestroyCSSErrorReporter};
use style::gecko_bindings::bindings::Gecko_ReportUnexpectedCSSError;
use style::gecko_bindings::structs::{Loader, ServoStyleSheet, nsIURI};
use style::gecko_bindings::structs::ErrorReporter as GeckoErrorReporter;
use style::gecko_bindings::structs::URLExtraData as RawUrlExtraData;
-use style::gecko_bindings::sugar::refptr::RefPtr;
use style::stylesheets::UrlExtraData;
use style_traits::StyleParseErrorKind;
pub type ErrorKind<'i> = ParseErrorKind<'i, StyleParseErrorKind<'i>>;
/// Wrapper around an instance of Gecko's CSS error reporter.
pub struct ErrorReporter(*mut GeckoErrorReporter);
impl ErrorReporter {
/// Create a new instance of the Gecko error reporter.
pub fn new(sheet: *mut ServoStyleSheet,
loader: *mut Loader,
- url: *mut RawUrlExtraData) -> ErrorReporter {
+ extra_data: *mut RawUrlExtraData) -> ErrorReporter {
unsafe {
- let url = RefPtr::from_ptr_ref(&url);
- ErrorReporter(Gecko_CreateCSSErrorReporter(sheet, loader, url.mBaseURI.raw::<nsIURI>()))
+ let url = extra_data.as_ref()
+ .map(|d| d.mBaseURI.raw::<nsIURI>())
+ .unwrap_or(ptr::null_mut());
+ ErrorReporter(Gecko_CreateCSSErrorReporter(sheet, loader, url))
}
}
}
impl Drop for ErrorReporter {
fn drop(&mut self) {
unsafe {
Gecko_DestroyCSSErrorReporter(self.0);
@@ -359,21 +360,18 @@ impl<'a> ErrorHelpers<'a> for Contextual
ContextualParseError::UnsupportedFontFeatureValuesDescriptor(..) |
ContextualParseError::InvalidFontFeatureValuesRule(..) =>
(b"PEUnknownAtRule\0", Action::Skip),
};
(None, msg, action)
}
}
-impl ParseErrorReporter for ErrorReporter {
- fn report_error(&self,
- _url: &UrlExtraData,
- location: SourceLocation,
- error: ContextualParseError) {
+impl ErrorReporter {
+ pub fn report(&self, location: SourceLocation, error: ContextualParseError) {
let (pre, name, action) = error.to_gecko_message();
let suffix = match action {
Action::Nothing => ptr::null(),
Action::Skip => b"PEDeclSkipped\0".as_ptr(),
Action::Drop => b"PEDeclDropped\0".as_ptr(),
};
let params = error.error_params();
let param = params.main_param;
@@ -395,8 +393,19 @@ impl ParseErrorReporter for ErrorReporte
suffix as *const _,
source.as_ptr() as *const _,
source.len() as u32,
location.line,
location.column);
}
}
}
+
+impl ParseErrorReporter for ErrorReporter {
+ fn report_error(
+ &self,
+ _url: &UrlExtraData,
+ location: SourceLocation,
+ error: ContextualParseError
+ ) {
+ self.report(location, error)
+ }
+}