mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Implement CSSStyleSheet::replaceSync (#36586)
Implements the `replaceSync` method on CSSStyleSheet Testing: Covered by wpt tests. Expectations are updated. Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
5d3cbc67ee
commit
30fdf48ca6
12 changed files with 47 additions and 162 deletions
|
@ -93,6 +93,7 @@ pub(crate) fn throw_dom_exception(
|
|||
Error::NotReadable => DOMErrorName::NotReadableError,
|
||||
Error::Data => DOMErrorName::DataError,
|
||||
Error::Operation => DOMErrorName::OperationError,
|
||||
Error::NotAllowed => DOMErrorName::NotAllowedError,
|
||||
Error::Type(message) => unsafe {
|
||||
assert!(!JS_IsExceptionPending(*cx));
|
||||
throw_type_error(*cx, &message);
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::dom::bindings::reflector::{
|
|||
DomGlobal, reflect_dom_object, reflect_dom_object_with_proto,
|
||||
};
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::str::{DOMString, USVString};
|
||||
use crate::dom::cssrulelist::{CSSRuleList, RulesSource};
|
||||
use crate::dom::element::Element;
|
||||
use crate::dom::medialist::MediaList;
|
||||
|
@ -290,4 +290,32 @@ impl CSSStyleSheetMethods<crate::DomTypeHolder> for CSSStyleSheet {
|
|||
// > 8. Return -1.
|
||||
Ok(-1)
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/cssom/#synchronously-replace-the-rules-of-a-cssstylesheet>
|
||||
fn ReplaceSync(&self, text: USVString) -> Result<(), Error> {
|
||||
// Step 1. If the constructed flag is not set throw a NotAllowedError
|
||||
if !self.is_constructed {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
// Step 2. Let rules be the result of running parse a stylesheet’s contents from text.
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
|
||||
StyleStyleSheet::update_from_str(
|
||||
&self.style_stylesheet,
|
||||
&text,
|
||||
UrlExtraData(window.get_url().get_arc()),
|
||||
None,
|
||||
window.css_error_reporter(),
|
||||
AllowImportRules::No, // Step 3.If rules contains one or more @import rules, remove those rules from rules.
|
||||
);
|
||||
|
||||
// Step 4. Set sheet’s CSS rules to rules.
|
||||
// We reset our rule list, which will be initialized properly
|
||||
// at the next getter access.
|
||||
self.rulelist.set(None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ pub(crate) enum DOMErrorName {
|
|||
NotReadableError,
|
||||
DataError,
|
||||
OperationError,
|
||||
NotAllowedError,
|
||||
}
|
||||
|
||||
impl DOMErrorName {
|
||||
|
@ -84,6 +85,7 @@ impl DOMErrorName {
|
|||
"NotReadableError" => Some(DOMErrorName::NotReadableError),
|
||||
"DataError" => Some(DOMErrorName::DataError),
|
||||
"OperationError" => Some(DOMErrorName::OperationError),
|
||||
"NotAllowedError" => Some(DOMErrorName::NotAllowedError),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +137,10 @@ impl DOMException {
|
|||
DOMErrorName::OperationError => {
|
||||
"The operation failed for an operation-specific reason."
|
||||
},
|
||||
DOMErrorName::NotAllowedError => {
|
||||
r#"The request is not allowed by the user agent or the platform in the current context,
|
||||
possibly because the user denied permission."#
|
||||
},
|
||||
};
|
||||
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue