Skip to content
Permalink
Browse files

Codegen style fix

  • Loading branch information
brunoabinader committed Dec 30, 2014
1 parent 7cca51b commit bb577968e5063c48cd534f2f3fc1f2fba1be26de
Showing with 47 additions and 32 deletions.
  1. +47 −32 components/script/dom/bindings/codegen/CodegenRust.py
@@ -107,8 +107,8 @@ def __init__(self, descriptor, source, codeOnFailure):
}

def __str__(self):
return string.Template(
"""match unwrap_jsmanaged(${source}) {
return string.Template("""\
match unwrap_jsmanaged(${source}) {
Ok(val) => val,
Err(()) => {
${codeOnFailure}
@@ -509,9 +509,7 @@ def firstCap(string):
return string[0].upper() + string[1:]

# Helper functions for dealing with failures due to the JS value being the
# wrong type of value
# Helper functions for dealing with failures due to the JS value being the
# wrong type of value
# wrong type of value.
def onFailureNotAnObject(failureCode):
return CGWrapper(
CGGeneric(
@@ -1421,7 +1419,8 @@ def DOMClass(descriptor):
# padding.
protoList.extend(['PrototypeList::ID::Count'] * (descriptor.config.maxProtoChainLength - len(protoList)))
prototypeChainString = ', '.join(protoList)
return """DOMClass {
return """\
DOMClass {
interface_chain: [ %s ],
native_hooks: &sNativePropertyHooks,
}""" % prototypeChainString
@@ -1620,7 +1619,8 @@ def define(self):
class CGCallbackTempRoot(CGGeneric):
def __init__(self, name):
val = "%s::new(tempRoot)" % name
define = """{
define = """\
{
let tempRoot = ${val}.to_object();
%s
}""" % val
@@ -1814,11 +1814,11 @@ def CreateBindingJSObject(descriptor, parent=None):
create += ("let obj = with_compartment(aCx, proto, || {\n"
" JS_NewObject(aCx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n"
"});\n" % parent)
create += """assert!(obj.is_not_null());
create += """\
assert!(obj.is_not_null());
JS_SetReservedSlot(obj, DOM_OBJECT_SLOT as u32,
PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void));\
"""
PrivateValue(squirrel_away_unique(aObject) as *const libc::c_void));"""
return create

class CGWrapMethod(CGAbstractMethod):
@@ -1998,7 +1998,8 @@ def definition_body(self):
else:
constructor = 'None'

call = """return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
call = """\
return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
&PrototypeClass, %s,
%s,
&sNativeProperties);""" % (constructor, domClass)
@@ -2132,7 +2133,6 @@ def definition_body(self):
return CGGeneric(body)



class CGDefineDOMInterfaceMethod(CGAbstractMethod):
"""
A method for resolve hooks to try to lazily define the interface object for
@@ -2888,7 +2888,8 @@ def define(self):
]
# XXXManishearth The following should be #[must_root],
# however we currently allow it till #2661 is fixed
return ("""#[allow(unrooted_must_root)]
return ("""\
#[allow(unrooted_must_root)]
pub enum %s {
%s
}
@@ -3145,7 +3146,8 @@ def __init__(self, baseClass, name, visibility='public'):
ClassItem.__init__(self, name, visibility)

def declare(self, cgClass):
return string.Template("""using ${baseClass}::${name};
return string.Template("""\
using ${baseClass}::${name};
""").substitute({ 'baseClass': self.baseClass,
'name': self.name })

@@ -3222,7 +3224,8 @@ def declare(self, cgClass):
body += '\n'
body = ' {\n' + body + '}'

return string.Template("""pub fn ${decorators}new(${args}) -> ${className}${body}
return string.Template("""\
pub fn ${decorators}new(${args}) -> ${className}${body}
""").substitute({ 'decorators': self.getDecorators(True),
'className': cgClass.getNameString(),
'args': args,
@@ -3239,7 +3242,8 @@ def define(self, cgClass):
if len(body) > 0:
body += '\n'

return string.Template("""${decorators}
return string.Template("""\
${decorators}
${className}::${className}(${args})${initializationList}
{${body}}
""").substitute({ 'decorators': self.getDecorators(False),
@@ -3295,7 +3299,8 @@ def declare(self, cgClass):
else:
body = ';'

return string.Template("""${decorators}~${className}()${body}
return string.Template("""\
${decorators}~${className}()${body}
""").substitute({ 'decorators': self.getDecorators(True),
'className': cgClass.getNameString(),
'body': body })
@@ -3309,7 +3314,8 @@ def define(self, cgClass):
if len(body) > 0:
body += '\n'

return string.Template("""${decorators}
return string.Template("""\
${decorators}
${className}::~${className}()
{${body}}
""").substitute({ 'decorators': self.getDecorators(False),
@@ -3597,7 +3603,8 @@ def __init__(self, descriptor):
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", '*const ' + descriptor.concreteType, args, alwaysInline=True)

def definition_body(self):
return CGGeneric("""/*if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
return CGGeneric("""\
/*if (xpc::WrapperFactory::IsXrayWrapper(obj)) {
obj = js::UnwrapObject(obj);
}*/
//MOZ_ASSERT(IsProxy(obj));
@@ -3681,7 +3688,8 @@ def getBody(self):
else:
namedGet = ""

return setOrIndexedGet + """let expando: *mut JSObject = GetExpandoObject(proxy);
return setOrIndexedGet + """\
let expando: *mut JSObject = GetExpandoObject(proxy);
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
if expando.is_not_null() {
let flags = if set { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
@@ -3818,7 +3826,8 @@ def getBody(self):
else:
named = ""

return indexed + """let expando: *mut JSObject = GetExpandoObject(proxy);
return indexed + """\
let expando: *mut JSObject = GetExpandoObject(proxy);
if expando.is_not_null() {
let mut b: JSBool = 1;
let ok = JS_HasPropertyById(cx, expando, id, &mut b) != 0;
@@ -3827,7 +3836,8 @@ def getBody(self):
return ok;
}
}
""" + named + """*bp = false;
""" + named + """\
*bp = false;
return true;"""

def definition_body(self):
@@ -3841,7 +3851,8 @@ def __init__(self, descriptor):
CGAbstractExternMethod.__init__(self, descriptor, "get", "bool", args)
self.descriptor = descriptor
def getBody(self):
getFromExpando = """let expando = GetExpandoObject(proxy);
getFromExpando = """\
let expando = GetExpandoObject(proxy);
if expando.is_not_null() {
let mut hasProp = 0;
if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 {
@@ -3889,7 +3900,8 @@ def getBody(self):
else:
getNamed = ""

return """//MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
return """\
//MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
//"Should not have a XrayWrapper here");
%s
@@ -3928,8 +3940,7 @@ def getBody(self):
else:
error = None
call = CGCallGenerator(error, [], "", returnType, extendedAttributes, self.descriptor, nativeName, False, object="UnwrapProxy(proxy)")
return call.define() + """
return call.define() + """\
JSString* jsresult;
return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;"""

@@ -3963,7 +3974,8 @@ def generate_code(self):
assert(False)

def finalizeHook(descriptor, hookName, context):
release = """let value = unwrap::<%s>(obj);
release = """\
let value = unwrap::<%s>(obj);
let _: Box<%s> = mem::transmute(value);
debug!("%s finalize: {:p}", this);\
""" % (descriptor.concreteType, descriptor.concreteType, descriptor.concreteType)
@@ -4777,7 +4789,8 @@ def getConstructors(self):

class CGCallbackFunctionImpl(CGGeneric):
def __init__(self, callback):
impl = string.Template("""impl CallbackContainer for ${type} {
impl = string.Template("""\
impl CallbackContainer for ${type} {
fn new(callback: *mut JSObject) -> ${type} {
${type}::new(callback)
}
@@ -5235,20 +5248,22 @@ def InheritTypes(config):
(name + 'Derived', 'is_' + name.lower()))]
for protoName in descriptor.prototypeChain[1:-1]:
protoDescriptor = config.getDescriptor(protoName)
delegate = string.Template('''impl ${selfName} for ${baseName} {
delegate = string.Template("""\
impl ${selfName} for ${baseName} {
#[inline]
fn ${fname}(&self) -> bool {
${parentName}Cast::from_actual(self).${fname}()
}
}\
''').substitute({'fname': 'is_' + name.lower(),
""").substitute({'fname': 'is_' + name.lower(),
'selfName': name + 'Derived',
'baseName': protoDescriptor.concreteType,
'parentName': protoDescriptor.prototypeChain[-2]})
derived += [CGGeneric(delegate)]
derived += [CGGeneric('\n')]

cast = [CGGeneric(string.Template('''pub trait ${castTraitName} {
cast = [CGGeneric(string.Template("""\
pub trait ${castTraitName} {
#[inline(always)]
fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, Self>> {
match base.${checkFn}() {
@@ -5296,7 +5311,7 @@ def InheritTypes(config):
unsafe { mem::transmute(derived) }
}
}
''').substitute({'checkFn': 'is_' + name.lower(),
""").substitute({'checkFn': 'is_' + name.lower(),
'castTraitName': name + 'Cast',
'fromBound': name + 'Base',
'toBound': name + 'Derived'})),

5 comments on commit bb57796

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Dec 30, 2014

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Dec 30, 2014

merging brunoabinader/servo/codegen-cleanup = bb57796 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Dec 30, 2014

brunoabinader/servo/codegen-cleanup = bb57796 merged ok, testing candidate = 37a97f3

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Dec 30, 2014

fast-forwarding master to auto = 37a97f3

Please sign in to comment.
You can’t perform that action at this time.