script: Implement HTMLOptgroupElement::Label (#35970)

* Implement HTMLOptgroupElement::Label

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

* Update WPT expectations

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-03-14 21:33:07 +01:00 committed by GitHub
parent 0bc05a8414
commit f93d65b496
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 141 deletions

View file

@ -5,10 +5,12 @@
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix, local_name};
use js::rust::HandleObject;
use script_bindings::str::DOMString;
use stylo_dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
use crate::dom::bindings::codegen::GenericBindings::NodeBinding::Node_Binding::NodeMethods;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::DomRoot;
use crate::dom::document::Document;
@ -16,12 +18,13 @@ use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmloptionelement::HTMLOptionElement;
use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
use crate::dom::node::{BindContext, Node, UnbindContext};
use crate::dom::validation::Validatable;
use crate::dom::validitystate::ValidationFlags;
use crate::dom::virtualmethods::VirtualMethods;
use crate::script_runtime::CanGc;
/// <https://html.spec.whatwg.org/multipage/#htmloptgroupelement>
#[dom_struct]
pub(crate) struct HTMLOptGroupElement {
htmlelement: HTMLElement,
@ -62,17 +65,18 @@ impl HTMLOptGroupElement {
}
fn update_select_validity(&self) {
if let Some(select) = self
.upcast::<Node>()
.ancestors()
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
.next()
{
if let Some(select) = self.owner_select_element() {
select
.validity_state()
.perform_validation_and_update(ValidationFlags::all());
}
}
fn owner_select_element(&self) -> Option<DomRoot<HTMLSelectElement>> {
self.upcast::<Node>()
.GetParentNode()
.and_then(DomRoot::downcast)
}
}
impl HTMLOptGroupElementMethods<crate::DomTypeHolder> for HTMLOptGroupElement {
@ -81,6 +85,12 @@ impl HTMLOptGroupElementMethods<crate::DomTypeHolder> for HTMLOptGroupElement {
// https://html.spec.whatwg.org/multipage/#dom-optgroup-disabled
make_bool_setter!(SetDisabled, "disabled");
// https://html.spec.whatwg.org/multipage/#dom-optgroup-label
make_getter!(Label, "label");
// https://html.spec.whatwg.org/multipage/#dom-optgroup-label
make_setter!(SetLabel, "label");
}
impl VirtualMethods for HTMLOptGroupElement {
@ -133,12 +143,7 @@ impl VirtualMethods for HTMLOptGroupElement {
fn unbind_from_tree(&self, context: &UnbindContext) {
self.super_type().unwrap().unbind_from_tree(context);
if let Some(select) = context
.parent
.inclusive_ancestors(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
.next()
{
if let Some(select) = context.parent.downcast::<HTMLSelectElement>() {
select
.validity_state()
.perform_validation_and_update(ValidationFlags::all());

View file

@ -9,6 +9,6 @@ interface HTMLOptGroupElement : HTMLElement {
[CEReactions]
attribute boolean disabled;
// [CEReactions]
// attribute DOMString label;
[CEReactions]
attribute DOMString label;
};

View file

@ -1,6 +0,0 @@
[HTMLOptGroupElement.html]
[label on HTMLOptGroupElement must enqueue an attributeChanged reaction when adding a new attribute]
expected: FAIL
[label on HTMLOptGroupElement must enqueue an attributeChanged reaction when replacing an existing attribute]
expected: FAIL

View file

@ -7765,12 +7765,6 @@
[HTMLSelectElement interface: document.createElement("select") must inherit property "showPicker()" with the proper type]
expected: FAIL
[HTMLOptGroupElement interface: attribute label]
expected: FAIL
[HTMLOptGroupElement interface: document.createElement("optgroup") must inherit property "label" with the proper type]
expected: FAIL
[HTMLTextAreaElement interface: attribute autocomplete]
expected: FAIL

View file

@ -2237,120 +2237,6 @@
[optgroup.tabIndex: IDL set to -2147483648]
expected: FAIL
[optgroup.label: typeof IDL attribute]
expected: FAIL
[optgroup.label: IDL get with DOM attribute unset]
expected: FAIL
[optgroup.label: setAttribute() to ""]
expected: FAIL
[optgroup.label: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[optgroup.label: setAttribute() to undefined]
expected: FAIL
[optgroup.label: setAttribute() to 7]
expected: FAIL
[optgroup.label: setAttribute() to 1.5]
expected: FAIL
[optgroup.label: setAttribute() to "5%"]
expected: FAIL
[optgroup.label: setAttribute() to "+100"]
expected: FAIL
[optgroup.label: setAttribute() to ".5"]
expected: FAIL
[optgroup.label: setAttribute() to true]
expected: FAIL
[optgroup.label: setAttribute() to false]
expected: FAIL
[optgroup.label: setAttribute() to object "[object Object\]"]
expected: FAIL
[optgroup.label: setAttribute() to NaN]
expected: FAIL
[optgroup.label: setAttribute() to Infinity]
expected: FAIL
[optgroup.label: setAttribute() to -Infinity]
expected: FAIL
[optgroup.label: setAttribute() to "\\0"]
expected: FAIL
[optgroup.label: setAttribute() to null]
expected: FAIL
[optgroup.label: setAttribute() to object "test-toString"]
expected: FAIL
[optgroup.label: setAttribute() to object "test-valueOf"]
expected: FAIL
[optgroup.label: IDL set to ""]
expected: FAIL
[optgroup.label: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
expected: FAIL
[optgroup.label: IDL set to undefined]
expected: FAIL
[optgroup.label: IDL set to 7]
expected: FAIL
[optgroup.label: IDL set to 1.5]
expected: FAIL
[optgroup.label: IDL set to "5%"]
expected: FAIL
[optgroup.label: IDL set to "+100"]
expected: FAIL
[optgroup.label: IDL set to ".5"]
expected: FAIL
[optgroup.label: IDL set to true]
expected: FAIL
[optgroup.label: IDL set to false]
expected: FAIL
[optgroup.label: IDL set to object "[object Object\]"]
expected: FAIL
[optgroup.label: IDL set to NaN]
expected: FAIL
[optgroup.label: IDL set to Infinity]
expected: FAIL
[optgroup.label: IDL set to -Infinity]
expected: FAIL
[optgroup.label: IDL set to "\\0"]
expected: FAIL
[optgroup.label: IDL set to null]
expected: FAIL
[optgroup.label: IDL set to object "test-toString"]
expected: FAIL
[optgroup.label: IDL set to object "test-valueOf"]
expected: FAIL
[option.accessKey: typeof IDL attribute]
expected: FAIL