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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 self._interface = interface | 495 self._interface = interface |
496 self._backend = backend | 496 self._backend = backend |
497 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 497 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
498 self._library_name = self._renamer.GetLibraryName(self._interface) | 498 self._library_name = self._renamer.GetLibraryName(self._interface) |
499 self._metadata = options.metadata | 499 self._metadata = options.metadata |
500 | 500 |
501 def Generate(self): | 501 def Generate(self): |
502 if IsCustomType(self._interface.id): | 502 if IsCustomType(self._interface.id): |
503 pass | 503 pass |
504 elif 'Callback' in self._interface.ext_attrs: | 504 elif 'Callback' in self._interface.ext_attrs: |
505 self.GenerateCallback() | 505 if len(GetCallbackHandlers(self._interface)) > 0: |
| 506 self.GenerateCallback() |
| 507 else: |
| 508 return |
506 else: | 509 else: |
507 self.GenerateInterface() | 510 self.GenerateInterface() |
508 | 511 |
509 def GenerateCallback(self): | 512 def GenerateCallback(self): |
510 """Generates a typedef for the callback interface.""" | 513 """Generates a typedef for the callback interface.""" |
511 typedef_name = self._renamer.RenameInterface(self._interface) | 514 typedef_name = self._renamer.RenameInterface(self._interface) |
512 if not typedef_name: | 515 if not typedef_name: |
513 return | 516 return |
514 | 517 |
515 info = GetCallbackInfo(self._interface) | 518 info = GetCallbackInfo(self._interface) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 | 898 |
896 has_indexed_getter = self.HasIndexedGetter() | 899 has_indexed_getter = self.HasIndexedGetter() |
897 | 900 |
898 if has_indexed_getter: | 901 if has_indexed_getter: |
899 indexed_getter = ('JS("%s%s", "#[#]", this, index)' % | 902 indexed_getter = ('JS("%s%s", "#[#]", this, index)' % |
900 (self.SecureOutputType(element_type), "|Null" if nullable else "")); | 903 (self.SecureOutputType(element_type), "|Null" if nullable else "")); |
901 elif any(op.id == 'getItem' for op in self._interface.operations): | 904 elif any(op.id == 'getItem' for op in self._interface.operations): |
902 indexed_getter = 'this.getItem(index)' | 905 indexed_getter = 'this.getItem(index)' |
903 elif any(op.id == 'item' for op in self._interface.operations): | 906 elif any(op.id == 'item' for op in self._interface.operations): |
904 indexed_getter = 'this.item(index)' | 907 indexed_getter = 'this.item(index)' |
| 908 else: |
| 909 indexed_getter = False |
905 | 910 |
906 if indexed_getter: | 911 if indexed_getter: |
907 self._members_emitter.Emit( | 912 self._members_emitter.Emit( |
908 '\n' | 913 '\n' |
909 ' $TYPE operator[](int index) {\n' | 914 ' $TYPE operator[](int index) {\n' |
910 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' | 915 ' if (JS("bool", "# >>> 0 !== # || # >= #", index,\n' |
911 ' index, index, length))\n' | 916 ' index, index, length))\n' |
912 ' throw new RangeError.index(index, this);\n' | 917 ' throw new RangeError.index(index, this);\n' |
913 ' return $INDEXED_GETTER;\n' | 918 ' return $INDEXED_GETTER;\n' |
914 ' }', | 919 ' }', |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 | 1384 |
1380 def AddFile(self, basename, library_name, path): | 1385 def AddFile(self, basename, library_name, path): |
1381 self._libraries[library_name].AddFile(path) | 1386 self._libraries[library_name].AddFile(path) |
1382 | 1387 |
1383 def AddTypeEntry(self, library_name, idl_name, dart_name): | 1388 def AddTypeEntry(self, library_name, idl_name, dart_name): |
1384 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) | 1389 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) |
1385 | 1390 |
1386 def Emit(self, emitter, auxiliary_dir): | 1391 def Emit(self, emitter, auxiliary_dir): |
1387 for lib in self._libraries.values(): | 1392 for lib in self._libraries.values(): |
1388 lib.Emit(emitter, auxiliary_dir) | 1393 lib.Emit(emitter, auxiliary_dir) |
OLD | NEW |