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:
Martin Robinson
2026-03-06 21:02:37 +01:00
committed by GitHub
parent 291e9e57cb
commit 401d327b96
23 changed files with 134 additions and 164 deletions

View File

@@ -120,7 +120,7 @@ impl HTMLIFrameElement {
let element = self.upcast::<Element>();
// Step 2. If element has a src attribute specified, and its value is not the empty string, then:
let url = element
.get_attribute(&ns!(), &local_name!("src"))
.get_attribute(&local_name!("src"))
.and_then(|src| {
let url = src.value();
if url.is_empty() {
@@ -750,7 +750,7 @@ impl HTMLIFrameElement {
fn parse_sandbox_attribute(&self) {
let attribute = self
.upcast::<Element>()
.get_attribute(&ns!(), &local_name!("sandbox"));
.get_attribute(&local_name!("sandbox"));
self.sandboxing_flag_set
.set(attribute.map(|attribute_value| {
let tokens: Vec<_> = attribute_value