From 27457e4d84f6f3ef05dc9f7ee3f84fa82e0de9da Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 17 Nov 2017 13:25:50 -0800 Subject: [PATCH] Fetch cancellation: Send cancellation message whenever XHR needs to abort a fetch --- components/script/dom/xmlhttprequest.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 734355ee20d..f1ae76ad087 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1023,6 +1023,12 @@ impl XMLHttpRequest { } fn terminate_ongoing_fetch(&self) { + if let Some(ref cancel_chan) = *self.cancellation_chan.borrow() { + // The receiver will be destroyed if the request has already completed; + // so we throw away the error. Cancellation is a courtesy call, + // we don't actually care if the other side heard. + let _ = cancel_chan.send(()); + } let GenerationId(prev_id) = self.generation_id.get(); self.generation_id.set(GenerationId(prev_id + 1)); self.response_status.set(Ok(()));