diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-06-17 22:17:02 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-06-22 15:15:12 +0200 |
commit | 6d2784aece4d5e8a3a605ddb1397d3d7c0efdf0c (patch) | |
tree | 047d11424c7cb7ef2ba824d7cd2663a4971d39b4 | |
parent | 92f9fe59e5a60c99a6852a7c7da32e37eb384898 (diff) | |
download | servo-6d2784aece4d5e8a3a605ddb1397d3d7c0efdf0c.tar.gz servo-6d2784aece4d5e8a3a605ddb1397d3d7c0efdf0c.zip |
Implement static methods (fixes #1989).
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 52 | ||||
-rw-r--r-- | src/components/script/dom/testbinding.rs | 4 | ||||
-rw-r--r-- | src/components/script/dom/webidls/TestBinding.webidl | 2 |
3 files changed, 54 insertions, 4 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 8776b32d4a8..e0dde48b4cb 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1126,6 +1126,7 @@ class MethodDefiner(PropertyDefiner): m.isMethod() and m.isStatic() == static and not m.isIdentifierLess()] self.regular = [{"name": m.identifier.name, + "methodInfo": not m.isStatic(), "length": methodLength(m), "flags": "JSPROP_ENUMERATE" } for m in methods] @@ -2368,6 +2369,30 @@ class CGAbstractBindingMethod(CGAbstractExternMethod): def generate_code(self): 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): """ A class for generating the C++ code for an IDL method.. @@ -2407,6 +2432,21 @@ class CGSpecializedMethod(CGAbstractExternMethod): def makeNativeName(descriptor, method): 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): """ A class for generating the C++ code for an IDL attribute getter. @@ -3850,10 +3890,14 @@ class CGDescriptor(CGThing): (hasMethod, hasGetter, hasLenientGetter, hasSetter, hasLenientSetter) = False, False, False, False, False for m in descriptor.interface.members: - if m.isMethod() and not m.isStatic() and not m.isIdentifierLess(): - cgThings.append(CGSpecializedMethod(descriptor, m)) - cgThings.append(CGMemberJITInfo(descriptor, m)) - hasMethod = True + if m.isMethod() and not m.isIdentifierLess(): + if m.isStatic(): + assert descriptor.interface.hasInterfaceObject() + cgThings.append(CGStaticMethod(descriptor, m)) + elif descriptor.interface.hasInterfacePrototypeObject(): + cgThings.append(CGSpecializedMethod(descriptor, m)) + cgThings.append(CGMemberJITInfo(descriptor, m)) + hasMethod = True elif m.isAttr(): cgThings.append(CGSpecializedGetter(descriptor, m)) if m.hasLenientThis(): diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index d4826d881b9..6ee10aaad31 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -296,6 +296,10 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { } } +impl TestBinding { + pub fn ReceiveVoidStatic() {} +} + impl Reflectable for TestBinding { fn reflector<'a>(&'a self) -> &'a Reflector { &self.reflector diff --git a/src/components/script/dom/webidls/TestBinding.webidl b/src/components/script/dom/webidls/TestBinding.webidl index 2437514a2c1..ba977c2a773 100644 --- a/src/components/script/dom/webidls/TestBinding.webidl +++ b/src/components/script/dom/webidls/TestBinding.webidl @@ -266,4 +266,6 @@ interface TestBinding { void passVariadicUnion2((Event or DOMString)... args); void passVariadicUnion3((Blob or DOMString)... args); void passVariadicAny(any... args); + + static void receiveVoidStatic(); }; |