Remove the pointless terminator from ConstantSpec slices.

This commit is contained in:
Ms2ger 2014-06-06 14:10:41 +02:00
parent 0c54cd1634
commit ba68203ebf
2 changed files with 10 additions and 16 deletions

View file

@ -1073,7 +1073,7 @@ class PropertyDefiner:
specTemplate is a template for each entry of the spec array specTemplate is a template for each entry of the spec array
specTerminator is a terminator for the spec array (inserted at the end specTerminator is a terminator for the spec array (inserted at the end
of the array) of the array), or None
specType is the actual typename of our spec specType is the actual typename of our spec
@ -1086,7 +1086,8 @@ class PropertyDefiner:
for member in array: for member in array:
specs.append(specTemplate % getDataTuple(member)) specs.append(specTemplate % getDataTuple(member))
specs.append(specTerminator) if specTerminator:
specs.append(specTerminator)
return (("static %s: [%s, ..%i] = [\n" + return (("static %s: [%s, ..%i] = [\n" +
",\n".join(specs) + "\n" + ",\n".join(specs) + "\n" +
@ -1254,7 +1255,7 @@ class ConstDefiner(PropertyDefiner):
return decls + self.generatePrefableArray( return decls + self.generatePrefableArray(
array, name, array, name,
' ConstantSpec { name: &%s_name as *u8 as *libc::c_char, value: %s }', ' ConstantSpec { name: &%s_name as *u8 as *libc::c_char, value: %s }',
' ConstantSpec { name: 0 as *libc::c_char, value: VoidVal }', None,
'ConstantSpec', 'ConstantSpec',
specData) specData)

View file

@ -312,10 +312,8 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
} }
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) -> bool { fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) -> bool {
for spec in constants.iter() { constants.iter().all(|spec| {
if spec.name.is_null() { assert!(spec.name.is_not_null());
return true;
}
let jsval = match spec.value { let jsval = match spec.value {
NullVal => NullValue(), NullVal => NullValue(),
IntVal(i) => Int32Value(i), IntVal(i) => Int32Value(i),
@ -325,16 +323,11 @@ fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [
VoidVal => UndefinedValue(), VoidVal => UndefinedValue(),
}; };
unsafe { unsafe {
if JS_DefineProperty(cx, obj, spec.name, JS_DefineProperty(cx, obj, spec.name, jsval, None, None,
jsval, None, JSPROP_ENUMERATE | JSPROP_READONLY |
None, JSPROP_PERMANENT) != 0
JSPROP_ENUMERATE | JSPROP_READONLY |
JSPROP_PERMANENT) == 0 {
return false;
}
} }
} })
fail!();
} }
fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: &'static [JSFunctionSpec]) -> bool { fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: &'static [JSFunctionSpec]) -> bool {