Skip to content

Commit

Permalink
Support WebIDL record<>
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Oct 15, 2019
1 parent 9785613 commit b697621
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 251 deletions.
37 changes: 30 additions & 7 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -77,14 +77,13 @@ def innerContainerType(type):

def wrapInNativeContainerType(type, inner):
if type.isSequence():
containerType = "Vec"
return CGWrapper(inner, pre="Vec<", post=">")
elif type.isRecord():
containerType = "MozMap"
key = type.inner.keyType if type.nullable() else type.keyType
return CGRecord(key, inner)
else:
raise TypeError("Unexpected container type %s", type)

return CGWrapper(inner, pre=containerType + "<", post=">")


builtinNames = {
IDLType.Tags.bool: 'bool',
Expand Down Expand Up @@ -1905,6 +1904,30 @@ def define(self):
return self.pre + defn + self.post


class CGRecord(CGThing):
"""
CGThing that wraps value CGThing in record with key type equal to keyType parameter
"""
def __init__(self, keyType, value):
CGThing.__init__(self)
assert keyType.isString()
self.keyType = keyType
self.value = value

def define(self):
if self.keyType.isByteString():
keyDef = "ByteString"
elif self.keyType.isDOMString():
keyDef = "DOMString"
elif self.keyType.isUSVString():
keyDef = "USVString"
else:
assert False

defn = keyDef + ", " + self.value.define()
return "Record<" + defn + ">"


class CGImports(CGWrapper):
"""
Generates the appropriate import/use statements.
Expand Down Expand Up @@ -2024,7 +2047,7 @@ def removeWrapperAndNullableTypes(types):
extras += [descriptor.path, descriptor.bindingPath]
parentName = descriptor.getParentName()
elif t.isType() and t.isRecord():
extras += ['crate::dom::bindings::mozmap::MozMap']
extras += ['crate::dom::bindings::record::Record']
elif isinstance(t, IDLPromiseType):
extras += ['crate::dom::promise::Promise']
else:
Expand Down Expand Up @@ -2373,7 +2396,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'crate::dom::bindings::conversions::StringificationBehavior',
'crate::dom::bindings::conversions::root_from_handlevalue',
'std::ptr::NonNull',
'crate::dom::bindings::mozmap::MozMap',
'crate::dom::bindings::record::Record',
'crate::dom::bindings::num::Finite',
'crate::dom::bindings::root::DomRoot',
'crate::dom::bindings::str::ByteString',
Expand Down Expand Up @@ -6054,7 +6077,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'crate::dom::bindings::proxyhandler::ensure_expando_object',
'crate::dom::bindings::proxyhandler::fill_property_descriptor',
'crate::dom::bindings::proxyhandler::get_expando_object',
'crate::dom::bindings::mozmap::MozMap',
'crate::dom::bindings::record::Record',
'std::ptr::NonNull',
'crate::dom::bindings::num::Finite',
'crate::dom::bindings::str::ByteString',
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/bindings/mod.rs
Expand Up @@ -143,10 +143,10 @@ pub mod htmlconstructor;
pub mod inheritance;
pub mod interface;
pub mod iterable;
pub mod mozmap;
pub mod namespace;
pub mod num;
pub mod proxyhandler;
pub mod record;
pub mod refcounted;
pub mod reflector;
pub mod root;
Expand Down
135 changes: 0 additions & 135 deletions components/script/dom/bindings/mozmap.rs

This file was deleted.

0 comments on commit b697621

Please sign in to comment.