Commit f466c35a authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Implement Interface.exposed_constructs

Implements Interface.exposed_constructs that returns a list of
the constructs that are exposed on the global object.

Bug: 839389
Change-Id: I1e6dbc119e3371818ed418829e530214b76d2497
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983116Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727855}
parent af0cbb6f
...@@ -94,6 +94,8 @@ class IdlCompiler(object): ...@@ -94,6 +94,8 @@ class IdlCompiler(object):
self._propagate_extattrs_to_overload_group() self._propagate_extattrs_to_overload_group()
self._calculate_group_exposure() self._calculate_group_exposure()
self._fill_exposed_constructs()
self._sort_dictionary_members() self._sort_dictionary_members()
# Updates on IRs are finished. Create API objects. # Updates on IRs are finished. Create API objects.
...@@ -420,6 +422,32 @@ class IdlCompiler(object): ...@@ -420,6 +422,32 @@ class IdlCompiler(object):
])) ]))
group.exposure.set_only_in_secure_contexts(flag_names) group.exposure.set_only_in_secure_contexts(flag_names)
def _fill_exposed_constructs(self):
old_interfaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.INTERFACE)
old_namespaces = self._ir_map.irs_of_kind(IRMap.IR.Kind.NAMESPACE)
exposed_map = {} # global name: [construct's identifier...]
for ir in itertools.chain(old_interfaces, old_namespaces):
for pair in ir.exposure.global_names_and_features:
exposed_map.setdefault(pair.global_name,
[]).append(ir.identifier)
self._ir_map.move_to_new_phase()
for old_ir in old_interfaces:
new_ir = make_copy(old_ir)
self._ir_map.add(new_ir)
assert not new_ir.exposed_constructs
global_names = new_ir.extended_attributes.values_of("Global")
if not global_names:
continue
constructs = set()
for global_name in global_names:
constructs.update(exposed_map.get(global_name, []))
new_ir.exposed_constructs = map(
self._ref_to_idl_def_factory.create, sorted(constructs))
def _sort_dictionary_members(self): def _sort_dictionary_members(self):
"""Sorts dictionary members in alphabetical order.""" """Sorts dictionary members in alphabetical order."""
old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY) old_irs = self._ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY)
......
...@@ -102,6 +102,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -102,6 +102,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
self.constructor_groups = [] self.constructor_groups = []
self.operations = list(operations) self.operations = list(operations)
self.operation_groups = [] self.operation_groups = []
self.exposed_constructs = []
self.stringifier = stringifier self.stringifier = stringifier
self.iterable = iterable self.iterable = iterable
self.maplike = maplike self.maplike = maplike
...@@ -162,6 +163,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -162,6 +163,7 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
self._operations), self._operations),
owner=self) for operation_group_ir in ir.operation_groups owner=self) for operation_group_ir in ir.operation_groups
]) ])
self._exposed_constructs = tuple(ir.exposed_constructs)
self._stringifier = None self._stringifier = None
if ir.stringifier: if ir.stringifier:
operations = filter(lambda x: x.is_stringifier, self._operations) operations = filter(lambda x: x.is_stringifier, self._operations)
...@@ -265,19 +267,18 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo, ...@@ -265,19 +267,18 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
return self._operation_groups return self._operation_groups
@property @property
def named_constructor(self): def exposed_constructs(self):
"""Returns a named constructor or None."""
assert False, "Not implemented yet."
@property
def exposed_interfaces(self):
""" """
Returns a tuple of interfaces that are exposed to this interface, if Returns a list of the constructs that are exposed on this global object.
this is a global interface. Returns None otherwise.
""" """
return tuple(
map(lambda ref: ref.target_object, self._exposed_constructs))
@property
def named_constructor(self):
"""Returns a named constructor or None."""
assert False, "Not implemented yet." assert False, "Not implemented yet."
# Special operations
@property @property
def indexed_property_handler(self): def indexed_property_handler(self):
""" """
......
...@@ -194,7 +194,7 @@ class IRMap(object): ...@@ -194,7 +194,7 @@ class IRMap(object):
accumulated.extend(irs) accumulated.extend(irs)
return accumulated return accumulated
else: else:
return self.find_by_kind(kind).itervalues() return list(self.find_by_kind(kind).itervalues())
def irs_of_kinds(self, *kinds): def irs_of_kinds(self, *kinds):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment