aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py3
-rw-r--r--components/script/dom/bindings/guard.rs12
-rw-r--r--components/script/dom/bindings/interface.rs8
3 files changed, 16 insertions, 7 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index f418a1ba569..73d9f7f3ed0 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1334,8 +1334,11 @@ def MemberCondition(pref, func):
"""
assert pref is None or isinstance(pref, str)
assert func is None or isinstance(func, str)
+ assert func is None or pref is None
if pref:
return 'Condition::Pref("%s")' % pref
+ if func:
+ return 'Condition::Func(%s)' % func
return "Condition::Satisfied"
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,
}
}
diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs
index 371e70372ac..590e57ba8e0 100644
--- a/components/script/dom/bindings/interface.rs
+++ b/components/script/dom/bindings/interface.rs
@@ -220,7 +220,7 @@ pub unsafe fn create_callback_interface_object(
rval.set(JS_NewObject(cx, ptr::null()));
assert!(!rval.ptr.is_null());
for guard in constants {
- if let Some(specs) = guard.expose() {
+ if let Some(specs) = guard.expose(cx, rval.handle()) {
define_constants(cx, rval.handle(), specs);
}
}
@@ -369,7 +369,7 @@ unsafe fn create_object(
define_guarded_methods(cx, rval.handle(), methods);
define_guarded_properties(cx, rval.handle(), properties);
for guard in constants {
- if let Some(specs) = guard.expose() {
+ if let Some(specs) = guard.expose(cx, rval.handle()) {
define_constants(cx, rval.handle(), specs);
}
}
@@ -381,7 +381,7 @@ pub unsafe fn define_guarded_methods(
obj: HandleObject,
methods: &[Guard<&'static [JSFunctionSpec]>]) {
for guard in methods {
- if let Some(specs) = guard.expose() {
+ if let Some(specs) = guard.expose(cx, obj) {
define_methods(cx, obj, specs).unwrap();
}
}
@@ -393,7 +393,7 @@ pub unsafe fn define_guarded_properties(
obj: HandleObject,
properties: &[Guard<&'static [JSPropertySpec]>]) {
for guard in properties {
- if let Some(specs) = guard.expose() {
+ if let Some(specs) = guard.expose(cx, obj) {
define_properties(cx, obj, specs).unwrap();
}
}