mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Introduce ConstantSpec::get_value.
I'll need it for cross-origin wrappers as well.
This commit is contained in:
parent
14d596c1bc
commit
f925343552
1 changed files with 15 additions and 9 deletions
|
@ -222,6 +222,20 @@ pub struct ConstantSpec {
|
||||||
pub value: ConstantVal
|
pub value: ConstantVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ConstantSpec {
|
||||||
|
/// Returns a `JSVal` that represents the value of this `ConstantSpec`.
|
||||||
|
pub fn get_value(&self) -> JSVal {
|
||||||
|
match self.value {
|
||||||
|
NullVal => NullValue(),
|
||||||
|
IntVal(i) => Int32Value(i),
|
||||||
|
UintVal(u) => UInt32Value(u),
|
||||||
|
DoubleVal(d) => DoubleValue(d),
|
||||||
|
BoolVal(b) => BooleanValue(b),
|
||||||
|
VoidVal => UndefinedValue(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper structure for cross-origin wrappers for DOM binding objects.
|
/// Helper structure for cross-origin wrappers for DOM binding objects.
|
||||||
pub struct NativePropertyHooks {
|
pub struct NativePropertyHooks {
|
||||||
/// The property arrays for this interface.
|
/// The property arrays for this interface.
|
||||||
|
@ -349,17 +363,9 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) {
|
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) {
|
||||||
for spec in constants.iter() {
|
for spec in constants.iter() {
|
||||||
let jsval = match spec.value {
|
|
||||||
NullVal => NullValue(),
|
|
||||||
IntVal(i) => Int32Value(i),
|
|
||||||
UintVal(u) => UInt32Value(u),
|
|
||||||
DoubleVal(d) => DoubleValue(d),
|
|
||||||
BoolVal(b) => BooleanValue(b),
|
|
||||||
VoidVal => UndefinedValue(),
|
|
||||||
};
|
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char,
|
assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char,
|
||||||
jsval, None, None,
|
spec.get_value(), None, None,
|
||||||
JSPROP_ENUMERATE | JSPROP_READONLY |
|
JSPROP_ENUMERATE | JSPROP_READONLY |
|
||||||
JSPROP_PERMANENT) != 0);
|
JSPROP_PERMANENT) != 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue