use std::cell::RefCell;
use std::rc::Rc;
use super::transcript::TranscriptLine;
#[allow(
clippy::struct_excessive_bools,
reason = "each flag is one JavaScript property a script reads and writes \
— `Doc.delay`, `Doc.dirty`, `app.calculate`, \
`app.runtimeHighlight`, and the two request flags. They are not \
a state machine and grouping them into an enum would put names \
between the binding and the value it answers."
)]
#[derive(Debug)]
pub(crate) struct HostState {
pub(crate) transcript: Vec<TranscriptLine>,
pub(crate) timers: super::timer::Timers,
pub(crate) document: super::model::DocumentModel,
pub(crate) colors: std::collections::BTreeMap<String, super::color::Color>,
pub(crate) globals: super::global::Bag,
pub(crate) icon_names: Vec<String>,
pub(crate) field_writes: Vec<(u32, String)>,
pub(crate) calculate_requested: bool,
pub(crate) base_url: String,
pub(crate) delay: bool,
pub(crate) delayed_writes: Vec<(u32, Vec<String>)>,
pub(crate) app_calculate: bool,
pub(crate) app_runtime_highlight: bool,
pub(crate) dirty: bool,
pub(crate) event: super::event::EventState,
pub(crate) focus_requested: Option<u32>,
}
pub(crate) type Host = Rc<RefCell<HostState>>;
#[derive(Debug, Clone, Copy)]
pub(crate) struct ConfiguredZone {
pub(crate) zone: super::zone::Zone,
}
impl boa_engine::context::HostHooks for ConfiguredZone {
fn local_timezone_offset_seconds(&self, unix_time_seconds: i64) -> i32 {
self.zone.offset_secs_at(unix_time_seconds)
}
}
impl Default for HostState {
fn default() -> HostState {
HostState {
transcript: Vec::new(),
timers: super::timer::Timers::default(),
document: super::model::DocumentModel::empty(),
colors: super::color::initial(),
globals: super::global::Bag::new(),
icon_names: Vec::new(),
field_writes: Vec::new(),
base_url: String::new(),
app_calculate: true,
app_runtime_highlight: false,
delay: false,
delayed_writes: Vec::new(),
dirty: false,
calculate_requested: false,
focus_requested: None,
event: super::event::EventState::default(),
}
}
}