mirror of
https://github.com/servo/servo
synced 2026-04-26 01:25:32 +02:00
script: Clean up attribute access a little bit in Element (#43064)
- Use modern Rust conveniences such as `unwrap_or_default` - Unabbreviate `attr` - Unify the lowercase ASCII name assertion and make it a debug assertion - Use `unreachable!` instead of panic - Expose two attribute getters that follow the behavior of two specification concepts and what we expect internally in Servo: - One that takes a namespace, but does not require lowercase attribute names. ([specification concept](https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace>)) - One that does not take a namespace, but does require lowercase attribute names. ([specification concept](https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name)) Testing: This should not really change behavior so should be covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
@@ -1092,9 +1092,7 @@ impl HTMLMediaElement {
|
||||
let mode = if self.src_object.borrow().is_some() {
|
||||
// If the media element has an assigned media provider object, then let mode be object.
|
||||
Mode::Object
|
||||
} else if let Some(attribute) = self
|
||||
.upcast::<Element>()
|
||||
.get_attribute(&ns!(), &local_name!("src"))
|
||||
} else if let Some(attribute) = self.upcast::<Element>().get_attribute(&local_name!("src"))
|
||||
{
|
||||
// Otherwise, if the media element has no assigned media provider object but has a src
|
||||
// attribute, then let mode be attribute.
|
||||
@@ -1213,7 +1211,7 @@ impl HTMLMediaElement {
|
||||
// its src attribute's value is the empty string, then end the synchronous section, and jump
|
||||
// down to the failed with elements step below.
|
||||
let Some(src) = element
|
||||
.get_attribute(&ns!(), &local_name!("src"))
|
||||
.get_attribute(&local_name!("src"))
|
||||
.filter(|attribute| !attribute.value().is_empty())
|
||||
else {
|
||||
self.load_from_source_child_failure_steps(source);
|
||||
@@ -1223,7 +1221,7 @@ impl HTMLMediaElement {
|
||||
// Step 9.children.3. If candidate has a media attribute whose value does not match the
|
||||
// environment, then end the synchronous section, and jump down to the failed with elements
|
||||
// step below.
|
||||
if let Some(media) = element.get_attribute(&ns!(), &local_name!("media")) {
|
||||
if let Some(media) = element.get_attribute(&local_name!("media")) {
|
||||
if !MediaList::matches_environment(&element.owner_document(), &media.value()) {
|
||||
self.load_from_source_child_failure_steps(source);
|
||||
return;
|
||||
@@ -1244,7 +1242,7 @@ impl HTMLMediaElement {
|
||||
// type (including any codecs described by the codecs parameter, for types that define that
|
||||
// parameter), represents a type that the user agent knows it cannot render, then end the
|
||||
// synchronous section, and jump down to the failed with elements step below.
|
||||
if let Some(type_) = element.get_attribute(&ns!(), &local_name!("type")) {
|
||||
if let Some(type_) = element.get_attribute(&local_name!("type")) {
|
||||
if ServoMedia::get().can_play_type(&type_.value()) == SupportsMediaType::No {
|
||||
self.load_from_source_child_failure_steps(source);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user