-
Notifications
You must be signed in to change notification settings - Fork 64
Allow the embedder to override all preferences #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ences" Bumps Stylo to servo/stylo#309 For consistency with Gecko, Stylo renames the `layout.threads` pref to `layout.css.stylo-threads`. But it seems fine to keep `--layout_threads` as the command argument. stylo-prefs
| pub fn get_bool(&self, key: &str, default: bool) -> bool { | ||
| let prefs = self.bool_prefs.read().expect("RwLock is poisoned"); | ||
| *prefs.get(key).unwrap_or(&false) | ||
| *prefs.get(key).unwrap_or(&default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate that the API now must take the default value rather than being able to look up the default value itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but static_prefs::pref!() gets the default automatically, and that's the API that we should use. E.g. Gecko doesn't have style_config::get_bool() at all.
| pub trait Getter { | ||
| fn get(key: &str, default: Self) -> Self; | ||
| } | ||
|
|
||
| impl Getter for bool { | ||
| fn get(key: &str, default: Self) -> Self { | ||
| get_bool(key, default) | ||
| } | ||
| } | ||
|
|
||
| impl Getter for i32 { | ||
| fn get(key: &str, default: Self) -> Self { | ||
| get_i32(key, default) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these used? I find it bizarre to add a get() method on i32 and bool. Maybe they can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this in
#[macro_export]
macro_rules! pref {
($string:tt) => {
style_config::Getter::get($string, $crate::default_value!($string))
};
}The reason is that static_prefs::pref!() can access both booleans and numbers, so I needed a trait for the specialization.
Previously, Stylo was hard-coding the value for various preferences. Now Stylo will only define the default value for the preferences, but if the embedder sets a different value, the latter will be used instead. For example, `layout.css.marker.restricted` should definitely default to true (according to the spec), but Servo should be allowed to set it to false e.g. for debugging purposes, or in specific tests. For consistent defaults, this replaces most `style_config::get_bool()` with `static_prefs::pref!()`. And the pref `layout.threads` gets renamed to `layout.css.stylo-threads`, in order to share code with Gecko. Signed-off-by: Oriol Brufau <[email protected]>
e77734e to
babc456
Compare
Previously, Stylo was hard-coding the value for various preferences. Now Stylo will only define the default value for the preferences, but if the embedder sets a different value, the latter will be used instead.
For example, when not set otherwise,
layout.threadsused to default to 0 as any other i32 pref. However, this was a bad default, it meant that embedders like Blitz were running Stylo single-threaded. With this change we can make it default to -1, while still allowing Servo to set it to 3.For consistent defaults, this replaces most
style_config::get_bool()withstatic_prefs::pref!().Servo PR: servo/servo#42491