mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Pass the NativeProperties struct to CreateInterfaceObjects2.
This will simplify adding more kinds of properties, such as static attributes.
This commit is contained in:
parent
886d401ff0
commit
4964d2792e
2 changed files with 11 additions and 23 deletions
|
@ -1933,12 +1933,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
||||||
&PrototypeClass, %s,
|
&PrototypeClass, %s,
|
||||||
%s,
|
%s,
|
||||||
sNativeProperties.methods,
|
&sNativeProperties);""" % (constructor, domClass)
|
||||||
sNativeProperties.attrs,
|
|
||||||
sNativeProperties.consts,
|
|
||||||
sNativeProperties.staticMethods);""" % (
|
|
||||||
constructor,
|
|
||||||
domClass)
|
|
||||||
|
|
||||||
return CGList([
|
return CGList([
|
||||||
CGGeneric(getParentProto),
|
CGGeneric(getParentProto),
|
||||||
|
|
|
@ -230,13 +230,9 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
protoClass: &'static JSClass,
|
protoClass: &'static JSClass,
|
||||||
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
||||||
domClass: *DOMClass,
|
domClass: *DOMClass,
|
||||||
methods: Option<&'static [JSFunctionSpec]>,
|
members: &'static NativeProperties) -> *mut JSObject {
|
||||||
properties: Option<&'static [JSPropertySpec]>,
|
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>) -> *mut JSObject {
|
|
||||||
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||||
protoClass, methods,
|
protoClass, members);
|
||||||
properties, constants);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||||
|
@ -248,7 +244,7 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
name.to_c_str().with_ref(|s| {
|
name.to_c_str().with_ref(|s| {
|
||||||
CreateInterfaceObject(cx, global, receiver,
|
CreateInterfaceObject(cx, global, receiver,
|
||||||
native, nargs, proto,
|
native, nargs, proto,
|
||||||
staticMethods, constants, s)
|
members, s)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
None => (),
|
None => (),
|
||||||
|
@ -260,8 +256,7 @@ 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: NonNullJSNative,
|
constructorNative: NonNullJSNative,
|
||||||
ctorNargs: u32, proto: *mut JSObject,
|
ctorNargs: u32, proto: *mut JSObject,
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>,
|
members: &'static NativeProperties,
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
|
||||||
name: *libc::c_char) {
|
name: *libc::c_char) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs,
|
let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs,
|
||||||
|
@ -271,12 +266,12 @@ 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());
|
||||||
|
|
||||||
match staticMethods {
|
match members.staticMethods {
|
||||||
Some(staticMethods) => DefineMethods(cx, constructor, staticMethods),
|
Some(staticMethods) => DefineMethods(cx, constructor, staticMethods),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match constants {
|
match members.consts {
|
||||||
Some(constants) => DefineConstants(cx, constructor, constants),
|
Some(constants) => DefineConstants(cx, constructor, constants),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
@ -330,24 +325,22 @@ fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: &'static
|
||||||
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
||||||
parentProto: *mut JSObject,
|
parentProto: *mut JSObject,
|
||||||
protoClass: &'static JSClass,
|
protoClass: &'static JSClass,
|
||||||
methods: Option<&'static [JSFunctionSpec]>,
|
members: &'static NativeProperties) -> *mut JSObject {
|
||||||
properties: Option<&'static [JSPropertySpec]>,
|
|
||||||
constants: Option<&'static [ConstantSpec]>) -> *mut JSObject {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, parentProto, global);
|
||||||
assert!(ourProto.is_not_null());
|
assert!(ourProto.is_not_null());
|
||||||
|
|
||||||
match methods {
|
match members.methods {
|
||||||
Some(methods) => DefineMethods(cx, ourProto, methods),
|
Some(methods) => DefineMethods(cx, ourProto, methods),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match properties {
|
match members.attrs {
|
||||||
Some(properties) => DefineProperties(cx, ourProto, properties),
|
Some(properties) => DefineProperties(cx, ourProto, properties),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match constants {
|
match members.consts {
|
||||||
Some(constants) => DefineConstants(cx, ourProto, constants),
|
Some(constants) => DefineConstants(cx, ourProto, constants),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue