| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import logging | 10 import logging |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 def HasIndexedGetter(self): | 831 def HasIndexedGetter(self): |
| 832 ext_attrs = self._interface.ext_attrs | 832 ext_attrs = self._interface.ext_attrs |
| 833 has_indexed_getter = 'CustomIndexedGetter' in ext_attrs | 833 has_indexed_getter = 'CustomIndexedGetter' in ext_attrs |
| 834 for operation in self._interface.operations: | 834 for operation in self._interface.operations: |
| 835 if operation.id == 'item' and 'getter' in operation.specials \ | 835 if operation.id == 'item' and 'getter' in operation.specials \ |
| 836 and not self._OperationRequiresConversions(operation): | 836 and not self._OperationRequiresConversions(operation): |
| 837 has_indexed_getter = True | 837 has_indexed_getter = True |
| 838 break | 838 break |
| 839 return has_indexed_getter | 839 return has_indexed_getter |
| 840 | 840 |
| 841 def AddIndexer(self, element_type): | 841 def AddIndexer(self, element_type, nullable): |
| 842 """Adds all the methods required to complete implementation of List.""" | 842 """Adds all the methods required to complete implementation of List.""" |
| 843 # We would like to simply inherit the implementation of everything except | 843 # We would like to simply inherit the implementation of everything except |
| 844 # length, [], and maybe []=. It is possible to extend from a base | 844 # length, [], and maybe []=. It is possible to extend from a base |
| 845 # array implementation class only when there is no other implementation | 845 # array implementation class only when there is no other implementation |
| 846 # inheritance. There might be no implementation inheritance other than | 846 # inheritance. There might be no implementation inheritance other than |
| 847 # DOMBaseWrapper for many classes, but there might be some where the | 847 # DOMBaseWrapper for many classes, but there might be some where the |
| 848 # array-ness is introduced by a non-root interface: | 848 # array-ness is introduced by a non-root interface: |
| 849 # | 849 # |
| 850 # interface Y extends X, List<T> ... | 850 # interface Y extends X, List<T> ... |
| 851 # | 851 # |
| 852 # In the non-root case we have to choose between: | 852 # In the non-root case we have to choose between: |
| 853 # | 853 # |
| 854 # class YImpl extends XImpl { add List<T> methods; } | 854 # class YImpl extends XImpl { add List<T> methods; } |
| 855 # | 855 # |
| 856 # and | 856 # and |
| 857 # | 857 # |
| 858 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 858 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
| 859 # | 859 # |
| 860 | 860 |
| 861 has_indexed_getter = self.HasIndexedGetter() | 861 has_indexed_getter = self.HasIndexedGetter() |
| 862 | 862 |
| 863 if has_indexed_getter: | 863 if has_indexed_getter: |
| 864 indexed_getter = ('JS("%s", "#[#]", this, index)' % | 864 indexed_getter = ('JS("%s%s", "#[#]", this, index)' % |
| 865 self.SecureOutputType(element_type)); | 865 (self.SecureOutputType(element_type), "|Null" if nullable else "")); |
| 866 elif any(op.id == 'getItem' for op in self._interface.operations): | 866 elif any(op.id == 'getItem' for op in self._interface.operations): |
| 867 indexed_getter = 'this.getItem(index)' | 867 indexed_getter = 'this.getItem(index)' |
| 868 elif any(op.id == 'item' for op in self._interface.operations): | 868 elif any(op.id == 'item' for op in self._interface.operations): |
| 869 indexed_getter = 'this.item(index)' | 869 indexed_getter = 'this.item(index)' |
| 870 | 870 |
| 871 if indexed_getter: | 871 if indexed_getter: |
| 872 self._members_emitter.Emit( | 872 self._members_emitter.Emit( |
| 873 '\n' | 873 '\n' |
| 874 ' $TYPE operator[](int index) {\n' | 874 ' $TYPE operator[](int index) {\n' |
| 875 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' | 875 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 887 ' JS("void", "#[#] = #", this, index, value); }', | 887 ' JS("void", "#[#] = #", this, index, value); }', |
| 888 TYPE=self._NarrowInputType(element_type)) | 888 TYPE=self._NarrowInputType(element_type)) |
| 889 else: | 889 else: |
| 890 self._members_emitter.Emit( | 890 self._members_emitter.Emit( |
| 891 '\n' | 891 '\n' |
| 892 ' void operator[]=(int index, $TYPE value) {\n' | 892 ' void operator[]=(int index, $TYPE value) {\n' |
| 893 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' | 893 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' |
| 894 ' }\n', | 894 ' }\n', |
| 895 TYPE=self._NarrowInputType(element_type)) | 895 TYPE=self._NarrowInputType(element_type)) |
| 896 | 896 |
| 897 self.EmitListMixin(self._DartType(element_type)) | 897 self.EmitListMixin(self._DartType(element_type), nullable) |
| 898 | 898 |
| 899 def EmitAttribute(self, attribute, html_name, read_only): | 899 def EmitAttribute(self, attribute, html_name, read_only): |
| 900 if self._HasCustomImplementation(attribute.id): | 900 if self._HasCustomImplementation(attribute.id): |
| 901 return | 901 return |
| 902 | 902 |
| 903 if IsPureInterface(self._interface.id, self._database): | 903 if IsPureInterface(self._interface.id, self._database): |
| 904 self._AddInterfaceAttribute(attribute, html_name, read_only) | 904 self._AddInterfaceAttribute(attribute, html_name, read_only) |
| 905 return | 905 return |
| 906 | 906 |
| 907 # If the attribute is shadowing, we can't generate a shadowing | 907 # If the attribute is shadowing, we can't generate a shadowing |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 | 1344 |
| 1345 def AddFile(self, basename, library_name, path): | 1345 def AddFile(self, basename, library_name, path): |
| 1346 self._libraries[library_name].AddFile(path) | 1346 self._libraries[library_name].AddFile(path) |
| 1347 | 1347 |
| 1348 def AddTypeEntry(self, library_name, idl_name, dart_name): | 1348 def AddTypeEntry(self, library_name, idl_name, dart_name): |
| 1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) | 1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) |
| 1350 | 1350 |
| 1351 def Emit(self, emitter, auxiliary_dir): | 1351 def Emit(self, emitter, auxiliary_dir): |
| 1352 for lib in self._libraries.values(): | 1352 for lib in self._libraries.values(): |
| 1353 lib.Emit(emitter, auxiliary_dir) | 1353 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |