aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/guard.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-05-21 00:09:06 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-05-27 00:55:02 +0200
commite179cb02fff68d12c1461dd655a991088c647d68 (patch)
tree79023bf587cbc711fd14f962eedfb11ad384b198 /components/script/dom/bindings/guard.rs
parent0d04acd50f3871d6a16e24516df44ef0cff3b829 (diff)
downloadservo-e179cb02fff68d12c1461dd655a991088c647d68.tar.gz
servo-e179cb02fff68d12c1461dd655a991088c647d68.zip
Implement [Func]
Diffstat (limited to 'components/script/dom/bindings/guard.rs')
-rw-r--r--components/script/dom/bindings/guard.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs
index 15b7c418a31..40faebbd4f2 100644
--- a/components/script/dom/bindings/guard.rs
+++ b/components/script/dom/bindings/guard.rs
@@ -4,6 +4,7 @@
//! Machinery to conditionally expose things.
+use js::jsapi::{HandleObject, JSContext};
use util::prefs::get_pref;
/// A container with a condition.
@@ -22,8 +23,10 @@ impl<T: Clone + Copy> Guard<T> {
}
/// Expose the value if the condition is satisfied.
- pub fn expose(&self) -> Option<T> {
- if self.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) {
Some(self.value)
} else {
None
@@ -33,6 +36,8 @@ impl<T: Clone + Copy> Guard<T> {
/// A condition to expose things.
pub enum Condition {
+ /// The condition is satisfied if the function returns true.
+ Func(unsafe fn(*mut JSContext, HandleObject) -> bool),
/// The condition is satisfied if the preference is set.
Pref(&'static str),
/// The condition is always satisfied.
@@ -40,9 +45,10 @@ pub enum Condition {
}
impl Condition {
- fn is_satisfied(&self) -> bool {
+ unsafe fn is_satisfied(&self, cx: *mut JSContext, obj: HandleObject) -> bool {
match *self {
Condition::Pref(name) => get_pref(name).as_boolean().unwrap_or(false),
+ Condition::Func(f) => f(cx, obj),
Condition::Satisfied => true,
}
}