@@ -87,7 +87,9 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::{
87
87
} ;
88
88
use crate :: dom:: bindings:: codegen:: UnionTypes :: {
89
89
BooleanOrScrollIntoViewOptions , NodeOrString , TrustedHTMLOrNullIsEmptyString ,
90
- TrustedHTMLOrString , TrustedScriptURLOrUSVString ,
90
+ TrustedHTMLOrString ,
91
+ TrustedHTMLOrTrustedScriptOrTrustedScriptURLOrString as TrustedTypeOrString ,
92
+ TrustedScriptURLOrUSVString ,
91
93
} ;
92
94
use crate :: dom:: bindings:: conversions:: DerivedFrom ;
93
95
use crate :: dom:: bindings:: domname:: {
@@ -161,6 +163,7 @@ use crate::dom::servoparser::ServoParser;
161
163
use crate :: dom:: shadowroot:: { IsUserAgentWidget , ShadowRoot } ;
162
164
use crate :: dom:: text:: Text ;
163
165
use crate :: dom:: trustedhtml:: TrustedHTML ;
166
+ use crate :: dom:: trustedtypepolicyfactory:: TrustedTypePolicyFactory ;
164
167
use crate :: dom:: validation:: Validatable ;
165
168
use crate :: dom:: validitystate:: ValidationFlags ;
166
169
use crate :: dom:: virtualmethods:: { VirtualMethods , vtable_for} ;
@@ -752,7 +755,7 @@ impl Element {
752
755
753
756
// https://html.spec.whatwg.org/multipage/#translation-mode
754
757
pub ( crate ) fn is_translate_enabled ( & self ) -> bool {
755
- let name = & html5ever :: local_name!( "translate" ) ;
758
+ let name = & local_name ! ( "translate" ) ;
756
759
if self . has_attribute ( name) {
757
760
match_ignore_ascii_case ! { & * self . get_string_attribute( name) ,
758
761
"yes" | "" => return true ,
@@ -3155,17 +3158,39 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
3155
3158
}
3156
3159
3157
3160
/// <https://dom.spec.whatwg.org/#dom-element-setattribute>
3158
- fn SetAttribute ( & self , name : DOMString , value : DOMString , can_gc : CanGc ) -> ErrorResult {
3159
- // Step 1. If qualifiedName is not a valid attribute local name,
3160
- // then throw an "InvalidCharacterError" DOMException.
3161
+ fn SetAttribute (
3162
+ & self ,
3163
+ name : DOMString ,
3164
+ value : TrustedTypeOrString ,
3165
+ can_gc : CanGc ,
3166
+ ) -> ErrorResult {
3167
+ // Step 1. If qualifiedName does not match the Name production in XML,
3168
+ // then throw an "InvalidCharacterError" DOMException.
3161
3169
if !is_valid_attribute_local_name ( & name) {
3162
3170
return Err ( Error :: InvalidCharacter ) ;
3163
3171
}
3164
3172
3165
- // Step 2.
3173
+ // Step 2. If this is in the HTML namespace and its node document is an HTML document,
3174
+ // then set qualifiedName to qualifiedName in ASCII lowercase.
3166
3175
let name = self . parsed_name ( name) ;
3167
3176
3168
- // Step 3-5.
3177
+ // Step 3. Let verifiedValue be the result of calling get
3178
+ // Trusted Types-compliant attribute value with qualifiedName, null,
3179
+ // this, and value. [TRUSTED-TYPES]
3180
+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3181
+ self . namespace ( ) ,
3182
+ self . local_name ( ) ,
3183
+ & name,
3184
+ None ,
3185
+ value,
3186
+ & self . owner_global ( ) ,
3187
+ can_gc,
3188
+ ) ?;
3189
+
3190
+ // Step 4. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise.
3191
+ // Step 5. If attribute is null, create an attribute whose local name is qualifiedName, value is verifiedValue, and node document
3192
+ // is this’s node document, then append this attribute to this, and then return.
3193
+ // Step 6. Change attribute to verifiedValue.
3169
3194
let value = self . parse_attribute ( & ns ! ( ) , & name, value) ;
3170
3195
self . set_first_matching_attribute (
3171
3196
name. clone ( ) ,
@@ -3184,20 +3209,29 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
3184
3209
& self ,
3185
3210
namespace : Option < DOMString > ,
3186
3211
qualified_name : DOMString ,
3187
- value : DOMString ,
3212
+ value : TrustedTypeOrString ,
3188
3213
can_gc : CanGc ,
3189
3214
) -> ErrorResult {
3190
- // Step 1. Let (namespace, prefix, localName) be the result of validating and
3191
- // extracting namespace and qualifiedName given "element".
3192
- let context = domname:: Context :: Element ;
3215
+ // Step 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
3193
3216
let ( namespace, prefix, local_name) =
3194
- domname:: validate_and_extract ( namespace, & qualified_name, context) ?;
3195
- let qualified_name = LocalName :: from ( qualified_name) ;
3217
+ domname:: validate_and_extract ( namespace, & qualified_name, domname:: Context :: Element ) ?;
3218
+ // Step 2. Let verifiedValue be the result of calling get
3219
+ // Trusted Types-compliant attribute value with localName, namespace, element, and value. [TRUSTED-TYPES]
3220
+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3221
+ self . namespace ( ) ,
3222
+ self . local_name ( ) ,
3223
+ & local_name,
3224
+ Some ( & namespace) ,
3225
+ value,
3226
+ & self . owner_global ( ) ,
3227
+ can_gc,
3228
+ ) ?;
3229
+ // Step 3. Set an attribute value for this using localName, verifiedValue, and also prefix and namespace.
3196
3230
let value = self . parse_attribute ( & namespace, & local_name, value) ;
3197
3231
self . set_first_matching_attribute (
3198
3232
local_name. clone ( ) ,
3199
3233
value,
3200
- qualified_name,
3234
+ LocalName :: from ( qualified_name) ,
3201
3235
namespace. clone ( ) ,
3202
3236
prefix,
3203
3237
|attr| * attr. local_name ( ) == local_name && * attr. namespace ( ) == namespace,
0 commit comments