| 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 from generator import AnalyzeOperation, ConstantOutputOrder, \ | 10 from generator import AnalyzeOperation, ConstantOutputOrder, \ |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 # We don't yet handle inconsistent renames of the getter and setter yet. | 304 # We don't yet handle inconsistent renames of the getter and setter yet. |
| 305 assert(not html_setter_name or attr_name == html_setter_name) | 305 assert(not html_setter_name or attr_name == html_setter_name) |
| 306 | 306 |
| 307 if declare_only: | 307 if declare_only: |
| 308 self.DeclareAttribute(attribute, | 308 self.DeclareAttribute(attribute, |
| 309 self.SecureOutputType(attribute.type.id), attr_name, read_only) | 309 self.SecureOutputType(attribute.type.id), attr_name, read_only) |
| 310 else: | 310 else: |
| 311 self.EmitAttribute(attribute, attr_name, read_only) | 311 self.EmitAttribute(attribute, attr_name, read_only) |
| 312 | 312 |
| 313 def AddOperation(self, info, declare_only=False, dart_js_interop=False): | 313 def AddOperation(self, info, declare_only=False, dart_js_interop=False): |
| 314 # TODO(terry): Hack window has 2 overloaded getter one returns Window and |
| 315 # and other object (we'll always return Window)? |
| 316 if self._interface.id == "Window" and info.name == '__getter__': |
| 317 info.operations[1].type = info.operations[0].type; |
| 318 |
| 314 """ Adds an operation to the generated class. | 319 """ Adds an operation to the generated class. |
| 315 Arguments: | 320 Arguments: |
| 316 info - The operation info of the operation to be added. | 321 info - The operation info of the operation to be added. |
| 317 declare_only- True if the operation should be declared as an abstract | 322 declare_only- True if the operation should be declared as an abstract |
| 318 member and not include invocation code. | 323 member and not include invocation code. |
| 319 """ | 324 """ |
| 320 # FIXME: When we pass in operations[0] below, we're assuming all | 325 # FIXME: When we pass in operations[0] below, we're assuming all |
| 321 # overloaded operations have the same security attributes. This | 326 # overloaded operations have the same security attributes. This |
| 322 # is currently true, but we should consider filtering earlier or | 327 # is currently true, but we should consider filtering earlier or |
| 323 # merging the relevant data into info itself. | 328 # merging the relevant data into info itself. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 factory_name to call (calls an autogenerated FactoryProvider | 526 factory_name to call (calls an autogenerated FactoryProvider |
| 522 if unspecified) | 527 if unspecified) |
| 523 """ | 528 """ |
| 524 for constructor_info in constructors: | 529 for constructor_info in constructors: |
| 525 self._AddConstructor( | 530 self._AddConstructor( |
| 526 constructor_info, factory_name, factory_constructor_name) | 531 constructor_info, factory_name, factory_constructor_name) |
| 527 | 532 |
| 528 def _AddConstructor(self, | 533 def _AddConstructor(self, |
| 529 constructor_info, factory_name, factory_constructor_name): | 534 constructor_info, factory_name, factory_constructor_name): |
| 530 # Hack to ignore the Image constructor used by JavaScript. | 535 # Hack to ignore the Image constructor used by JavaScript. |
| 531 if ((self._interface.id == 'HTMLImageElement' or self._interface.id == 'Blob
') | 536 if ((self._interface.id == 'HTMLImageElement' or |
| 537 self._interface.id == 'Blob' or |
| 538 self._interface.id == 'DOMException') |
| 532 and not constructor_info.pure_dart_constructor): | 539 and not constructor_info.pure_dart_constructor): |
| 533 return | 540 return |
| 534 | 541 |
| 535 if self.GenerateCustomFactory(constructor_info): | 542 if self.GenerateCustomFactory(constructor_info): |
| 536 return | 543 return |
| 537 | 544 |
| 538 metadata = self._metadata.GetFormattedMetadata( | 545 metadata = self._metadata.GetFormattedMetadata( |
| 539 self._library_name, self._interface, self._interface.id, ' ') | 546 self._library_name, self._interface, self._interface.id, ' ') |
| 540 | 547 |
| 541 if not factory_constructor_name: | 548 if not factory_constructor_name: |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 '$(INDENT)$TYPE $NAME = $CONVERT($ARG);\n', | 850 '$(INDENT)$TYPE $NAME = $CONVERT($ARG);\n', |
| 844 TYPE=TypeOrVar(temp_type), | 851 TYPE=TypeOrVar(temp_type), |
| 845 NAME=temp_name, | 852 NAME=temp_name, |
| 846 CONVERT=conversion.function_name, | 853 CONVERT=conversion.function_name, |
| 847 ARG=info.param_infos[position].name) | 854 ARG=info.param_infos[position].name) |
| 848 converted_arguments.append(temp_name) | 855 converted_arguments.append(temp_name) |
| 849 param_type = temp_type | 856 param_type = temp_type |
| 850 verified_type = temp_type # verified by assignment in checked mode. | 857 verified_type = temp_type # verified by assignment in checked mode. |
| 851 else: | 858 else: |
| 852 converted_arguments.append(info.param_infos[position].name) | 859 converted_arguments.append(info.param_infos[position].name) |
| 853 param_type = self._NarrowInputType(arg.type.id) | 860 if self._database.HasTypeDef(arg.type.id): |
| 854 # Verified by argument checking on entry to the dispatcher. | 861 param_type = 'dynamic' |
| 855 | 862 else: |
| 856 verified_type = self._InputType( | 863 param_type = self._NarrowInputType(arg.type.id) |
| 857 info.param_infos[position].type_id, info) | 864 # Verified by argument checking on entry to the dispatcher. |
| 858 # The native method does not need an argument type if we know the type. | 865 |
| 859 # But we do need the native methods to have correct function types, so | 866 verified_type = self._InputType( |
| 860 # be conservative. | 867 info.param_infos[position].type_id, info) |
| 861 if param_type == verified_type: | 868 # The native method does not need an argument type if we know the type
. |
| 862 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object']: | 869 # But we do need the native methods to have correct function types, so |
| 863 param_type = 'dynamic' | 870 # be conservative. |
| 871 if param_type == verified_type: |
| 872 if param_type in ['String', 'num', 'int', 'double', 'bool', 'Object'
]: |
| 873 param_type = 'dynamic' |
| 864 | 874 |
| 865 target_parameters.append( | 875 target_parameters.append( |
| 866 '%s%s' % (TypeOrNothing(param_type), param_name)) | 876 '%s%s' % (TypeOrNothing(param_type), param_name)) |
| 867 | 877 |
| 868 return target_parameters, converted_arguments | 878 return target_parameters, converted_arguments |
| 869 | 879 |
| 870 def _InputType(self, type_name, info): | 880 def _InputType(self, type_name, info): |
| 871 conversion = self._InputConversion(type_name, info.declared_name) | 881 conversion = self._InputConversion(type_name, info.declared_name) |
| 872 if conversion: | 882 if conversion: |
| 873 return conversion.input_type | 883 return conversion.input_type |
| 874 else: | 884 else: |
| 875 return self._NarrowInputType(type_name) if type_name else 'dynamic' | 885 # If typedef it's a union return dynamic. |
| 886 if self._database.HasTypeDef(type_name): |
| 887 return 'dynamic' |
| 888 else: |
| 889 return self._NarrowInputType(type_name) if type_name else 'dynamic' |
| OLD | NEW |