mirror of
https://github.com/servo/servo.git
synced 2025-06-10 09:33:13 +00:00
Move WebIDL unions into their own module.
This will allow multiple unions to contain the same type.
This commit is contained in:
parent
a90f1e3773
commit
d8801da9c5
4 changed files with 29 additions and 19 deletions
|
@ -555,7 +555,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
|||
raise TypeError("Can't handle unions as members, we have a "
|
||||
"holderType")
|
||||
|
||||
declType = CGGeneric(type.name)
|
||||
declType = CGGeneric(type.name + "::" + type.name)
|
||||
if type.nullable():
|
||||
declType = CGWrapper(declType, pre="Option<", post=" >")
|
||||
|
||||
|
@ -1657,6 +1657,20 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
|||
Returns a CGList containing CGUnionStructs for every union.
|
||||
"""
|
||||
|
||||
imports = [
|
||||
'dom::bindings::utils::unwrap_jsmanaged',
|
||||
'dom::bindings::codegen::PrototypeList',
|
||||
'dom::bindings::conversions::FromJSValConvertible',
|
||||
'dom::bindings::conversions::ToJSValConvertible',
|
||||
'dom::bindings::conversions::Default',
|
||||
'dom::bindings::error::throw_not_in_union',
|
||||
'dom::bindings::js::JS',
|
||||
'dom::types::*',
|
||||
'js::jsapi::JSContext',
|
||||
'js::jsval::JSVal',
|
||||
'servo_util::str::DOMString',
|
||||
]
|
||||
|
||||
# Now find all the things we'll need as arguments and return values because
|
||||
# we need to wrap or unwrap them.
|
||||
unionStructs = dict()
|
||||
|
@ -1668,7 +1682,12 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
|
|||
name = str(t)
|
||||
if not name in unionStructs:
|
||||
provider = descriptor or config.getDescriptorProvider()
|
||||
unionStructs[name] = CGList([CGUnionStruct(t, provider), CGUnionConversionStruct(t, provider)])
|
||||
unionStructs[name] = CGNamespace(name,
|
||||
CGImports(CGList([
|
||||
CGUnionStruct(t, provider),
|
||||
CGUnionConversionStruct(t, provider)
|
||||
]), [], imports),
|
||||
public=True)
|
||||
|
||||
return CGList(SortedDictValues(unionStructs), "\n\n")
|
||||
|
||||
|
@ -4531,7 +4550,7 @@ class CGNativeMember(ClassMethod):
|
|||
if type.isUnion():
|
||||
if type.nullable():
|
||||
type = type.inner
|
||||
return str(type), False, True
|
||||
return str(type) + "::" + str(type), False, True
|
||||
|
||||
if type.isGeckoInterface() and not type.isCallbackInterface():
|
||||
iface = type.unroll().inner
|
||||
|
@ -5315,20 +5334,6 @@ class GlobalGenRoots():
|
|||
config.getCallbacks(),
|
||||
config)
|
||||
|
||||
curr = CGImports(curr, [], [
|
||||
'dom::bindings::utils::unwrap_jsmanaged',
|
||||
'dom::bindings::codegen::PrototypeList',
|
||||
'dom::bindings::conversions::FromJSValConvertible',
|
||||
'dom::bindings::conversions::ToJSValConvertible',
|
||||
'dom::bindings::conversions::Default',
|
||||
'dom::bindings::error::throw_not_in_union',
|
||||
'dom::bindings::js::JS',
|
||||
'dom::types::*',
|
||||
'js::jsapi::JSContext',
|
||||
'js::jsval::JSVal',
|
||||
'servo_util::str::DOMString',
|
||||
])
|
||||
|
||||
# Add the auto-generated comment.
|
||||
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue