Skip to content

Commit

Permalink
Auto merge of #7230 - nox:required-dictionary-member, r=Ms2ger
Browse files Browse the repository at this point in the history
Support required dictionary members (fixes #7216)



<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7230)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 18, 2015
2 parents 50e1c96 + 44aabbe commit ef98e57
Show file tree
Hide file tree
Showing 4 changed files with 1,172 additions and 441 deletions.
21 changes: 13 additions & 8 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -918,7 +918,8 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
assert not type.treatNonObjectAsNull() or type.nullable()
assert not type.treatNonObjectAsNull() or not type.treatNonCallableAsNull()

declType = CGGeneric('%s::%s' % (type.unroll().module(), type.unroll().identifier.name))
callback = type.unroll().callback
declType = CGGeneric('%s::%s' % (callback.module(), callback.identifier.name))
finalDeclType = CGTemplatedType("Rc", declType)

conversion = CGCallbackTempRoot(declType.define())
Expand Down Expand Up @@ -1285,8 +1286,8 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
result = CGWrapper(result, pre="Option<", post=">")
return result
if returnType.isCallback():
result = CGGeneric('Rc<%s::%s>' % (returnType.unroll().module(),
returnType.unroll().identifier.name))
callback = returnType.unroll().callback
result = CGGeneric('Rc<%s::%s>' % (callback.module(), callback.identifier.name))
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
Expand Down Expand Up @@ -4798,7 +4799,7 @@ def makeModuleName(dictionary):
def getMemberType(self, memberInfo):
member, info = memberInfo
declType = info.declType
if not member.defaultValue:
if member.optional and not member.defaultValue:
declType = CGWrapper(info.declType, pre="Option<", post=">")
return declType.define()

Expand All @@ -4815,7 +4816,11 @@ def indent(s):
conversion = "%s.get()" % conversion

assert (member.defaultValue is None) == (default is None)
if not default:
if not member.optional:
assert default is None
default = ("throw_type_error(cx, \"Missing required member \\\"%s\\\".\");\n"
"return Err(());") % member.identifier.name
elif not default:
default = "None"
conversion = "Some(%s)" % conversion

Expand Down Expand Up @@ -4935,7 +4940,7 @@ def __init__(self, config, prefix, webIDLFile):

# Do codegen for all the callback interfaces.
cgthings.extend(CGList([CGCallbackInterface(x),
CGCallbackFunctionImpl(x)], "\n")
CGCallbackFunctionImpl(x.interface)], "\n")
for x in callbackDescriptors)

# And make sure we have the right number of newlines at the end
Expand Down Expand Up @@ -5258,7 +5263,7 @@ def __init__(self, callback):
self.callback().to_jsval(cx, rval);
}
}\
""").substitute({"type": callback.name})
""").substitute({"type": callback.identifier.name})
CGGeneric.__init__(self, impl)


Expand Down Expand Up @@ -5687,7 +5692,7 @@ def InterfaceTypes(config):
def Bindings(config):

descriptors = (set(d.name + "Binding" for d in config.getDescriptors(register=True)) |
set(d.unroll().module() for d in config.callbacks) |
set(d.module() for d in config.callbacks) |
set(d.module() for d in config.getDictionaries()))
curr = CGList([CGGeneric("pub mod %s;\n" % name) for name in sorted(descriptors)])
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
Expand Down

0 comments on commit ef98e57

Please sign in to comment.