Update ProgressEvent to use doubles (#36487)

See: https://github.com/whatwg/xhr/pull/394

Testing: WPT tests exist for this

Signed-off-by: Sebastian C <sebsebmc@gmail.com>
This commit is contained in:
Sebastian C 2025-04-12 20:41:39 -05:00 committed by GitHub
parent 4c55104b36
commit 85bd0918f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 26 deletions

View file

@ -14,6 +14,7 @@ use js::jsval::{self, JSVal};
use js::rust::HandleObject;
use js::typedarray::{ArrayBuffer, CreateWith};
use mime::{self, Mime};
use script_bindings::num::Finite;
use stylo_atoms::Atom;
use crate::dom::bindings::cell::DomRefCell;
@ -463,8 +464,8 @@ impl FileReader {
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
total.is_some(),
loaded,
total.unwrap_or(0),
Finite::wrap(loaded as f64),
Finite::wrap(total.unwrap_or(0) as f64),
can_gc,
);
progressevent.upcast::<Event>().fire(self.upcast(), can_gc);

View file

@ -4,6 +4,7 @@
use dom_struct::dom_struct;
use js::rust::HandleObject;
use script_bindings::num::Finite;
use stylo_atoms::Atom;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
@ -22,12 +23,16 @@ use crate::script_runtime::CanGc;
pub(crate) struct ProgressEvent {
event: Event,
length_computable: bool,
loaded: u64,
total: u64,
loaded: Finite<f64>,
total: Finite<f64>,
}
impl ProgressEvent {
fn new_inherited(length_computable: bool, loaded: u64, total: u64) -> ProgressEvent {
fn new_inherited(
length_computable: bool,
loaded: Finite<f64>,
total: Finite<f64>,
) -> ProgressEvent {
ProgressEvent {
event: Event::new_inherited(),
length_computable,
@ -43,8 +48,8 @@ impl ProgressEvent {
can_bubble: EventBubbles,
cancelable: EventCancelable,
length_computable: bool,
loaded: u64,
total: u64,
loaded: Finite<f64>,
total: Finite<f64>,
can_gc: CanGc,
) -> DomRoot<ProgressEvent> {
Self::new_with_proto(
@ -68,8 +73,8 @@ impl ProgressEvent {
can_bubble: EventBubbles,
cancelable: EventCancelable,
length_computable: bool,
loaded: u64,
total: u64,
loaded: Finite<f64>,
total: Finite<f64>,
can_gc: CanGc,
) -> DomRoot<ProgressEvent> {
let ev = reflect_dom_object_with_proto(
@ -121,12 +126,12 @@ impl ProgressEventMethods<crate::DomTypeHolder> for ProgressEvent {
}
// https://xhr.spec.whatwg.org/#dom-progressevent-loaded
fn Loaded(&self) -> u64 {
fn Loaded(&self) -> Finite<f64> {
self.loaded
}
// https://xhr.spec.whatwg.org/#dom-progressevent-total
fn Total(&self) -> u64 {
fn Total(&self) -> Finite<f64> {
self.total
}

View file

@ -31,6 +31,7 @@ use net_traits::{
FetchMetadata, FetchResponseListener, FilteredMetadata, NetworkError, ReferrerPolicy,
ResourceFetchTiming, ResourceTimingType, trim_http_whitespace,
};
use script_bindings::num::Finite;
use script_traits::DocumentActivity;
use servo_url::ServoUrl;
use stylo_atoms::Atom;
@ -1235,8 +1236,8 @@ impl XMLHttpRequest {
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
length_computable,
loaded,
total_length,
Finite::wrap(loaded as f64),
Finite::wrap(total_length as f64),
can_gc,
);
let target = if upload {

View file

@ -16,12 +16,12 @@
interface ProgressEvent : Event {
[Throws] constructor(DOMString type, optional ProgressEventInit eventInitDict = {});
readonly attribute boolean lengthComputable;
readonly attribute unsigned long long loaded;
readonly attribute unsigned long long total;
readonly attribute double loaded;
readonly attribute double total;
};
dictionary ProgressEventInit : EventInit {
boolean lengthComputable = false;
unsigned long long loaded = 0;
unsigned long long total = 0;
double loaded = 0;
double total = 0;
};

View file

@ -1,9 +0,0 @@
[progressevent-constructor.html]
[Decimal number test.]
expected: FAIL
[Mixed integer and decimal number test.]
expected: FAIL
[Negative number.]
expected: FAIL