Introduce static makeNativeName methods to share code with the upcoming static members.

This commit is contained in:
Ms2ger 2014-06-22 14:09:28 +02:00
parent 927ae39817
commit 92f9fe59e5

View file

@ -2396,12 +2396,17 @@ class CGSpecializedMethod(CGAbstractExternMethod):
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
def definition_body(self):
name = self.method.identifier.name
return CGWrapper(CGMethodCall([], MakeNativeName(name), self.method.isStatic(),
nativeName = CGSpecializedMethod.makeNativeName(self.descriptor,
self.method)
return CGWrapper(CGMethodCall([], nativeName, self.method.isStatic(),
self.descriptor, self.method),
pre="let this = JS::from_raw(this);\n"
"let mut this = this.root();\n")
@staticmethod
def makeNativeName(descriptor, method):
return MakeNativeName(method.identifier.name)
class CGGenericGetter(CGAbstractBindingMethod):
"""
A class for generating the C++ code for an IDL attribute getter.
@ -2441,18 +2446,25 @@ class CGSpecializedGetter(CGAbstractExternMethod):
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
def definition_body(self):
name = self.attr.identifier.name
nativeName = MakeNativeName(name)
infallible = ('infallible' in
self.descriptor.getExtendedAttributes(self.attr,
getter=True))
if self.attr.type.nullable() or not infallible:
nativeName = "Get" + nativeName
nativeName = CGSpecializedGetter.makeNativeName(self.descriptor,
self.attr)
return CGWrapper(CGGetterCall([], self.attr.type, nativeName,
self.descriptor, self.attr),
pre="let this = JS::from_raw(this);\n"
"let mut this = this.root();\n")
@staticmethod
def makeNativeName(descriptor, attr):
nativeName = MakeNativeName(attr.identifier.name)
infallible = ('infallible' in
descriptor.getExtendedAttributes(attr, getter=True))
if attr.type.nullable() or not infallible:
return "Get" + nativeName
return nativeName
class CGGenericSetter(CGAbstractBindingMethod):
"""
A class for generating the Rust code for an IDL attribute setter.
@ -2497,13 +2509,16 @@ class CGSpecializedSetter(CGAbstractExternMethod):
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
def definition_body(self):
name = self.attr.identifier.name
return CGWrapper(CGSetterCall([], self.attr.type,
"Set" + MakeNativeName(name),
nativeName = CGSpecializedSetter.makeNativeName(self.descriptor,
self.attr)
return CGWrapper(CGSetterCall([], self.attr.type, nativeName,
self.descriptor, self.attr),
pre="let this = JS::from_raw(this);\n"
"let mut this = this.root();\n")
@staticmethod
def makeNativeName(descriptor, attr):
return "Set" + MakeNativeName(attr.identifier.name)
class CGMemberJITInfo(CGThing):
"""