fix: Implement additional logic in DOMString::set_best_representation_of_the_floating_point_number in order to correct some failing tests related to -0 values. (#32272)

This commit is contained in:
shanehandley 2024-05-13 18:07:48 +10:00 committed by GitHub
parent 3d4fd0e550
commit 8eeb888010
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 74 deletions

View file

@ -10,6 +10,7 @@ use crate::dom::bindings::codegen::Bindings::HTMLProgressElementBinding::HTMLPro
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::Element;
use crate::dom::htmlelement::HTMLElement;
@ -75,11 +76,15 @@ impl HTMLProgressElementMethods for HTMLProgressElement {
})
}
// https://html.spec.whatwg.org/multipage/#dom-progress-value
/// <https://html.spec.whatwg.org/multipage/#dom-progress-value>
fn SetValue(&self, new_val: Finite<f64>) {
if 0.0 <= *new_val {
if *new_val >= 0.0 {
let mut string_value = DOMString::from_string((*new_val).to_string());
string_value.set_best_representation_of_the_floating_point_number();
self.upcast::<Element>()
.set_string_attribute(&local_name!("value"), (*new_val).to_string().into());
.set_string_attribute(&local_name!("value"), string_value);
}
}
@ -100,10 +105,16 @@ impl HTMLProgressElementMethods for HTMLProgressElement {
})
}
// https://html.spec.whatwg.org/multipage/#dom-progress-max
/// <https://html.spec.whatwg.org/multipage/#dom-progress-max>
fn SetMax(&self, new_val: Finite<f64>) {
self.upcast::<Element>()
.set_string_attribute(&local_name!("max"), (*new_val).to_string().into());
if *new_val > 0.0 {
let mut string_value = DOMString::from_string((*new_val).to_string());
string_value.set_best_representation_of_the_floating_point_number();
self.upcast::<Element>()
.set_string_attribute(&local_name!("max"), string_value);
}
}
// https://html.spec.whatwg.org/multipage/#dom-progress-position