Implement static methods (fixes #1989).

This commit is contained in:
Ms2ger 2014-06-17 22:17:02 +02:00
parent 92f9fe59e5
commit 6d2784aece
3 changed files with 54 additions and 4 deletions

View file

@ -1126,6 +1126,7 @@ class MethodDefiner(PropertyDefiner):
m.isMethod() and m.isStatic() == static and m.isMethod() and m.isStatic() == static and
not m.isIdentifierLess()] not m.isIdentifierLess()]
self.regular = [{"name": m.identifier.name, self.regular = [{"name": m.identifier.name,
"methodInfo": not m.isStatic(),
"length": methodLength(m), "length": methodLength(m),
"flags": "JSPROP_ENUMERATE" } "flags": "JSPROP_ENUMERATE" }
for m in methods] for m in methods]
@ -2368,6 +2369,30 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
def generate_code(self): def generate_code(self):
assert(False) # Override me assert(False) # Override me
class CGAbstractStaticBindingMethod(CGAbstractMethod):
"""
Common class to generate the JSNatives for all our static methods, getters
and setters. This will generate the function declaration and unwrap the
global object. Subclasses are expected to override the generate_code
function to do the rest of the work. This function should return a
CGThing which is already properly indented.
"""
def __init__(self, descriptor, name):
args = [
Argument('*mut JSContext', 'cx'),
Argument('libc::c_uint', 'argc'),
Argument('*mut JSVal', 'vp'),
]
CGAbstractMethod.__init__(self, descriptor, name, "JSBool", args, extern=True)
def definition_body(self):
return self.generate_code()
def generate_code(self):
assert False # Override me
class CGGenericMethod(CGAbstractBindingMethod): class CGGenericMethod(CGAbstractBindingMethod):
""" """
A class for generating the C++ code for an IDL method.. A class for generating the C++ code for an IDL method..
@ -2407,6 +2432,21 @@ class CGSpecializedMethod(CGAbstractExternMethod):
def makeNativeName(descriptor, method): def makeNativeName(descriptor, method):
return MakeNativeName(method.identifier.name) return MakeNativeName(method.identifier.name)
class CGStaticMethod(CGAbstractStaticBindingMethod):
"""
A class for generating the Rust code for an IDL static method.
"""
def __init__(self, descriptor, method):
self.method = method
name = method.identifier.name
CGAbstractStaticBindingMethod.__init__(self, descriptor, name)
def generate_code(self):
nativeName = CGSpecializedMethod.makeNativeName(self.descriptor,
self.method)
return CGMethodCall([], nativeName, True, self.descriptor, self.method)
class CGGenericGetter(CGAbstractBindingMethod): class CGGenericGetter(CGAbstractBindingMethod):
""" """
A class for generating the C++ code for an IDL attribute getter. A class for generating the C++ code for an IDL attribute getter.
@ -3850,10 +3890,14 @@ class CGDescriptor(CGThing):
(hasMethod, hasGetter, hasLenientGetter, (hasMethod, hasGetter, hasLenientGetter,
hasSetter, hasLenientSetter) = False, False, False, False, False hasSetter, hasLenientSetter) = False, False, False, False, False
for m in descriptor.interface.members: for m in descriptor.interface.members:
if m.isMethod() and not m.isStatic() and not m.isIdentifierLess(): if m.isMethod() and not m.isIdentifierLess():
cgThings.append(CGSpecializedMethod(descriptor, m)) if m.isStatic():
cgThings.append(CGMemberJITInfo(descriptor, m)) assert descriptor.interface.hasInterfaceObject()
hasMethod = True cgThings.append(CGStaticMethod(descriptor, m))
elif descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGSpecializedMethod(descriptor, m))
cgThings.append(CGMemberJITInfo(descriptor, m))
hasMethod = True
elif m.isAttr(): elif m.isAttr():
cgThings.append(CGSpecializedGetter(descriptor, m)) cgThings.append(CGSpecializedGetter(descriptor, m))
if m.hasLenientThis(): if m.hasLenientThis():

View file

@ -296,6 +296,10 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
} }
} }
impl TestBinding {
pub fn ReceiveVoidStatic() {}
}
impl Reflectable for TestBinding { impl Reflectable for TestBinding {
fn reflector<'a>(&'a self) -> &'a Reflector { fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector &self.reflector

View file

@ -266,4 +266,6 @@ interface TestBinding {
void passVariadicUnion2((Event or DOMString)... args); void passVariadicUnion2((Event or DOMString)... args);
void passVariadicUnion3((Blob or DOMString)... args); void passVariadicUnion3((Blob or DOMString)... args);
void passVariadicAny(any... args); void passVariadicAny(any... args);
static void receiveVoidStatic();
}; };