diff options
author | sreeise <reeisesean@gmail.com> | 2019-05-28 03:23:47 -0400 |
---|---|---|
committer | sreeise <reeisesean@gmail.com> | 2019-07-14 09:24:43 -0400 |
commit | 871239a3e302d4aefdbbad1b0141511dcd66afc4 (patch) | |
tree | 7c5907d5d1bef787d91c3bc469cb31436e20babc /components/script/dom/bindings/guard.rs | |
parent | 2b843483722de683c1277f803a9a45dd6afa09cf (diff) | |
download | servo-871239a3e302d4aefdbbad1b0141511dcd66afc4.tar.gz servo-871239a3e302d4aefdbbad1b0141511dcd66afc4.zip |
Change bindings generation to make Exposed annotation aware of members/partial interfaces
Diffstat (limited to 'components/script/dom/bindings/guard.rs')
-rw-r--r-- | components/script/dom/bindings/guard.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs index 5ab9971afb7..40052c7098e 100644 --- a/components/script/dom/bindings/guard.rs +++ b/components/script/dom/bindings/guard.rs @@ -4,6 +4,8 @@ //! Machinery to conditionally expose things. +use crate::dom::bindings::codegen::InterfaceObjectMap; +use crate::dom::bindings::interface::is_exposed_in; use js::jsapi::JSContext; use js::rust::HandleObject; use servo_config::prefs; @@ -26,8 +28,13 @@ impl<T: Clone + Copy> Guard<T> { /// Expose the value if the condition is satisfied. /// /// The passed handle is the object on which the value may be exposed. - pub unsafe fn expose(&self, cx: *mut JSContext, obj: HandleObject) -> Option<T> { - if self.condition.is_satisfied(cx, obj) { + pub unsafe fn expose( + &self, + cx: *mut JSContext, + obj: HandleObject, + global: HandleObject, + ) -> Option<T> { + if self.condition.is_satisfied(cx, obj, global) { Some(self.value) } else { None @@ -41,15 +48,23 @@ pub enum Condition { Func(unsafe fn(*mut JSContext, HandleObject) -> bool), /// The condition is satisfied if the preference is set. Pref(&'static str), + // The condition is satisfied if the interface is exposed in the global. + Exposed(InterfaceObjectMap::Globals), /// The condition is always satisfied. Satisfied, } impl Condition { - unsafe fn is_satisfied(&self, cx: *mut JSContext, obj: HandleObject) -> bool { + unsafe fn is_satisfied( + &self, + cx: *mut 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), + Condition::Exposed(globals) => is_exposed_in(global, globals), Condition::Satisfied => true, } } |