Chromium Code Reviews| 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 systems to generate | 6 """This module provides shared functionality for the systems to generate |
| 7 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 # TODO: Optimize the dispatch to avoid repeated checks. | 648 # TODO: Optimize the dispatch to avoid repeated checks. |
| 649 if len(operations) > 1: | 649 if len(operations) > 1: |
| 650 for operation in operations: | 650 for operation in operations: |
| 651 for position, argument in enumerate(operation.arguments): | 651 for position, argument in enumerate(operation.arguments): |
| 652 if self._IsArgumentOptionalInWebCore(operation, argument): | 652 if self._IsArgumentOptionalInWebCore(operation, argument): |
| 653 GenerateChecksAndCall(operation, position) | 653 GenerateChecksAndCall(operation, position) |
| 654 GenerateChecksAndCall(operation, len(operation.arguments)) | 654 GenerateChecksAndCall(operation, len(operation.arguments)) |
| 655 body.Emit(' throw "Incorrect number or type of arguments";\n'); | 655 body.Emit(' throw "Incorrect number or type of arguments";\n'); |
| 656 else: | 656 else: |
| 657 operation = operations[0] | 657 operation = operations[0] |
| 658 argument_count = len(operation.arguments) | |
| 658 for position, argument in list(enumerate(operation.arguments))[::-1]: | 659 for position, argument in list(enumerate(operation.arguments))[::-1]: |
| 659 if self._IsArgumentOptionalInWebCore(operation, argument): | 660 if self._IsArgumentOptionalInWebCore(operation, argument): |
| 660 check = '%s === _null' % argument_names[position] | 661 check = '%s !== _null' % argument_names[position] |
| 661 GenerateCall(operation, position, [check]) | 662 # argument_count instead of position + 1 is used here to cover one |
| 662 GenerateCall(operation, len(operation.arguments), []) | 663 # complicated case. Consider foo(x, [Optional] y, [Optional=DefaultIs NullString] z) |
|
podivilov
2012/08/21 13:46:57
I think it's exactly the optional in the middle pr
Anton Muhin
2012/08/21 18:14:34
Yes, this _null/null distinction is another of pro
| |
| 664 # (as of now it's modelled after HTMLMediaElement.webkitAddKey). | |
| 665 # y is optional in WebCore, while z is not. | |
| 666 # In this case, if y !== _null, we'd like to emit foo(x, y, z) invocat ion, not | |
| 667 # foo(x, y). | |
| 668 GenerateCall(operation, argument_count, [check]) | |
| 669 argument_count = position | |
| 670 GenerateCall(operation, argument_count, []) | |
| 663 | 671 |
| 664 def SecondaryContext(self, interface): | 672 def SecondaryContext(self, interface): |
| 665 pass | 673 pass |
| 666 | 674 |
| 667 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): | 675 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): |
| 668 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) | 676 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) |
| 669 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) | 677 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) |
| 670 self._GenerateNativeCallback( | 678 self._GenerateNativeCallback( |
| 671 cpp_callback_name, | 679 cpp_callback_name, |
| 672 not operation.is_static, | 680 not operation.is_static, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 parent_interface = _FindInHierarchy(database, parent_interface, test) | 944 parent_interface = _FindInHierarchy(database, parent_interface, test) |
| 937 if parent_interface: | 945 if parent_interface: |
| 938 return parent_interface | 946 return parent_interface |
| 939 | 947 |
| 940 def _ToWebKitName(name): | 948 def _ToWebKitName(name): |
| 941 name = name[0].lower() + name[1:] | 949 name = name[0].lower() + name[1:] |
| 942 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 950 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), |
| 943 name) | 951 name) |
| 944 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , | 952 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , |
| 945 name) | 953 name) |
| OLD | NEW |