Consolidated opts into a manual Default trait implementation (#35257)

Signed-off-by: Shalvin Deo <shalvin.deo@live.com>
This commit is contained in:
Shalvin 2025-02-01 21:18:09 +01:00 committed by GitHub
parent cdd6660113
commit ec6c4bc8fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,7 +15,7 @@ use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl; use servo_url::ServoUrl;
/// Global flags for Servo, currently set on the command line. /// Global flags for Servo, currently set on the command line.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Opts { pub struct Opts {
/// Whether or not the legacy layout system is enabled. /// Whether or not the legacy layout system is enabled.
pub legacy_layout: bool, pub legacy_layout: bool,
@ -207,43 +207,45 @@ pub enum OutputOptions {
Stdout(f64), Stdout(f64),
} }
pub fn default_opts() -> Opts { impl Default for Opts {
Opts { fn default() -> Self {
legacy_layout: false, Self {
time_profiling: None, legacy_layout: false,
time_profiler_trace_path: None, time_profiling: None,
mem_profiler_period: None, time_profiler_trace_path: None,
nonincremental_layout: false, mem_profiler_period: None,
userscripts: None, nonincremental_layout: false,
user_stylesheets: Vec::new(), userscripts: None,
output_file: None, user_stylesheets: Vec::new(),
headless: false, output_file: None,
hard_fail: true, headless: false,
webdriver_port: None, hard_fail: true,
initial_window_size: Size2D::new(1024, 740), webdriver_port: None,
screen_size_override: None, initial_window_size: Size2D::new(1024, 740),
multiprocess: false, screen_size_override: None,
background_hang_monitor: false, multiprocess: false,
random_pipeline_closure_probability: None, background_hang_monitor: false,
random_pipeline_closure_seed: None, random_pipeline_closure_probability: None,
sandbox: false, random_pipeline_closure_seed: None,
debug: Default::default(), sandbox: false,
exit_after_load: false, debug: Default::default(),
config_dir: None, exit_after_load: false,
shaders_dir: None, config_dir: None,
certificate_path: None, shaders_dir: None,
ignore_certificate_errors: false, certificate_path: None,
unminify_js: false, ignore_certificate_errors: false,
local_script_source: None, unminify_js: false,
unminify_css: false, local_script_source: None,
print_pwm: false, unminify_css: false,
print_pwm: false,
}
} }
} }
// Make Opts available globally. This saves having to clone and pass // Make Opts available globally. This saves having to clone and pass
// opts everywhere it is used, which gets particularly cumbersome // opts everywhere it is used, which gets particularly cumbersome
// when passing through the DOM structures. // when passing through the DOM structures.
static OPTIONS: LazyLock<RwLock<Opts>> = LazyLock::new(|| RwLock::new(default_opts())); static OPTIONS: LazyLock<RwLock<Opts>> = LazyLock::new(|| RwLock::new(Opts::default()));
pub fn set_options(opts: Opts) { pub fn set_options(opts: Opts) {
*OPTIONS.write().unwrap() = opts; *OPTIONS.write().unwrap() = opts;