mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Move ConstantSpec, NonNullJSNative and define_constants from utils to interface
This commit is contained in:
parent
525e77f64f
commit
e54929b4d7
3 changed files with 72 additions and 68 deletions
|
@ -22,16 +22,16 @@ use js::glue::{RUST_JSID_TO_INT, UnwrapObject};
|
|||
use js::jsapi::{CallArgs, CompartmentOptions, DOMCallbacks, GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSAutoCompartment, JSClass, JSContext};
|
||||
use js::jsapi::{JSJitInfo, JSObject, JSTraceOp, JSTracer, JSVersion, JSWrapObjectCallbacks};
|
||||
use js::jsapi::{JS_DefineProperty, JS_DeletePropertyById1, JS_FireOnNewGlobalObject};
|
||||
use js::jsapi::{JS_DeletePropertyById1, JS_FireOnNewGlobalObject};
|
||||
use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetClass, JS_GetProperty, JS_GetPrototype};
|
||||
use js::jsapi::{JS_GetReservedSlot, JS_HasProperty, JS_HasPropertyById, JS_InitStandardClasses};
|
||||
use js::jsapi::{JS_IsExceptionPending, JS_NewGlobalObject, JS_ObjectToOuterObject, JS_SetProperty};
|
||||
use js::jsapi::{JS_SetReservedSlot, MutableHandleValue, ObjectOpResult, OnNewGlobalHookOption};
|
||||
use js::jsapi::{RootedObject, RootedValue};
|
||||
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue};
|
||||
use js::jsval::{PrivateValue, UInt32Value, UndefinedValue};
|
||||
use js::jsapi::{RootedObject};
|
||||
use js::jsval::{JSVal};
|
||||
use js::jsval::{PrivateValue, UndefinedValue};
|
||||
use js::rust::{GCMethods, ToString};
|
||||
use js::{JS_CALLEE, JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY};
|
||||
use js::{JS_CALLEE};
|
||||
use libc::{self, c_uint};
|
||||
use std::default::Default;
|
||||
use std::ffi::CString;
|
||||
|
@ -79,42 +79,6 @@ pub const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT;
|
|||
// changes.
|
||||
pub const JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1;
|
||||
|
||||
/// Representation of an IDL constant value.
|
||||
#[derive(Clone)]
|
||||
pub enum ConstantVal {
|
||||
/// `long` constant.
|
||||
IntVal(i32),
|
||||
/// `unsigned long` constant.
|
||||
UintVal(u32),
|
||||
/// `double` constant.
|
||||
DoubleVal(f64),
|
||||
/// `boolean` constant.
|
||||
BoolVal(bool),
|
||||
/// `null` constant.
|
||||
NullVal,
|
||||
}
|
||||
|
||||
/// Representation of an IDL constant.
|
||||
#[derive(Clone)]
|
||||
pub struct ConstantSpec {
|
||||
/// name of the constant.
|
||||
pub name: &'static [u8],
|
||||
/// value of the constant.
|
||||
pub value: ConstantVal,
|
||||
}
|
||||
|
||||
impl ConstantSpec {
|
||||
/// Returns a `JSVal` that represents the value of this `ConstantSpec`.
|
||||
pub fn get_value(&self) -> JSVal {
|
||||
match self.value {
|
||||
ConstantVal::NullVal => NullValue(),
|
||||
ConstantVal::IntVal(i) => Int32Value(i),
|
||||
ConstantVal::UintVal(u) => UInt32Value(u),
|
||||
ConstantVal::DoubleVal(d) => DoubleValue(d),
|
||||
ConstantVal::BoolVal(b) => BooleanValue(b),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The struct that holds inheritance information for DOM object reflectors.
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -155,27 +119,6 @@ pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray
|
|||
}
|
||||
}
|
||||
|
||||
/// A JSNative that cannot be null.
|
||||
pub type NonNullJSNative =
|
||||
unsafe extern "C" fn (arg1: *mut JSContext, arg2: c_uint, arg3: *mut JSVal) -> bool;
|
||||
|
||||
/// Defines constants on `obj`.
|
||||
/// Fails on JSAPI failure.
|
||||
pub fn define_constants(cx: *mut JSContext, obj: HandleObject, constants: &'static [ConstantSpec]) {
|
||||
for spec in constants {
|
||||
let value = RootedValue::new(cx, spec.get_value());
|
||||
unsafe {
|
||||
assert!(JS_DefineProperty(cx,
|
||||
obj,
|
||||
spec.name.as_ptr() as *const libc::c_char,
|
||||
value.handle(),
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT,
|
||||
None,
|
||||
None));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A throwing constructor, for those interfaces that have neither
|
||||
/// `NoInterfaceObject` nor `Constructor`.
|
||||
pub unsafe extern "C" fn throwing_constructor(cx: *mut JSContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue