mirror of
https://github.com/servo/servo.git
synced 2025-07-31 19:20:22 +01:00
Simplify how Prefable arrays are passed in bindings::interface
This commit is contained in:
parent
bee6f59b16
commit
adcecda047
2 changed files with 19 additions and 26 deletions
|
@ -2531,15 +2531,10 @@ assert!(!prototype_proto.ptr.is_null());""" % getPrototypeProto)]
|
||||||
properties = {"id": name}
|
properties = {"id": name}
|
||||||
for arrayName in self.properties.arrayNames():
|
for arrayName in self.properties.arrayNames():
|
||||||
array = getattr(self.properties, arrayName)
|
array = getattr(self.properties, arrayName)
|
||||||
if arrayName == "consts":
|
if array.length():
|
||||||
if array.length():
|
properties[arrayName] = array.variableName()
|
||||||
properties[arrayName] = array.variableName()
|
|
||||||
else:
|
|
||||||
properties[arrayName] = "&[]"
|
|
||||||
elif array.length():
|
|
||||||
properties[arrayName] = "Some(%s)" % array.variableName()
|
|
||||||
else:
|
else:
|
||||||
properties[arrayName] = "None"
|
properties[arrayName] = "&[]"
|
||||||
|
|
||||||
code.append(CGGeneric("""
|
code.append(CGGeneric("""
|
||||||
let mut prototype = RootedObject::new(cx, ptr::null_mut());
|
let mut prototype = RootedObject::new(cx, ptr::null_mut());
|
||||||
|
|
|
@ -227,8 +227,8 @@ pub unsafe fn create_interface_prototype_object(
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
proto: HandleObject,
|
proto: HandleObject,
|
||||||
class: &'static JSClass,
|
class: &'static JSClass,
|
||||||
regular_methods: Option<&'static [Prefable<JSFunctionSpec>]>,
|
regular_methods: &'static [Prefable<JSFunctionSpec>],
|
||||||
regular_properties: Option<&'static [Prefable<JSPropertySpec>]>,
|
regular_properties: &'static [Prefable<JSPropertySpec>],
|
||||||
constants: &'static [Prefable<ConstantSpec>],
|
constants: &'static [Prefable<ConstantSpec>],
|
||||||
rval: MutableHandleObject) {
|
rval: MutableHandleObject) {
|
||||||
create_object(cx, proto, class, regular_methods, regular_properties, constants, rval);
|
create_object(cx, proto, class, regular_methods, regular_properties, constants, rval);
|
||||||
|
@ -240,8 +240,8 @@ pub unsafe fn create_noncallback_interface_object(
|
||||||
receiver: HandleObject,
|
receiver: HandleObject,
|
||||||
proto: HandleObject,
|
proto: HandleObject,
|
||||||
class: &'static NonCallbackInterfaceObjectClass,
|
class: &'static NonCallbackInterfaceObjectClass,
|
||||||
static_methods: Option<&'static [Prefable<JSFunctionSpec>]>,
|
static_methods: &'static [Prefable<JSFunctionSpec>],
|
||||||
static_properties: Option<&'static [Prefable<JSPropertySpec>]>,
|
static_properties: &'static [Prefable<JSPropertySpec>],
|
||||||
constants: &'static [Prefable<ConstantSpec>],
|
constants: &'static [Prefable<ConstantSpec>],
|
||||||
interface_prototype_object: HandleObject,
|
interface_prototype_object: HandleObject,
|
||||||
name: &'static [u8],
|
name: &'static [u8],
|
||||||
|
@ -354,36 +354,34 @@ unsafe fn create_object(
|
||||||
cx: *mut JSContext,
|
cx: *mut JSContext,
|
||||||
proto: HandleObject,
|
proto: HandleObject,
|
||||||
class: &'static JSClass,
|
class: &'static JSClass,
|
||||||
methods: Option<&'static [Prefable<JSFunctionSpec>]>,
|
methods: &'static [Prefable<JSFunctionSpec>],
|
||||||
properties: Option<&'static [Prefable<JSPropertySpec>]>,
|
properties: &'static [Prefable<JSPropertySpec>],
|
||||||
constants: &'static [Prefable<ConstantSpec>],
|
constants: &'static [Prefable<ConstantSpec>],
|
||||||
rval: MutableHandleObject) {
|
rval: MutableHandleObject) {
|
||||||
rval.set(JS_NewObjectWithUniqueType(cx, class, proto));
|
rval.set(JS_NewObjectWithUniqueType(cx, class, proto));
|
||||||
assert!(!rval.ptr.is_null());
|
assert!(!rval.ptr.is_null());
|
||||||
if let Some(methods) = methods {
|
define_prefable_methods(cx, rval.handle(), methods);
|
||||||
define_prefable_methods(cx, rval.handle(), methods);
|
define_prefable_properties(cx, rval.handle(), properties);
|
||||||
}
|
|
||||||
if let Some(properties) = properties {
|
|
||||||
define_prefable_properties(cx, rval.handle(), properties);
|
|
||||||
}
|
|
||||||
for prefable in constants {
|
for prefable in constants {
|
||||||
define_constants(cx, rval.handle(), prefable.specs());
|
define_constants(cx, rval.handle(), prefable.specs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Conditionally define methods on an object.
|
/// Conditionally define methods on an object.
|
||||||
pub unsafe fn define_prefable_methods(cx: *mut JSContext,
|
pub unsafe fn define_prefable_methods(
|
||||||
obj: HandleObject,
|
cx: *mut JSContext,
|
||||||
methods: &'static [Prefable<JSFunctionSpec>]) {
|
obj: HandleObject,
|
||||||
|
methods: &'static [Prefable<JSFunctionSpec>]) {
|
||||||
for prefable in methods {
|
for prefable in methods {
|
||||||
define_methods(cx, obj, prefable.specs()).unwrap();
|
define_methods(cx, obj, prefable.specs()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Conditionally define properties on an object.
|
/// Conditionally define properties on an object.
|
||||||
pub unsafe fn define_prefable_properties(cx: *mut JSContext,
|
pub unsafe fn define_prefable_properties(
|
||||||
obj: HandleObject,
|
cx: *mut JSContext,
|
||||||
properties: &'static [Prefable<JSPropertySpec>]) {
|
obj: HandleObject,
|
||||||
|
properties: &'static [Prefable<JSPropertySpec>]) {
|
||||||
for prefable in properties {
|
for prefable in properties {
|
||||||
define_properties(cx, obj, prefable.specs()).unwrap();
|
define_properties(cx, obj, prefable.specs()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue