diff options
author | Josh Matthews <josh@joshmatthews.net> | 2025-01-10 03:19:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 08:19:19 +0000 |
commit | c94d909a8688589209cdf0c7ae58e40f9b8c411e (patch) | |
tree | 12febf23eed4438249fd4d276c4d8b35dee22a97 /components/script/dom/bindings/guard.rs | |
parent | f220d6d3a52296794cd19935e9e59cc75a179a44 (diff) | |
download | servo-c94d909a8688589209cdf0c7ae58e40f9b8c411e.tar.gz servo-c94d909a8688589209cdf0c7ae58e40f9b8c411e.zip |
script: Limit public exports. (#34915)
* script: Restrict reexport visibility of DOM types.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Mass pub->pub(crate) conversion.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* script: Hide existing dead code warnings.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Formatting.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Fix clippy warnings.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Formatting.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Fix unit tests.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Fix clippy.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* More formatting.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/script/dom/bindings/guard.rs')
-rw-r--r-- | components/script/dom/bindings/guard.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs index 883d3067214..45e4473d821 100644 --- a/components/script/dom/bindings/guard.rs +++ b/components/script/dom/bindings/guard.rs @@ -14,21 +14,26 @@ use crate::realms::{AlreadyInRealm, InRealm}; use crate::script_runtime::JSContext; /// A container with a list of conditions. -pub struct Guard<T: Clone + Copy> { +pub(crate) struct Guard<T: Clone + Copy> { conditions: &'static [Condition], value: T, } impl<T: Clone + Copy> Guard<T> { /// Construct a new guarded value. - pub const fn new(conditions: &'static [Condition], value: T) -> Self { + pub(crate) const fn new(conditions: &'static [Condition], value: T) -> Self { Guard { conditions, value } } /// Expose the value if the conditions are satisfied. /// /// The passed handle is the object on which the value may be exposed. - pub fn expose(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> Option<T> { + pub(crate) fn expose( + &self, + cx: JSContext, + obj: HandleObject, + global: HandleObject, + ) -> Option<T> { let mut exposed_on_global = false; let conditions_satisfied = self.conditions.iter().all(|c| match c { Condition::Satisfied => { @@ -53,7 +58,7 @@ impl<T: Clone + Copy> Guard<T> { /// A condition to expose things. #[derive(Clone, Copy)] -pub enum Condition { +pub(crate) enum Condition { /// The condition is satisfied if the function returns true. Func(fn(JSContext, HandleObject) -> bool), /// The condition is satisfied if the preference is set. @@ -73,7 +78,12 @@ fn is_secure_context(cx: JSContext) -> bool { } impl Condition { - pub fn is_satisfied(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> bool { + pub(crate) fn is_satisfied( + &self, + cx: JSContext, + obj: HandleObject, + global: HandleObject, + ) -> bool { match *self { Condition::Pref(name) => prefs::pref_map().get(name).as_bool().unwrap_or(false), Condition::Func(f) => f(cx, obj), |