aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/trustedscripturl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/trustedscripturl.rs')
-rw-r--r--components/script/dom/trustedscripturl.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/components/script/dom/trustedscripturl.rs b/components/script/dom/trustedscripturl.rs
index ba1e0335abc..3f0aef248b3 100644
--- a/components/script/dom/trustedscripturl.rs
+++ b/components/script/dom/trustedscripturl.rs
@@ -7,10 +7,14 @@ use std::fmt;
use dom_struct::dom_struct;
use crate::dom::bindings::codegen::Bindings::TrustedScriptURLBinding::TrustedScriptURLMethods;
+use crate::dom::bindings::codegen::UnionTypes::TrustedScriptURLOrUSVString;
+use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
+use crate::dom::trustedtypepolicy::TrustedType;
+use crate::dom::trustedtypepolicyfactory::TrustedTypePolicyFactory;
use crate::script_runtime::CanGc;
#[dom_struct]
@@ -32,6 +36,31 @@ impl TrustedScriptURL {
pub(crate) fn new(data: String, global: &GlobalScope, can_gc: CanGc) -> DomRoot<Self> {
reflect_dom_object(Box::new(Self::new_inherited(data)), global, can_gc)
}
+
+ pub(crate) fn get_trusted_script_url_compliant_string(
+ global: &GlobalScope,
+ value: TrustedScriptURLOrUSVString,
+ containing_class: &str,
+ field: &str,
+ can_gc: CanGc,
+ ) -> Fallible<String> {
+ match value {
+ TrustedScriptURLOrUSVString::USVString(value) => {
+ let sink = format!("{} {}", containing_class, field);
+ TrustedTypePolicyFactory::get_trusted_type_compliant_string(
+ TrustedType::TrustedScriptURL,
+ global,
+ value.as_ref().to_owned(),
+ &sink,
+ "'script'",
+ can_gc,
+ )
+ },
+ TrustedScriptURLOrUSVString::TrustedScriptURL(trusted_script_url) => {
+ Ok(trusted_script_url.to_string())
+ },
+ }
+ }
}
impl fmt::Display for TrustedScriptURL {