mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement all trusted sinks in HTMLScriptElement
(#36668)
As a follow-up to the recent introduction of `script.src` as trusted sink, this PR refactors machinery to also support `TrustedScript`. In doing so, all trusted sinks in `HTMLScriptElement` are now covered. Instead of calling the callbacks in `policy.createX`, we now have a `TrustedType` enum that specifies which callback to invoke. Unfortunately we still have the `USVString` vs `DOMString` problem, which is why we need to `.map` twice to retrieve the backing `String` and avoid two different types. Additionally, I saw that `script.text` should have called the "String replace all" algorithm rather than setting the child contents. So that's also now fixed. Part of #36258 Requires servo/html5ever#608 Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com> Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
parent
dd63325f50
commit
4164f76769
20 changed files with 320 additions and 353 deletions
|
@ -116,7 +116,7 @@ impl HTMLElement {
|
|||
/// `.outerText` in JavaScript.`
|
||||
///
|
||||
/// <https://html.spec.whatwg.org/multipage/#get-the-text-steps>
|
||||
fn get_inner_outer_text(&self, can_gc: CanGc) -> DOMString {
|
||||
pub(crate) fn get_inner_outer_text(&self, can_gc: CanGc) -> DOMString {
|
||||
let node = self.upcast::<Node>();
|
||||
let window = node.owner_window();
|
||||
let element = self.as_element();
|
||||
|
@ -134,6 +134,16 @@ impl HTMLElement {
|
|||
|
||||
DOMString::from(text)
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#set-the-inner-text-steps>
|
||||
pub(crate) fn set_inner_text(&self, input: DOMString, can_gc: CanGc) {
|
||||
// Step 1: Let fragment be the rendered text fragment for value given element's node
|
||||
// document.
|
||||
let fragment = self.rendered_text_fragment(input, can_gc);
|
||||
|
||||
// Step 2: Replace all with fragment within element.
|
||||
Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>(), can_gc);
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
|
||||
|
@ -494,12 +504,7 @@ impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#set-the-inner-text-steps>
|
||||
fn SetInnerText(&self, input: DOMString, can_gc: CanGc) {
|
||||
// Step 1: Let fragment be the rendered text fragment for value given element's node
|
||||
// document.
|
||||
let fragment = self.rendered_text_fragment(input, can_gc);
|
||||
|
||||
// Step 2: Replace all with fragment within element.
|
||||
Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>(), can_gc);
|
||||
self.set_inner_text(input, can_gc)
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-outertext>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue