diff options
Diffstat (limited to 'components/script/dom/xmlhttprequest.rs')
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 08b37c946c5..6c531e5b4d6 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -618,7 +618,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest { } // Substep 2 if !self.upload_complete.get() { - self.dispatch_upload_progress_event(atom!("loadstart"), Some(0)); + self.dispatch_upload_progress_event(atom!("loadstart"), Ok(Some(0))); if self.generation_id.get() != gen_id { return Ok(()); } @@ -1062,11 +1062,11 @@ impl XMLHttpRequest { self.upload_complete.set(true); // Substeps 2-4 if !self.sync.get() { - self.dispatch_upload_progress_event(atom!("progress"), None); + self.dispatch_upload_progress_event(atom!("progress"), Ok(None)); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event(atom!("load"), None); + self.dispatch_upload_progress_event(atom!("load"), Ok(None)); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event(atom!("loadend"), None); + self.dispatch_upload_progress_event(atom!("loadend"), Ok(None)); return_if_fetch_was_terminated!(); } // Part of step 13, send() (processing response) @@ -1164,9 +1164,9 @@ impl XMLHttpRequest { let upload_complete = &self.upload_complete; if !upload_complete.get() { upload_complete.set(true); - self.dispatch_upload_progress_event(Atom::from(errormsg), None); + self.dispatch_upload_progress_event(Atom::from(errormsg), Err(())); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event(atom!("loadend"), None); + self.dispatch_upload_progress_event(atom!("loadend"), Err(())); return_if_fetch_was_terminated!(); } self.dispatch_response_progress_event(Atom::from(errormsg)); @@ -1210,11 +1210,19 @@ impl XMLHttpRequest { progressevent.upcast::<Event>().fire(target); } - fn dispatch_upload_progress_event(&self, type_: Atom, partial_load: Option<u64>) { - // If partial_load is None, loading has completed and we can just use the value from the request body + fn dispatch_upload_progress_event(&self, type_: Atom, partial_load: Result<Option<u64>, ()>) { + // If partial_load is Ok(None), loading has completed and we can just use the value from the request body + // If an error occured, we pass 0 for both loaded and total - let total = self.request_body_len.get() as u64; - self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total)); + let request_body_len = self.request_body_len.get() as u64; + let (loaded, total) = match partial_load { + Ok(l) => match l { + Some(loaded) => (loaded, Some(request_body_len)), + None => (request_body_len, Some(request_body_len)), + }, + Err(()) => (0, None), + }; + self.dispatch_progress_event(true, type_, loaded, total); } fn dispatch_response_progress_event(&self, type_: Atom) { |