aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/utils.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2016-03-23 22:46:49 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-05-02 14:32:56 -0400
commitcb5bad63dc2e91adfc36e49af60fe49456427f20 (patch)
tree56f25880677b2077998d94bc856e98b4b0e53495 /components/script/dom/bindings/utils.rs
parent88059acd7efb4dceda48ec305528a247fd520c4f (diff)
downloadservo-cb5bad63dc2e91adfc36e49af60fe49456427f20.tar.gz
servo-cb5bad63dc2e91adfc36e49af60fe49456427f20.zip
Implement hiding of interface members via Pref annotations.
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r--components/script/dom/bindings/utils.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 1e2cf5c40f6..29eb33bdefd 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -41,6 +41,7 @@ use std::os::raw::c_void;
use std::ptr;
use std::slice;
use util::non_geckolib::jsstring_to_str;
+use util::prefs;
/// Proxy handler for a WindowProxy.
pub struct WindowProxyHandler(pub *const libc::c_void);
@@ -558,8 +559,30 @@ pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks {
instanceClassMatchesProto: Some(instance_class_has_proto_at_depth),
};
-#[allow(missing_docs)]
+/// A container around JS member specifications that are conditionally enabled.
pub struct Prefable<T: 'static> {
+ /// If present, the name of the preference used to conditionally enable these specs.
pub pref: Option<&'static str>,
- pub specs: &'static [T]
+ /// The underlying slice of specifications.
+ pub specs: &'static [T],
+ /// Whether the specifications contain special terminating entries that should be
+ /// included or not.
+ pub terminator: bool,
+}
+
+impl<T> Prefable<T> {
+ /// Retrieve the slice represented by this container, unless the condition
+ /// guarding it is false.
+ pub fn specs(&self) -> &'static [T] {
+ if let Some(pref) = self.pref {
+ if !prefs::get_pref(pref).as_boolean().unwrap_or(false) {
+ return if self.terminator {
+ &self.specs[self.specs.len() - 1..]
+ } else {
+ &[]
+ };
+ }
+ }
+ self.specs
+ }
}