diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-08-28 19:19:41 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-08-28 19:19:41 +0200 |
commit | 9060772af99bcdf7b7a1fe2b1d7bedfcbf65ad4d (patch) | |
tree | 1a5940ebe5fc3009ceed3ed35008c6090dc8f9b3 /src | |
parent | 14d596c1bc6c398b1d3ba2a8017499b116791c44 (diff) | |
parent | f925343552710025951d2ee0d85b131edc41f053 (diff) | |
download | servo-9060772af99bcdf7b7a1fe2b1d7bedfcbf65ad4d.tar.gz servo-9060772af99bcdf7b7a1fe2b1d7bedfcbf65ad4d.zip |
Merge pull request #3177 from Ms2ger/ConstantSpec
Introduce ConstantSpec::get_value; r=jdm
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/dom/bindings/utils.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 7e63c8f7f80..08b65dd084d 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -222,6 +222,20 @@ pub struct ConstantSpec { 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. pub struct NativePropertyHooks { /// The property arrays for this interface. @@ -349,17 +363,9 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m /// Fails on JSAPI failure. fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) { 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 { 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_PERMANENT) != 0); } |