mirror of
https://github.com/servo/servo.git
synced 2025-06-10 09:33:13 +00:00
Auto merge of #7230 - nox:required-dictionary-member, r=Ms2ger
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 -->
This commit is contained in:
commit
ef98e57429
4 changed files with 1181 additions and 450 deletions
|
@ -918,7 +918,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
|||
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())
|
||||
|
@ -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
|
||||
|
@ -4798,7 +4799,7 @@ class CGDictionary(CGThing):
|
|||
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()
|
||||
|
||||
|
@ -4815,7 +4816,11 @@ class CGDictionary(CGThing):
|
|||
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
|
||||
|
||||
|
@ -4935,7 +4940,7 @@ class CGBindingRoot(CGThing):
|
|||
|
||||
# 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
|
||||
|
@ -5258,7 +5263,7 @@ impl ToJSValConvertible for ${type} {
|
|||
self.callback().to_jsval(cx, rval);
|
||||
}
|
||||
}\
|
||||
""").substitute({"type": callback.name})
|
||||
""").substitute({"type": callback.identifier.name})
|
||||
CGGeneric.__init__(self, impl)
|
||||
|
||||
|
||||
|
@ -5687,7 +5692,7 @@ class GlobalGenRoots():
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue