From cfb5119fc08aedef0180e94b2e07555f35598cba Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 13 Feb 2024 09:02:20 +0000 Subject: [PATCH] Bug 1878045 - Progress element's max property should ignore non-positive values on setting. r=dom-core,edgar Tests will be in WPT (https://github.com/web-platform-tests/wpt/pull/44355) Differential Revision: https://phabricator.services.mozilla.com/D200619 --- dom/html/HTMLProgressElement.h | 5 ++++- dom/html/nsGenericHTMLElement.h | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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);