mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Replace XHR events for generic ones in ScriptTask
fixup! Replace XHR events for generic ones in ScriptTask fixup! Replace XHR events for generic ones in ScriptTask
This commit is contained in:
parent
c92a7898b4
commit
271aa277e9
4 changed files with 43 additions and 21 deletions
|
@ -19,7 +19,7 @@ use libc;
|
|||
use std::ptr;
|
||||
|
||||
/// DOM exceptions that can be thrown by a native DOM method.
|
||||
#[deriving(Show)]
|
||||
#[deriving(Show, Clone)]
|
||||
pub enum Error {
|
||||
IndexSize,
|
||||
FailureUnknown,
|
||||
|
|
|
@ -17,7 +17,6 @@ use dom::messageevent::MessageEvent;
|
|||
use dom::worker::{Worker, TrustedWorkerAddress};
|
||||
use dom::workerglobalscope::{WorkerGlobalScope, WorkerGlobalScopeHelpers};
|
||||
use dom::workerglobalscope::WorkerGlobalScopeTypeId;
|
||||
use dom::xmlhttprequest::XMLHttpRequest;
|
||||
use script_task::{ScriptTask, ScriptChan, ScriptMsg, TimerSource};
|
||||
use script_task::StackRootTLS;
|
||||
|
||||
|
@ -131,11 +130,8 @@ impl DedicatedWorkerGlobalScope {
|
|||
MessageEvent::dispatch_jsval(target, GlobalRef::Worker(scope), message);
|
||||
global.delayed_release_worker();
|
||||
},
|
||||
Ok(ScriptMsg::XHRProgress(addr, progress)) => {
|
||||
XMLHttpRequest::handle_progress(addr, progress)
|
||||
},
|
||||
Ok(ScriptMsg::XHRRelease(addr)) => {
|
||||
XMLHttpRequest::handle_release(addr)
|
||||
Ok(ScriptMsg::RunnableMsg(runnable)) => {
|
||||
runnable.handler()
|
||||
},
|
||||
Ok(ScriptMsg::WorkerPostMessage(addr, data, nbytes)) => {
|
||||
Worker::handle_message(addr, data, nbytes);
|
||||
|
|
|
@ -25,7 +25,7 @@ use dom::urlsearchparams::URLSearchParamsHelpers;
|
|||
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
|
||||
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTargetTypeId;
|
||||
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
|
||||
use script_task::{ScriptChan, ScriptMsg};
|
||||
use script_task::{ScriptChan, ScriptMsg, Runnable};
|
||||
|
||||
use encoding::all::UTF_8;
|
||||
use encoding::label::encoding_from_whatwg_label;
|
||||
|
@ -73,10 +73,37 @@ enum XMLHttpRequestState {
|
|||
XHRDone = 4, // So as not to conflict with the ProgressMsg `Done`
|
||||
}
|
||||
|
||||
#[deriving(PartialEq)]
|
||||
struct XHRReleaseHandler(TrustedXHRAddress);
|
||||
|
||||
impl Runnable for XHRReleaseHandler {
|
||||
fn handler(&self) {
|
||||
let XHRReleaseHandler(addr) = *self;
|
||||
XMLHttpRequest::handle_release(addr);
|
||||
}
|
||||
}
|
||||
|
||||
struct XHRProgressHandler {
|
||||
addr: TrustedXHRAddress,
|
||||
progress: XHRProgress,
|
||||
}
|
||||
|
||||
impl XHRProgressHandler {
|
||||
fn new(addr: TrustedXHRAddress, progress: XHRProgress) -> XHRProgressHandler {
|
||||
XHRProgressHandler { addr: addr, progress: progress }
|
||||
}
|
||||
}
|
||||
|
||||
impl Runnable for XHRProgressHandler {
|
||||
fn handler(&self) {
|
||||
XMLHttpRequest::handle_progress(self.addr, self.progress.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(PartialEq, Clone)]
|
||||
#[jstraceable]
|
||||
pub struct GenerationId(uint);
|
||||
|
||||
#[deriving(Clone)]
|
||||
pub enum XHRProgress {
|
||||
/// Notify that headers have been received
|
||||
HeadersReceived(GenerationId, Option<Headers>, Option<RawStatus>),
|
||||
|
@ -208,7 +235,7 @@ impl XMLHttpRequest {
|
|||
},
|
||||
SyncOrAsync::Async(addr, script_chan) => {
|
||||
let ScriptChan(ref chan) = *script_chan;
|
||||
chan.send(ScriptMsg::XHRProgress(addr, msg));
|
||||
chan.send(ScriptMsg::RunnableMsg(box XHRProgressHandler::new(addr, msg)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -609,7 +636,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
|
|||
self.fetch_time.set(time::now().to_timespec().sec);
|
||||
let script_chan = global.root_ref().script_chan().clone();
|
||||
// Pin the object before launching the fetch task.
|
||||
// The `ScriptMsg::XHRRelease` sent when the fetch task completes will
|
||||
// The `ScriptMsg::RunnableMsg` sent when the fetch task completes will
|
||||
// unpin it. This is to ensure that the object will stay alive
|
||||
// as long as there are (possibly cancelled) inflight events queued up
|
||||
// in the script task's port
|
||||
|
@ -625,7 +652,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
|
|||
gen_id,
|
||||
start_port);
|
||||
let ScriptChan(ref chan) = script_chan;
|
||||
chan.send(ScriptMsg::XHRRelease(addr));
|
||||
chan.send(ScriptMsg::RunnableMsg(box XHRReleaseHandler(addr)));
|
||||
});
|
||||
let timeout = self.timeout.get();
|
||||
if timeout > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue