Change bindings generation to make Exposed annotation aware of members/partial interfaces

This commit is contained in:
sreeise 2019-05-28 03:23:47 -04:00
parent 2b84348372
commit 871239a3e3
25 changed files with 151 additions and 78 deletions

View file

@ -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,
}
}