diff --git a/dom/html/HTMLProgressElement.h b/dom/html/HTMLProgressElement.h
index 04c3c2a77f69..e0de5362821a 100644
--- a/dom/html/HTMLProgressElement.h
+++ b/dom/html/HTMLProgressElement.h
@@ -37,7 +37,10 @@ class HTMLProgressElement final : public nsGenericHTMLElement {
}
double Max() const;
void SetMax(double aValue, ErrorResult& aRv) {
- SetDoubleAttr(nsGkAtoms::max, aValue, aRv);
+ // https://html.spec.whatwg.org/multipage/form-elements.html#dom-progress-max
+ // The max IDL attribute must reflect the content attribute of the same
+ // name, limited to only positive numbers.
+ SetDoubleAttr(nsGkAtoms::max, aValue, aRv);
}
double Position() const;
diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h
index b3790314208c..f6e7d2415db3 100644
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -858,14 +858,31 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
uint32_t GetDimensionAttrAsUnsignedInt(nsAtom* aAttr,
uint32_t aDefault) const;
+ enum class Reflection {
+ Unlimited,
+ OnlyPositive,
+ };
+
/**
* Sets value of attribute to specified double. Only works for attributes
* in null namespace.
*
+ * Implements
+ * https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-double
+ *
* @param aAttr name of attribute.
* @param aValue Double value of attribute.
*/
+ template
void SetDoubleAttr(nsAtom* aAttr, double aValue, mozilla::ErrorResult& aRv) {
+ // 1. If the reflected IDL attribute is limited to only positive numbers and
+ // the given value is not greater than 0, then return.
+ if (Limited == Reflection::OnlyPositive && aValue <= 0) {
+ return;
+ }
+
+ // 2. Run this's set the content attribute with the given value, converted
+ // to the best representation of the number as a floating-point number.
nsAutoString value;
value.AppendFloat(aValue);