mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
script: mark innerHTML
as fallible in ShadowRoot
(#38565)
This is a follow-up to #38532 which simply defaulted to an empty string as the spec's WebIDL doesn't mark `innerHTML` as `Throws`. However, since the absence of `Throws` in the spec doesn't imply no-throw, we can mark this as fallible in our WebIDL. This makes the `ShadowRoot`'s implementation match `Element`'s `innerHTML`. Testing: Same as #38532. Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
86d7f4c793
commit
21717158eb
3 changed files with 10 additions and 12 deletions
|
@ -9,7 +9,7 @@ use std::collections::hash_map::Entry;
|
|||
use dom_struct::dom_struct;
|
||||
use html5ever::serialize::TraversalScope;
|
||||
use js::rust::{HandleValue, MutableHandleValue};
|
||||
use script_bindings::error::ErrorResult;
|
||||
use script_bindings::error::{ErrorResult, Fallible};
|
||||
use script_bindings::script_runtime::JSContext;
|
||||
use servo_arc::Arc;
|
||||
use style::author_styles::AuthorStyles;
|
||||
|
@ -459,17 +459,15 @@ impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
|
|||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-innerhtml>
|
||||
fn InnerHTML(&self, can_gc: CanGc) -> DOMString {
|
||||
fn GetInnerHTML(&self, can_gc: CanGc) -> Fallible<DOMString> {
|
||||
// ShadowRoot's innerHTML getter steps are to return the result of running fragment serializing
|
||||
// algorithm steps with this and true.
|
||||
self.upcast::<Node>()
|
||||
.fragment_serialization_algorithm(true, can_gc)
|
||||
.inspect_err(|error| warn!("fragment serialization failed: {error:?}"))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-innerhtml>
|
||||
fn SetInnerHTML(&self, value: DOMString, can_gc: CanGc) {
|
||||
fn SetInnerHTML(&self, value: DOMString, can_gc: CanGc) -> ErrorResult {
|
||||
// TODO Step 1. Let compliantString be the result of invoking the Get Trusted Type compliant string algorithm
|
||||
// with TrustedHTML, this's relevant global object, the given value, "ShadowRoot innerHTML", and "script".
|
||||
let compliant_string = value;
|
||||
|
@ -479,14 +477,14 @@ impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
|
|||
|
||||
// Step 3. Let fragment be the result of invoking the fragment parsing algorithm steps with context and
|
||||
// compliantString.
|
||||
let Ok(frag) = context.parse_fragment(compliant_string, can_gc) else {
|
||||
// NOTE: The spec doesn't strictly tell us to bail out here, but
|
||||
// we can't continue if parsing failed
|
||||
return;
|
||||
};
|
||||
//
|
||||
// NOTE: The spec doesn't strictly tell us to bail out here, but
|
||||
// we can't continue if parsing failed
|
||||
let frag = context.parse_fragment(compliant_string, can_gc)?;
|
||||
|
||||
// Step 4. Replace all with fragment within this.
|
||||
Node::replace_all(Some(frag.upcast()), self.upcast(), can_gc);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#dom-shadowroot-slotassignment>
|
||||
|
|
|
@ -587,7 +587,7 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'ShadowRoot': {
|
||||
'canGc': ['SetHTMLUnsafe', 'SetInnerHTML', 'GetHTML', 'InnerHTML', 'AdoptedStyleSheets'],
|
||||
'canGc': ['SetHTMLUnsafe', 'SetInnerHTML', 'GetHTML', 'GetInnerHTML', 'AdoptedStyleSheets'],
|
||||
},
|
||||
|
||||
'StaticRange': {
|
||||
|
|
|
@ -29,5 +29,5 @@ partial interface ShadowRoot {
|
|||
DOMString getHTML(optional GetHTMLOptions options = {});
|
||||
|
||||
// [CEReactions] attribute (TrustedHTML or [LegacyNullToEmptyString] DOMString) innerHTML;
|
||||
[CEReactions] attribute [LegacyNullToEmptyString] DOMString innerHTML;
|
||||
[CEReactions, Throws] attribute [LegacyNullToEmptyString] DOMString innerHTML;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue