Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement [Func] #11308

Merged
merged 12 commits into from May 27, 2016

Simplify how Prefable arrays are passed in bindings::interface

  • Loading branch information
nox committed May 26, 2016
commit adcecda04736623eb4325f7a29c009ddc6b71cd8
@@ -2531,15 +2531,10 @@ def definition_body(self):
properties = {"id": name}
for arrayName in self.properties.arrayNames():
array = getattr(self.properties, arrayName)
if arrayName == "consts":
if array.length():
properties[arrayName] = array.variableName()
else:
properties[arrayName] = "&[]"
elif array.length():
properties[arrayName] = "Some(%s)" % array.variableName()
if array.length():
properties[arrayName] = array.variableName()
else:
properties[arrayName] = "None"
properties[arrayName] = "&[]"

code.append(CGGeneric("""
let mut prototype = RootedObject::new(cx, ptr::null_mut());
@@ -227,8 +227,8 @@ pub unsafe fn create_interface_prototype_object(
cx: *mut JSContext,
proto: HandleObject,
class: &'static JSClass,
regular_methods: Option<&'static [Prefable<JSFunctionSpec>]>,
regular_properties: Option<&'static [Prefable<JSPropertySpec>]>,
regular_methods: &'static [Prefable<JSFunctionSpec>],
regular_properties: &'static [Prefable<JSPropertySpec>],
constants: &'static [Prefable<ConstantSpec>],
rval: MutableHandleObject) {
create_object(cx, proto, class, regular_methods, regular_properties, constants, rval);
@@ -240,8 +240,8 @@ pub unsafe fn create_noncallback_interface_object(
receiver: HandleObject,
proto: HandleObject,
class: &'static NonCallbackInterfaceObjectClass,
static_methods: Option<&'static [Prefable<JSFunctionSpec>]>,
static_properties: Option<&'static [Prefable<JSPropertySpec>]>,
static_methods: &'static [Prefable<JSFunctionSpec>],
static_properties: &'static [Prefable<JSPropertySpec>],
constants: &'static [Prefable<ConstantSpec>],
interface_prototype_object: HandleObject,
name: &'static [u8],
@@ -354,36 +354,34 @@ unsafe fn create_object(
cx: *mut JSContext,
proto: HandleObject,
class: &'static JSClass,
methods: Option<&'static [Prefable<JSFunctionSpec>]>,
properties: Option<&'static [Prefable<JSPropertySpec>]>,
methods: &'static [Prefable<JSFunctionSpec>],
properties: &'static [Prefable<JSPropertySpec>],
constants: &'static [Prefable<ConstantSpec>],
rval: MutableHandleObject) {
rval.set(JS_NewObjectWithUniqueType(cx, class, proto));
assert!(!rval.ptr.is_null());
if let Some(methods) = methods {
define_prefable_methods(cx, rval.handle(), methods);
}
if let Some(properties) = properties {
define_prefable_properties(cx, rval.handle(), properties);
}
define_prefable_methods(cx, rval.handle(), methods);
define_prefable_properties(cx, rval.handle(), properties);
for prefable in constants {
define_constants(cx, rval.handle(), prefable.specs());
}
}

/// Conditionally define methods on an object.
pub unsafe fn define_prefable_methods(cx: *mut JSContext,
obj: HandleObject,
methods: &'static [Prefable<JSFunctionSpec>]) {
pub unsafe fn define_prefable_methods(
cx: *mut JSContext,
obj: HandleObject,
methods: &'static [Prefable<JSFunctionSpec>]) {
for prefable in methods {
define_methods(cx, obj, prefable.specs()).unwrap();
}
}

/// Conditionally define properties on an object.
pub unsafe fn define_prefable_properties(cx: *mut JSContext,
obj: HandleObject,
properties: &'static [Prefable<JSPropertySpec>]) {
pub unsafe fn define_prefable_properties(
cx: *mut JSContext,
obj: HandleObject,
properties: &'static [Prefable<JSPropertySpec>]) {
for prefable in properties {
define_properties(cx, obj, prefable.specs()).unwrap();
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.