Skip to main content

script/dom/workers/
abstractworker.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use script_bindings::reflector::DomObject;
6use servo_base::id::PipelineId;
7use servo_constellation_traits::StructuredSerializedData;
8use servo_url::ImmutableOrigin;
9
10use crate::dom::bindings::refcounted::Trusted;
11use crate::messaging::CommonScriptMsg;
12
13/// Messages used to control the worker event loops
14#[derive(MallocSizeOf)]
15pub(crate) enum WorkerScriptMsg {
16    /// Common variants associated with the script messages
17    Common(CommonScriptMsg),
18    /// Message sent through Worker.postMessage
19    DOMMessage(MessageData),
20}
21
22#[derive(MallocSizeOf)]
23pub(crate) struct MessageData {
24    pub origin: ImmutableOrigin,
25    pub data: Box<StructuredSerializedData>,
26    pub pipeline_id: PipelineId,
27}
28
29pub(crate) struct SimpleWorkerErrorHandler<T: DomObject> {
30    pub(crate) addr: Trusted<T>,
31}
32
33impl<T: DomObject> SimpleWorkerErrorHandler<T> {
34    pub(crate) fn new(addr: Trusted<T>) -> SimpleWorkerErrorHandler<T> {
35        SimpleWorkerErrorHandler { addr }
36    }
37}