mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Introduce GlobalScope::get_next_worker_id
This commit is contained in:
parent
38273fe7a8
commit
3e5c0c386c
6 changed files with 17 additions and 32 deletions
|
@ -7,7 +7,7 @@
|
|||
//! This module contains smart pointers to global scopes, to simplify writing
|
||||
//! code that works in workers as well as window scopes.
|
||||
|
||||
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
|
||||
use devtools_traits::ScriptToDevtoolsControlMsg;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::root_from_object;
|
||||
use dom::bindings::error::{ErrorInfo, report_pending_exception};
|
||||
|
@ -145,14 +145,6 @@ impl<'a> GlobalRef<'a> {
|
|||
self.resource_threads().sender()
|
||||
}
|
||||
|
||||
/// Get next worker id.
|
||||
pub fn get_next_worker_id(&self) -> WorkerId {
|
||||
match *self {
|
||||
GlobalRef::Window(ref window) => window.get_next_worker_id(),
|
||||
GlobalRef::Worker(ref worker) => worker.get_next_worker_id(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the URL for this global scope.
|
||||
pub fn get_url(&self) -> Url {
|
||||
match *self {
|
||||
|
|
|
@ -2,16 +2,19 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use devtools_traits::WorkerId;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::reflector::Reflectable;
|
||||
use dom::crypto::Crypto;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GlobalScope {
|
||||
eventtarget: EventTarget,
|
||||
crypto: MutNullableHeap<JS<Crypto>>,
|
||||
next_worker_id: Cell<WorkerId>,
|
||||
}
|
||||
|
||||
impl GlobalScope {
|
||||
|
@ -19,6 +22,7 @@ impl GlobalScope {
|
|||
GlobalScope {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
crypto: Default::default(),
|
||||
next_worker_id: Cell::new(WorkerId(0)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,4 +41,12 @@ impl GlobalScope {
|
|||
pub fn crypto(&self) -> Root<Crypto> {
|
||||
self.crypto.or_init(|| Crypto::new(self))
|
||||
}
|
||||
|
||||
/// Get next worker id.
|
||||
pub fn get_next_worker_id(&self) -> WorkerId {
|
||||
let worker_id = self.next_worker_id.get();
|
||||
let WorkerId(id_num) = worker_id;
|
||||
self.next_worker_id.set(WorkerId(id_num + 1));
|
||||
worker_id
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ impl ServiceWorkerRegistration {
|
|||
pipeline_id: Some(global.pipeline_id())
|
||||
};
|
||||
|
||||
let worker_id = global.get_next_worker_id();
|
||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
||||
let init = prepare_workerscope_init(global, None);
|
||||
ScopeThings {
|
||||
script_url: script_url,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType, WorkerId};
|
||||
use devtools_traits::{ScriptToDevtoolsControlMsg, TimelineMarker, TimelineMarkerType};
|
||||
use dom::bindings::callback::ExceptionHandling;
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
|
@ -175,8 +175,6 @@ pub struct Window {
|
|||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
timers: OneshotTimers,
|
||||
|
||||
next_worker_id: Cell<WorkerId>,
|
||||
|
||||
/// For sending messages to the memory profiler.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
|
@ -320,13 +318,6 @@ impl Window {
|
|||
self.image_cache_chan.clone()
|
||||
}
|
||||
|
||||
pub fn get_next_worker_id(&self) -> WorkerId {
|
||||
let worker_id = self.next_worker_id.get();
|
||||
let WorkerId(id_num) = worker_id;
|
||||
self.next_worker_id.set(WorkerId(id_num + 1));
|
||||
worker_id
|
||||
}
|
||||
|
||||
pub fn pipeline_id(&self) -> PipelineId {
|
||||
self.id
|
||||
}
|
||||
|
@ -1653,7 +1644,6 @@ impl Window {
|
|||
status: DOMRefCell::new(DOMString::new()),
|
||||
scheduler_chan: scheduler_chan.clone(),
|
||||
timers: OneshotTimers::new(timer_event_chan, scheduler_chan),
|
||||
next_worker_id: Cell::new(WorkerId(0)),
|
||||
id: id,
|
||||
parent_info: parent_info,
|
||||
dom_static: GlobalStaticData::new(),
|
||||
|
|
|
@ -91,7 +91,7 @@ impl Worker {
|
|||
};
|
||||
|
||||
let (devtools_sender, devtools_receiver) = ipc::channel().unwrap();
|
||||
let worker_id = global.get_next_worker_id();
|
||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
||||
if let Some(ref chan) = global.devtools_chan() {
|
||||
let pipeline_id = global.pipeline_id();
|
||||
let title = format!("Worker for {}", worker_url);
|
||||
|
|
|
@ -56,7 +56,7 @@ use url::Url;
|
|||
|
||||
pub fn prepare_workerscope_init(global: GlobalRef,
|
||||
devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>) -> WorkerGlobalScopeInit {
|
||||
let worker_id = global.get_next_worker_id();
|
||||
let worker_id = global.as_global_scope().get_next_worker_id();
|
||||
let init = WorkerGlobalScopeInit {
|
||||
resource_threads: global.resource_threads(),
|
||||
mem_profiler_chan: global.mem_profiler_chan().clone(),
|
||||
|
@ -84,7 +84,6 @@ pub struct WorkerGlobalScope {
|
|||
closing: Option<Arc<AtomicBool>>,
|
||||
#[ignore_heap_size_of = "Defined in js"]
|
||||
runtime: Runtime,
|
||||
next_worker_id: Cell<WorkerId>,
|
||||
#[ignore_heap_size_of = "Defined in std"]
|
||||
resource_threads: ResourceThreads,
|
||||
location: MutNullableHeap<JS<WorkerLocation>>,
|
||||
|
@ -137,7 +136,6 @@ impl WorkerGlobalScope {
|
|||
-> WorkerGlobalScope {
|
||||
WorkerGlobalScope {
|
||||
globalscope: GlobalScope::new_inherited(),
|
||||
next_worker_id: Cell::new(WorkerId(0)),
|
||||
worker_id: init.worker_id,
|
||||
pipeline_id: init.pipeline_id,
|
||||
worker_url: worker_url,
|
||||
|
@ -231,13 +229,6 @@ impl WorkerGlobalScope {
|
|||
self.worker_id.clone()
|
||||
}
|
||||
|
||||
pub fn get_next_worker_id(&self) -> WorkerId {
|
||||
let worker_id = self.next_worker_id.get();
|
||||
let WorkerId(id_num) = worker_id;
|
||||
self.next_worker_id.set(WorkerId(id_num + 1));
|
||||
worker_id
|
||||
}
|
||||
|
||||
pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
|
||||
RunnableWrapper {
|
||||
cancelled: self.closing.clone().unwrap(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue