diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index 75e8be38b17..25f90802c16 100644
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -105,8 +105,14 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
self.form_owner()
}
- // https://html.spec.whatwg.org/multipage/#dom-button-type
- make_enumerated_getter!(Type, "type", "submit", "reset" | "button");
+ //
+ make_enumerated_getter!(
+ Type,
+ "type",
+ "submit" | "reset" | "button",
+ missing => "submit",
+ invalid => "submit"
+ );
// https://html.spec.whatwg.org/multipage/#dom-button-type
make_setter!(SetType, "type");
@@ -121,15 +127,21 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
make_enumerated_getter!(
FormEnctype,
"formenctype",
- "application/x-www-form-urlencoded",
- "text/plain" | "multipart/form-data"
+ "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain",
+ invalid => "application/x-www-form-urlencoded"
);
// https://html.spec.whatwg.org/multipage/#dom-fs-formenctype
make_setter!(SetFormEnctype, "formenctype");
// https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
- make_enumerated_getter!(FormMethod, "formmethod", "get", "post" | "dialog");
+ make_enumerated_getter!(
+ FormMethod,
+ "formmethod",
+ "get" | "post" | "dialog",
+ missing => "get",
+ invalid => "get"
+ );
// https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
make_setter!(SetFormMethod, "formmethod");
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 5f96e38851f..4917024fa2c 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -160,7 +160,14 @@ impl HTMLElementMethods for HTMLElement {
make_setter!(SetLang, "lang");
// https://html.spec.whatwg.org/multipage/#the-dir-attribute
- make_enumerated_getter!(Dir, "dir", "", "ltr" | "rtl" | "auto");
+ make_enumerated_getter!(
+ Dir,
+ "dir",
+ "ltr" | "rtl" | "auto",
+ missing => "",
+ invalid => ""
+ );
+
// https://html.spec.whatwg.org/multipage/#the-dir-attribute
make_setter!(SetDir, "dir");
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 4fe3785d470..dd278cc8ad3 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -217,7 +217,13 @@ impl HTMLFormElementMethods for HTMLFormElement {
make_setter!(SetAction, "action");
// https://html.spec.whatwg.org/multipage/#dom-form-autocomplete
- make_enumerated_getter!(Autocomplete, "autocomplete", "on", "off");
+ make_enumerated_getter!(
+ Autocomplete,
+ "autocomplete",
+ "on" | "off",
+ missing => "on",
+ invalid => "on"
+ );
// https://html.spec.whatwg.org/multipage/#dom-form-autocomplete
make_setter!(SetAutocomplete, "autocomplete");
@@ -226,8 +232,9 @@ impl HTMLFormElementMethods for HTMLFormElement {
make_enumerated_getter!(
Enctype,
"enctype",
- "application/x-www-form-urlencoded",
- "text/plain" | "multipart/form-data"
+ "application/x-www-form-urlencoded" | "text/plain" | "multipart/form-data",
+ missing => "application/x-www-form-urlencoded",
+ invalid => "application/x-www-form-urlencoded"
);
// https://html.spec.whatwg.org/multipage/#dom-fs-enctype
@@ -244,7 +251,13 @@ impl HTMLFormElementMethods for HTMLFormElement {
}
// https://html.spec.whatwg.org/multipage/#dom-fs-method
- make_enumerated_getter!(Method, "method", "get", "post" | "dialog");
+ make_enumerated_getter!(
+ Method,
+ "method",
+ "get" | "post" | "dialog",
+ missing => "get",
+ invalid => "get"
+ );
// https://html.spec.whatwg.org/multipage/#dom-fs-method
make_setter!(SetMethod, "method");
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 5eae0866e1a..b2aaba04517 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -1399,21 +1399,28 @@ impl HTMLInputElementMethods for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-input-formaction
make_setter!(SetFormAction, "formaction");
- // https://html.spec.whatwg.org/multipage/#dom-input-formenctype
+ // https://html.spec.whatwg.org/multipage/#dom-fs-formenctype
make_enumerated_getter!(
FormEnctype,
"formenctype",
- "application/x-www-form-urlencoded",
- "text/plain" | "multipart/form-data"
+ "application/x-www-form-urlencoded" | "text/plain" | "multipart/form-data",
+ missing => "",
+ invalid => "application/x-www-form-urlencoded"
);
// https://html.spec.whatwg.org/multipage/#dom-input-formenctype
make_setter!(SetFormEnctype, "formenctype");
- // https://html.spec.whatwg.org/multipage/#dom-input-formmethod
- make_enumerated_getter!(FormMethod, "formmethod", "get", "post" | "dialog");
+ // https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
+ make_enumerated_getter!(
+ FormMethod,
+ "formmethod",
+ "get" | "post" | "dialog",
+ missing => "get",
+ invalid => "get"
+ );
- // https://html.spec.whatwg.org/multipage/#dom-input-formmethod
+ // https://html.spec.whatwg.org/multipage/#dom-fs-formmethod
make_setter!(SetFormMethod, "formmethod");
// https://html.spec.whatwg.org/multipage/#dom-input-formtarget
diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs
index b30fa3d4b22..7aeb765091f 100644
--- a/components/script/dom/htmlmediaelement.rs
+++ b/components/script/dom/htmlmediaelement.rs
@@ -2159,8 +2159,15 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
}
// https://html.spec.whatwg.org/multipage/#attr-media-preload
- // Missing value default is user-agent defined.
- make_enumerated_getter!(Preload, "preload", "", "none" | "metadata" | "auto");
+ // Missing/Invalid values are user-agent defined.
+ make_enumerated_getter!(
+ Preload,
+ "preload",
+ "none" | "metadata" | "auto",
+ missing => "auto",
+ invalid => "auto"
+ );
+
// https://html.spec.whatwg.org/multipage/#attr-media-preload
make_setter!(SetPreload, "preload");
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs
index f5268e72945..4d43656996c 100644
--- a/components/script/dom/macros.rs
+++ b/components/script/dom/macros.rs
@@ -158,22 +158,86 @@ macro_rules! make_labels_getter(
);
);
-#[macro_export]
+/// Implements the `To determine the state of an attribute` steps from
+///
macro_rules! make_enumerated_getter(
- ( $attr:ident, $htmlname:tt, $default:expr, $($choices:pat_param)|+) => (
+ ($attr:ident,
+ $htmlname:tt,
+ $($choices:literal)|+,
+ missing => $missing:literal,
+ invalid => $invalid:literal
+ ) => (
fn $attr(&self) -> DOMString {
use $crate::dom::bindings::inheritance::Castable;
use $crate::dom::element::Element;
- let element = self.upcast::();
- let mut val = element.get_string_attribute(&html5ever::local_name!($htmlname));
- val.make_ascii_lowercase();
- // https://html.spec.whatwg.org/multipage/#attr-fs-method
- match &*val {
- $($choices)|+ => val,
- _ => DOMString::from($default)
+ use $crate::dom::bindings::codegen::Bindings::AttrBinding::Attr_Binding::AttrMethods;
+
+ let attr_or_none = self.upcast::()
+ .get_attribute(&html5ever::ns!(), &html5ever::local_name!($htmlname));
+ match attr_or_none {
+ // Step 1. If the attribute is not specified:
+ None => {
+ // Step 1.1. If the attribute has a missing value default state defined, then return that
+ // missing value default state.
+ // Step 1.2 Otherwise, return no state.
+ return DOMString::from($missing);
+ },
+ Some(attr) => {
+ // Step 2. If the attribute's value is an ASCII case-insensitive match for one of the keywords
+ // defined for the attribute, then return the state represented by that keyword.
+ let value: DOMString = attr.Value().to_ascii_lowercase().into();
+ $(
+ if value.str() == $choices {
+ return value;
+ }
+ )+
+
+ // Step 3. If the attribute has an invalid value default state defined, then return that invalid
+ // value default state.
+ // Step 4. Return no state.
+ return DOMString::from($invalid);
+ }
}
}
);
+ ($attr:ident,
+ $htmlname:tt,
+ $($choices:literal)|+,
+ ) => (
+ make_enumerated_getter!(
+ $attr,
+ $htmlname,
+ $($choices)|+,
+ missing => "",
+ invalid => ""
+ );
+ );
+ ($attr:ident,
+ $htmlname:tt,
+ $($choices:literal)|+,
+ invalid => $invalid:literal
+ ) => (
+ make_enumerated_getter!(
+ $attr,
+ $htmlname,
+ $($choices)|+,
+ missing => "",
+ invalid => $invalid
+ );
+ );
+ ($attr:ident,
+ $htmlname:tt,
+ $($choices:literal)|+,
+ missing => $missing:literal,
+ ) => (
+ make_enumerated_getter!(
+ $attr,
+ $htmlname,
+ $($choices)|+,
+ missing => $missing,
+ invalid => ""
+ );
+ );
);
// concat_idents! doesn't work for function name positions, so
diff --git a/tests/wpt/meta/html/dom/reflection-forms-weekmonth.html.ini b/tests/wpt/meta/html/dom/reflection-forms-weekmonth.html.ini
index 748a792e7ee..c1f88030098 100644
--- a/tests/wpt/meta/html/dom/reflection-forms-weekmonth.html.ini
+++ b/tests/wpt/meta/html/dom/reflection-forms-weekmonth.html.ini
@@ -248,9 +248,6 @@
[input.autocomplete: IDL set to object "test-valueOf"]
expected: FAIL
- [input.formEnctype: IDL get with DOM attribute unset]
- expected: FAIL
-
[input.formMethod: IDL get with DOM attribute unset]
expected: FAIL
diff --git a/tests/wpt/meta/html/dom/reflection-forms.html.ini b/tests/wpt/meta/html/dom/reflection-forms.html.ini
index e216a11a0c0..dc44db86f7e 100644
--- a/tests/wpt/meta/html/dom/reflection-forms.html.ini
+++ b/tests/wpt/meta/html/dom/reflection-forms.html.ini
@@ -1130,9 +1130,6 @@
[input.autocomplete: IDL set to object "test-valueOf"]
expected: FAIL
- [input.formEnctype: IDL get with DOM attribute unset]
- expected: FAIL
-
[input.formMethod: IDL get with DOM attribute unset]
expected: FAIL
@@ -1604,9 +1601,6 @@
[button.tabIndex: IDL set to -2147483648]
expected: FAIL
- [button.formEnctype: IDL get with DOM attribute unset]
- expected: FAIL
-
[button.formMethod: IDL get with DOM attribute unset]
expected: FAIL