Skip to content

Commit

Permalink
Generate DOM bindings imports for webidl typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Aug 2, 2017
1 parent 5fff90c commit 354d940
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -1848,7 +1848,8 @@ class CGImports(CGWrapper):
"""
Generates the appropriate import/use statements.
"""
def __init__(self, child, descriptors, callbacks, dictionaries, enums, imports, config, ignored_warnings=None):
def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config,
ignored_warnings=None):
"""
Adds a set of imports.
"""
Expand Down Expand Up @@ -1937,6 +1938,11 @@ def removeWrapperAndNullableTypes(types):
for d in dictionaries:
types += componentTypes(d)

# Import the type names used in the typedefs that are being defined.
for t in typedefs:
if not t.innerType.isCallback():
types += componentTypes(t.innerType)

# Normalize the types we've collected and remove any ones which can't be imported.
types = removeWrapperAndNullableTypes(types)

Expand Down Expand Up @@ -2292,6 +2298,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
callbacks=[],
dictionaries=[],
enums=[],
typedefs=[],
imports=imports,
config=config,
ignored_warnings=[])
Expand Down Expand Up @@ -5507,15 +5514,17 @@ def define(self):
return self.code


def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries=None, enums=None):
def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries=None, enums=None, typedefs=None):
if not callbacks:
callbacks = []
if not dictionaries:
dictionaries = []
if not enums:
enums = []
if not typedefs:
typedefs = []

return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, [
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
'core::nonzero::NonZero',
'js',
'js::JSCLASS_GLOBAL_SLOT_COUNT',
Expand Down Expand Up @@ -6220,7 +6229,7 @@ def __init__(self, config, prefix, webIDLFile):
# Do codegen for all the enums.
cgthings = [CGEnum(e) for e in enums]

# Do codegen for all the typdefs
# Do codegen for all the typedefs
for t in typedefs:
typeName = getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider())
substs = {
Expand Down Expand Up @@ -6258,7 +6267,7 @@ def __init__(self, config, prefix, webIDLFile):

# Add imports
curr = generate_imports(config, curr, callbackDescriptors, mainCallbacks,
dictionaries, enums)
dictionaries, enums, typedefs)

# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
Expand Down Expand Up @@ -7060,7 +7069,7 @@ def RegisterBindings(config):
CGRegisterProxyHandlers(config),
], "\n")

return CGImports(code, descriptors=[], callbacks=[], dictionaries=[], enums=[], imports=[
return CGImports(code, descriptors=[], callbacks=[], dictionaries=[], enums=[], typedefs=[], imports=[
'dom::bindings::codegen::Bindings',
'dom::bindings::codegen::PrototypeList::Proxies',
'libc',
Expand Down

0 comments on commit 354d940

Please sign in to comment.