Replace catch-all experimental flag with fine-grained boolean preferences initialized from a JSON document.

This commit is contained in:
Josh Matthews 2015-08-26 12:35:38 -04:00
parent 6431e8da43
commit a3ee9b5dd9
11 changed files with 95 additions and 46 deletions

View file

@ -17,7 +17,6 @@ use std::fs::{File, PathExt};
use std::io::{self, Read, Write};
use std::path::Path;
use std::process;
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
use url::{self, Url};
/// Global flags for Servo, currently set on the command line.
@ -50,9 +49,6 @@ pub struct Opts {
/// and cause it to produce output on that interval (`-m`).
pub mem_profiler_period: Option<f64>,
/// Enable experimental web features (`-e`).
pub enable_experimental: bool,
/// The number of threads to use for layout (`-y`). Defaults to 1, which results in a recursive
/// sequential algorithm.
pub layout_threads: usize,
@ -384,7 +380,6 @@ pub fn default_opts() -> Opts {
device_pixels_per_px: None,
time_profiler_period: None,
mem_profiler_period: None,
enable_experimental: false,
layout_threads: 1,
nonincremental_layout: false,
nossl: false,
@ -434,7 +429,6 @@ pub fn from_cmdline_args(args: &[String]) {
opts.optopt("o", "output", "Output file", "output.png");
opts.optopt("s", "size", "Size of tiles", "512");
opts.optopt("", "device-pixel-ratio", "Device pixels per px", "");
opts.optflag("e", "experimental", "Enable experimental web features");
opts.optopt("t", "threads", "Number of paint threads", "1");
opts.optflagopt("p", "profile", "Profiler flag and output interval", "10");
opts.optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10");
@ -589,7 +583,6 @@ pub fn from_cmdline_args(args: &[String]) {
device_pixels_per_px: device_pixels_per_px,
time_profiler_period: time_profiler_period,
mem_profiler_period: mem_profiler_period,
enable_experimental: opt_match.opt_present("e"),
layout_threads: layout_threads,
nonincremental_layout: nonincremental_layout,
nossl: nossl,
@ -632,19 +625,6 @@ pub fn from_cmdline_args(args: &[String]) {
set_defaults(opts);
}
static EXPERIMENTAL_ENABLED: AtomicBool = ATOMIC_BOOL_INIT;
/// Turn on experimental features globally. Normally this is done
/// during initialization by `set` or `from_cmdline_args`, but
/// tests that require experimental features will also set it.
pub fn set_experimental_enabled(new_value: bool) {
EXPERIMENTAL_ENABLED.store(new_value, Ordering::SeqCst);
}
pub fn experimental_enabled() -> bool {
EXPERIMENTAL_ENABLED.load(Ordering::SeqCst)
}
// Make Opts available globally. This saves having to clone and pass
// opts everywhere it is used, which gets particularly cumbersome
// when passing through the DOM structures.
@ -653,7 +633,7 @@ const INVALID_OPTIONS: *mut Opts = 0x01 as *mut Opts;
lazy_static! {
static ref OPTIONS: Opts = {
let opts = unsafe {
unsafe {
let initial = if !DEFAULT_OPTIONS.is_null() {
let opts = Box::from_raw(DEFAULT_OPTIONS);
*opts
@ -662,9 +642,7 @@ lazy_static! {
};
DEFAULT_OPTIONS = INVALID_OPTIONS;
initial
};
set_experimental_enabled(opts.enable_experimental);
opts
}
};
}