mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Pass the interface object-related arguments to CreateInterfaceObjects2 together in an Option.
This clarifies the code and fixes our support of NoInterfaceObject interfaces.
This commit is contained in:
parent
f11e7ee0a9
commit
5acbea5199
2 changed files with 34 additions and 26 deletions
|
@ -1880,13 +1880,6 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
getParentProto = ("let parentProto: *mut JSObject = %s;\n"
|
getParentProto = ("let parentProto: *mut JSObject = %s;\n"
|
||||||
"assert!(parentProto.is_not_null());\n") % getParentProto
|
"assert!(parentProto.is_not_null());\n") % getParentProto
|
||||||
|
|
||||||
if self.descriptor.interface.ctor():
|
|
||||||
constructHook = CONSTRUCT_HOOK_NAME
|
|
||||||
constructArgs = methodLength(self.descriptor.interface.ctor())
|
|
||||||
else:
|
|
||||||
constructHook = "ThrowingConstructor"
|
|
||||||
constructArgs = 0
|
|
||||||
|
|
||||||
if self.descriptor.concrete:
|
if self.descriptor.concrete:
|
||||||
if self.descriptor.proxy:
|
if self.descriptor.proxy:
|
||||||
domClass = "&Class"
|
domClass = "&Class"
|
||||||
|
@ -1901,20 +1894,31 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
return "None"
|
return "None"
|
||||||
return "Some(%s.as_slice())" % val
|
return "Some(%s.as_slice())" % val
|
||||||
|
|
||||||
|
if needInterfaceObject:
|
||||||
|
if self.descriptor.interface.ctor():
|
||||||
|
constructHook = CONSTRUCT_HOOK_NAME
|
||||||
|
constructArgs = methodLength(self.descriptor.interface.ctor())
|
||||||
|
else:
|
||||||
|
constructHook = "ThrowingConstructor"
|
||||||
|
constructArgs = 0
|
||||||
|
|
||||||
|
constructor = 'Some((%s, "%s", %d))' % (
|
||||||
|
constructHook, self.descriptor.interface.identifier.name,
|
||||||
|
constructArgs)
|
||||||
|
else:
|
||||||
|
constructor = 'None'
|
||||||
|
|
||||||
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
||||||
&PrototypeClass, %s, %d,
|
&PrototypeClass, %s,
|
||||||
%s,
|
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s,
|
%s,
|
||||||
%s);""" % (
|
%s);""" % (
|
||||||
"Some(%s)" % constructHook if needInterfaceObject else "None",
|
constructor,
|
||||||
constructArgs,
|
|
||||||
domClass,
|
domClass,
|
||||||
arrayPtr("methods"), arrayPtr("attrs"),
|
arrayPtr("methods"), arrayPtr("attrs"),
|
||||||
arrayPtr("consts"), arrayPtr("staticMethods"),
|
arrayPtr("consts"), arrayPtr("staticMethods"))
|
||||||
'"' + self.descriptor.interface.identifier.name + '"' if needInterfaceObject else "ptr::null()")
|
|
||||||
|
|
||||||
functionBody = CGList(
|
functionBody = CGList(
|
||||||
[CGGeneric(getParentProto),
|
[CGGeneric(getParentProto),
|
||||||
|
|
|
@ -34,7 +34,7 @@ use js::jsapi::{JS_HasPropertyById, JS_GetPrototype};
|
||||||
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
||||||
use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
|
use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
|
||||||
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||||
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative};
|
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass};
|
||||||
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
|
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
|
||||||
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
|
||||||
use js::jsapi::{JSString};
|
use js::jsapi::{JSString};
|
||||||
|
@ -215,17 +215,18 @@ pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type NonNullJSNative =
|
||||||
|
unsafe extern "C" fn (arg1: *mut JSContext, arg2: c_uint, arg3: *mut JSVal) -> JSBool;
|
||||||
|
|
||||||
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
||||||
protoProto: *mut JSObject,
|
protoProto: *mut JSObject,
|
||||||
protoClass: &'static JSClass,
|
protoClass: &'static JSClass,
|
||||||
constructor: JSNative,
|
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
||||||
ctorNargs: u32,
|
|
||||||
domClass: *DOMClass,
|
domClass: *DOMClass,
|
||||||
methods: Option<&'static [JSFunctionSpec]>,
|
methods: Option<&'static [JSFunctionSpec]>,
|
||||||
properties: Option<&'static [JSPropertySpec]>,
|
properties: Option<&'static [JSPropertySpec]>,
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>,
|
staticMethods: Option<&'static [JSFunctionSpec]>) -> *mut JSObject {
|
||||||
name: &str) -> *mut JSObject {
|
|
||||||
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||||
protoClass, methods,
|
protoClass, methods,
|
||||||
properties, constants);
|
properties, constants);
|
||||||
|
@ -235,25 +236,28 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
PrivateValue(domClass as *libc::c_void));
|
PrivateValue(domClass as *libc::c_void));
|
||||||
}
|
}
|
||||||
|
|
||||||
if constructor.is_some() {
|
match constructor {
|
||||||
name.to_c_str().with_ref(|s| {
|
Some((native, name, nargs)) => {
|
||||||
CreateInterfaceObject(cx, global, receiver,
|
name.to_c_str().with_ref(|s| {
|
||||||
constructor, ctorNargs, proto,
|
CreateInterfaceObject(cx, global, receiver,
|
||||||
staticMethods, constants, s)
|
native, nargs, proto,
|
||||||
});
|
staticMethods, constants, s)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
proto
|
proto
|
||||||
}
|
}
|
||||||
|
|
||||||
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: NonNullJSNative,
|
||||||
ctorNargs: u32, proto: *mut JSObject,
|
ctorNargs: u32, proto: *mut JSObject,
|
||||||
staticMethods: Option<&'static [JSFunctionSpec]>,
|
staticMethods: Option<&'static [JSFunctionSpec]>,
|
||||||
constants: Option<&'static [ConstantSpec]>,
|
constants: Option<&'static [ConstantSpec]>,
|
||||||
name: *libc::c_char) {
|
name: *libc::c_char) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, constructorNative, ctorNargs,
|
let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs,
|
||||||
JSFUN_CONSTRUCTOR, global, name);
|
JSFUN_CONSTRUCTOR, global, name);
|
||||||
assert!(fun.is_not_null());
|
assert!(fun.is_not_null());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue