mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use safe JSContext when possible in interface.rs
This commit is contained in:
parent
8b070fef52
commit
78034a90d0
6 changed files with 194 additions and 176 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
use crate::dom::bindings::codegen::InterfaceObjectMap;
|
||||
use crate::dom::bindings::interface::is_exposed_in;
|
||||
use js::jsapi::JSContext;
|
||||
use crate::script_runtime::JSContext;
|
||||
use js::rust::HandleObject;
|
||||
use servo_config::prefs;
|
||||
|
||||
|
@ -28,12 +28,7 @@ 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,
|
||||
global: HandleObject,
|
||||
) -> Option<T> {
|
||||
pub fn expose(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> Option<T> {
|
||||
if self.condition.is_satisfied(cx, obj, global) {
|
||||
Some(self.value)
|
||||
} else {
|
||||
|
@ -45,7 +40,7 @@ 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),
|
||||
Func(fn(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.
|
||||
|
@ -55,12 +50,7 @@ pub enum Condition {
|
|||
}
|
||||
|
||||
impl Condition {
|
||||
unsafe fn is_satisfied(
|
||||
&self,
|
||||
cx: *mut JSContext,
|
||||
obj: HandleObject,
|
||||
global: HandleObject,
|
||||
) -> bool {
|
||||
fn is_satisfied(&self, cx: 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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue