mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Pass slices to CreateInterfaceObjects2 rather than raw pointers.
This commit is contained in:
parent
3dece6b7ab
commit
0c54cd1634
2 changed files with 68 additions and 47 deletions
|
@ -1942,8 +1942,8 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
def arrayPtr(name):
|
def arrayPtr(name):
|
||||||
val = ('%(' + name + ')s') % self.properties.variableNames(False)
|
val = ('%(' + name + ')s') % self.properties.variableNames(False)
|
||||||
if val == "ptr::null()":
|
if val == "ptr::null()":
|
||||||
return val
|
return "None"
|
||||||
return "&%s[0]" % val
|
return "Some(%s.as_slice())" % val
|
||||||
|
|
||||||
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
||||||
%s, %s, %d,
|
%s, %s, %d,
|
||||||
|
|
|
@ -219,10 +219,10 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
constructor: JSNative,
|
constructor: JSNative,
|
||||||
ctorNargs: u32,
|
ctorNargs: u32,
|
||||||
domClass: *DOMClass,
|
domClass: *DOMClass,
|
||||||
methods: *JSFunctionSpec,
|
methods: Option<&'static [JSFunctionSpec]>,
|
||||||
properties: *JSPropertySpec,
|
properties: Option<&'static [JSPropertySpec]>,
|
||||||
constants: *ConstantSpec,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
staticMethods: *JSFunctionSpec,
|
staticMethods: Option<&'static [JSFunctionSpec]>,
|
||||||
name: &str) -> *mut JSObject {
|
name: &str) -> *mut JSObject {
|
||||||
let mut proto = ptr::mut_null();
|
let mut proto = ptr::mut_null();
|
||||||
if protoClass.is_not_null() {
|
if protoClass.is_not_null() {
|
||||||
|
@ -261,8 +261,8 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
constructorNative: JSNative,
|
constructorNative: JSNative,
|
||||||
ctorNargs: u32, proto: *mut JSObject,
|
ctorNargs: u32, proto: *mut JSObject,
|
||||||
staticMethods: *JSFunctionSpec,
|
staticMethods: Option<&'static [JSFunctionSpec]>,
|
||||||
constants: *ConstantSpec,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
name: *libc::c_char) -> *mut JSObject {
|
name: *libc::c_char) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
||||||
|
@ -274,15 +274,23 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
|
||||||
let constructor = JS_GetFunctionObject(fun);
|
let constructor = JS_GetFunctionObject(fun);
|
||||||
assert!(constructor.is_not_null());
|
assert!(constructor.is_not_null());
|
||||||
|
|
||||||
if staticMethods.is_not_null() &&
|
match staticMethods {
|
||||||
!DefineMethods(cx, constructor, staticMethods) {
|
Some(staticMethods) => {
|
||||||
|
if !DefineMethods(cx, constructor, staticMethods) {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
if constants.is_not_null() &&
|
match constants {
|
||||||
!DefineConstants(cx, constructor, constants) {
|
Some(constants) => {
|
||||||
|
if !DefineConstants(cx, constructor, constants) {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
|
if proto.is_not_null() && JS_LinkConstructorAndPrototype(cx, constructor, proto) == 0 {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
|
@ -303,11 +311,8 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: *ConstantSpec) -> bool {
|
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) -> bool {
|
||||||
let mut i = 0;
|
for spec in constants.iter() {
|
||||||
loop {
|
|
||||||
unsafe {
|
|
||||||
let spec = *constants.offset(i);
|
|
||||||
if spec.name.is_null() {
|
if spec.name.is_null() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -319,6 +324,7 @@ fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: *ConstantS
|
||||||
BoolVal(b) => BooleanValue(b),
|
BoolVal(b) => BooleanValue(b),
|
||||||
VoidVal => UndefinedValue(),
|
VoidVal => UndefinedValue(),
|
||||||
};
|
};
|
||||||
|
unsafe {
|
||||||
if JS_DefineProperty(cx, obj, spec.name,
|
if JS_DefineProperty(cx, obj, spec.name,
|
||||||
jsval, None,
|
jsval, None,
|
||||||
None,
|
None,
|
||||||
|
@ -327,44 +333,59 @@ fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: *ConstantS
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += 1;
|
}
|
||||||
|
fail!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: &'static [JSFunctionSpec]) -> bool {
|
||||||
|
unsafe {
|
||||||
|
JS_DefineFunctions(cx, obj, methods.as_ptr()) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: *JSFunctionSpec) -> bool {
|
fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: &'static [JSPropertySpec]) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_DefineFunctions(cx, obj, methods) != 0
|
JS_DefineProperties(cx, obj, properties.as_ptr()) != 0
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: *JSPropertySpec) -> bool {
|
|
||||||
unsafe {
|
|
||||||
JS_DefineProperties(cx, obj, properties) != 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
||||||
parentProto: *mut JSObject, protoClass: *JSClass,
|
parentProto: *mut JSObject, protoClass: *JSClass,
|
||||||
methods: *JSFunctionSpec,
|
methods: Option<&'static [JSFunctionSpec]>,
|
||||||
properties: *JSPropertySpec,
|
properties: Option<&'static [JSPropertySpec]>,
|
||||||
constants: *ConstantSpec) -> *mut JSObject {
|
constants: Option<&'static [ConstantSpec]>) -> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
||||||
if ourProto.is_null() {
|
if ourProto.is_null() {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
if methods.is_not_null() && !DefineMethods(cx, ourProto, methods) {
|
match methods {
|
||||||
|
Some(methods) => {
|
||||||
|
if !DefineMethods(cx, ourProto, methods) {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
if properties.is_not_null() && !DefineProperties(cx, ourProto, properties) {
|
_ => (),
|
||||||
return ptr::mut_null();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if constants.is_not_null() && !DefineConstants(cx, ourProto, constants) {
|
match properties {
|
||||||
|
Some(properties) => {
|
||||||
|
if !DefineProperties(cx, ourProto, properties) {
|
||||||
return ptr::mut_null();
|
return ptr::mut_null();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
match constants {
|
||||||
|
Some(constants) => {
|
||||||
|
if !DefineConstants(cx, ourProto, constants) {
|
||||||
|
return ptr::mut_null();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
return ourProto;
|
return ourProto;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue