mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #18503 - servo:globalism, r=emilio
Simplify WorkerGlobalScope::process_event <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18503) <!-- Reviewable:end -->
This commit is contained in:
commit
4268037424
3 changed files with 18 additions and 38 deletions
|
@ -29,7 +29,7 @@ use js::rust::Runtime;
|
|||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
use net_traits::{IpcSend, load_whole_resource};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_reports, new_rt_and_cx};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, new_rt_and_cx};
|
||||
use script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
||||
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
||||
use servo_rand::random;
|
||||
|
@ -269,10 +269,6 @@ impl DedicatedWorkerGlobalScope {
|
|||
(chan, box rx)
|
||||
}
|
||||
|
||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||
self.handle_script_event(WorkerScriptMsg::Common(msg));
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn receive_event(&self) -> Result<MixedMessage, RecvError> {
|
||||
let scope = self.upcast::<WorkerGlobalScope>();
|
||||
|
@ -314,16 +310,9 @@ impl DedicatedWorkerGlobalScope {
|
|||
data.read(scope.upcast(), message.handle_mut());
|
||||
MessageEvent::dispatch_jsval(target, scope.upcast(), message.handle());
|
||||
},
|
||||
WorkerScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
||||
runnable.handler()
|
||||
WorkerScriptMsg::Common(msg) => {
|
||||
self.upcast::<WorkerGlobalScope>().process_event(msg);
|
||||
},
|
||||
WorkerScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) => {
|
||||
let scope = self.upcast::<WorkerGlobalScope>();
|
||||
let cx = scope.get_cx();
|
||||
let path_seg = format!("url({})", scope.get_url());
|
||||
let reports = get_reports(cx, path_seg);
|
||||
reports_chan.send(reports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ use js::jsval::UndefinedValue;
|
|||
use js::rust::Runtime;
|
||||
use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
||||
use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx, ScriptChan};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, StackRootTLS, new_rt_and_cx};
|
||||
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
|
||||
use servo_config::prefs::PREFS;
|
||||
use servo_rand::random;
|
||||
|
@ -262,15 +262,8 @@ impl ServiceWorkerGlobalScope {
|
|||
data.read(scope.upcast(), message.handle_mut());
|
||||
ExtendableMessageEvent::dispatch_jsval(target, scope.upcast(), message.handle());
|
||||
},
|
||||
CommonWorker(WorkerScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable))) => {
|
||||
runnable.handler()
|
||||
},
|
||||
CommonWorker(WorkerScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan))) => {
|
||||
let scope = self.upcast::<WorkerGlobalScope>();
|
||||
let cx = scope.get_cx();
|
||||
let path_seg = format!("url({})", scope.get_url());
|
||||
let reports = get_reports(cx, path_seg);
|
||||
reports_chan.send(reports);
|
||||
CommonWorker(WorkerScriptMsg::Common(msg)) => {
|
||||
self.upcast::<WorkerGlobalScope>().process_event(msg);
|
||||
},
|
||||
Response(mediator) => {
|
||||
// TODO XXXcreativcoder This will eventually use a FetchEvent interface to fire event
|
||||
|
@ -313,10 +306,6 @@ impl ServiceWorkerGlobalScope {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||
self.handle_script_event(ServiceWorkerScriptMsg::CommonWorker(WorkerScriptMsg::Common(msg)));
|
||||
}
|
||||
|
||||
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
||||
box ServiceWorkerChan {
|
||||
sender: self.own_sender.clone()
|
||||
|
|
|
@ -32,7 +32,7 @@ use js::panic::maybe_resume_unwind;
|
|||
use js::rust::Runtime;
|
||||
use net_traits::{IpcSend, load_whole_resource};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, get_reports};
|
||||
use script_thread::RunnableWrapper;
|
||||
use script_traits::{TimerEvent, TimerEventId};
|
||||
use script_traits::WorkerGlobalScopeInit;
|
||||
|
@ -386,17 +386,19 @@ impl WorkerGlobalScope {
|
|||
}
|
||||
|
||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>();
|
||||
let service_worker = self.downcast::<ServiceWorkerGlobalScope>();
|
||||
if let Some(dedicated) = dedicated {
|
||||
return dedicated.process_event(msg);
|
||||
} else if let Some(service_worker) = service_worker {
|
||||
return service_worker.process_event(msg);
|
||||
} else {
|
||||
panic!("need to implement a sender for SharedWorker")
|
||||
match msg {
|
||||
CommonScriptMsg::RunnableMsg(_, runnable) => {
|
||||
runnable.handler()
|
||||
},
|
||||
CommonScriptMsg::CollectReports(reports_chan) => {
|
||||
let cx = self.get_cx();
|
||||
let path_seg = format!("url({})", self.get_url());
|
||||
let reports = get_reports(cx, path_seg);
|
||||
reports_chan.send(reports);
|
||||
},
|
||||
}
|
||||
|
||||
//XXXjdm should we do a microtask checkpoint here?
|
||||
// FIXME(jdm): Should we do a microtask checkpoint here?
|
||||
}
|
||||
|
||||
pub fn handle_fire_timer(&self, timer_id: TimerEventId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue