diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-01-24 20:48:57 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-01-24 20:48:57 +0530 |
commit | e93a460db4902195ec64e6fe67817f9e3a7c1da9 (patch) | |
tree | d7a3b5dc507fcf2e7caab065305e873190754d61 /components/script/dom/bindings/utils.rs | |
parent | 525e77f64fc65ea2397b4ff3849f5b1f39386698 (diff) | |
parent | e54929b4d796affce89844ecb4ae31d503b26c1d (diff) | |
download | servo-e93a460db4902195ec64e6fe67817f9e3a7c1da9.tar.gz servo-e93a460db4902195ec64e6fe67817f9e3a7c1da9.zip |
Auto merge of #9413 - nxnfufunezn:issue-9412, r=nox
Move ConstantSpec, NonNullJSNative and define_constants from utils to interface
Fixes #9412
r? @nox
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9413)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/utils.rs')
-rw-r--r-- | components/script/dom/bindings/utils.rs | 67 |
1 files changed, 5 insertions, 62 deletions
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 6534d5171cb..d34d8f3f9f4 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -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, |