| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 version[0] += 1 | 227 version[0] += 1 |
| 228 generate_call(stmts_emitter, call_emitter, | 228 generate_call(stmts_emitter, call_emitter, |
| 229 version[0], signature_index, argument_count) | 229 version[0], signature_index, argument_count) |
| 230 | 230 |
| 231 def GenerateChecksAndCall(signature_index, argument_count): | 231 def GenerateChecksAndCall(signature_index, argument_count): |
| 232 checks = [] | 232 checks = [] |
| 233 for i in range(0, argument_count): | 233 for i in range(0, argument_count): |
| 234 argument = signatures[signature_index][i] | 234 argument = signatures[signature_index][i] |
| 235 parameter_name = parameter_names[i] | 235 parameter_name = parameter_names[i] |
| 236 test_type = self._DartType(argument.type.id) | 236 test_type = self._DartType(argument.type.id) |
| 237 # TODO(antonm): temporary ugly hack to be able to work with existing | |
| 238 # typed array types as well as dart:typeddata types until | |
| 239 # the transition to dart:typeddata is complete for both dart2js | |
| 240 # and dartium. | |
| 241 from systemnative import DartiumBackend | |
| 242 if isinstance(self, DartiumBackend): | |
| 243 if argument.type.id == 'ArrayBufferView': | |
| 244 checks.append( | |
| 245 '(%(name)s is ArrayBufferView ' | |
| 246 '|| %(name)s is _typeddata.TypedData ' | |
| 247 '|| %(name)s == null)' % {'name': parameter_name}) | |
| 248 continue | |
| 249 if argument.type.id == 'ArrayBuffer': | |
| 250 checks.append( | |
| 251 '(%(name)s is ArrayBuffer ' | |
| 252 '|| %(name)s is _typeddata.ByteBuffer ' | |
| 253 '|| %(name)s == null)' % {'name': parameter_name}) | |
| 254 continue | |
| 255 # end of ugly hack. | |
| 256 if test_type in ['dynamic', 'Object']: | 237 if test_type in ['dynamic', 'Object']: |
| 257 checks.append('?%s' % parameter_name) | 238 checks.append('?%s' % parameter_name) |
| 258 elif not can_omit_type_check(test_type, i): | 239 elif not can_omit_type_check(test_type, i): |
| 259 checks.append('(%s is %s || %s == null)' % ( | 240 checks.append('(%s is %s || %s == null)' % ( |
| 260 parameter_name, test_type, parameter_name)) | 241 parameter_name, test_type, parameter_name)) |
| 261 # There can be multiple presence checks. We need them all since a later | 242 # There can be multiple presence checks. We need them all since a later |
| 262 # optional argument could have been passed by name, leaving 'holes'. | 243 # optional argument could have been passed by name, leaving 'holes'. |
| 263 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) | 244 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) |
| 264 | 245 |
| 265 GenerateCall(signature_index, argument_count, checks) | 246 GenerateCall(signature_index, argument_count, checks) |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 walk(interface.parents) | 631 walk(interface.parents) |
| 651 else: | 632 else: |
| 652 walk(interface.parents[1:]) | 633 walk(interface.parents[1:]) |
| 653 return result | 634 return result |
| 654 | 635 |
| 655 def _DartType(self, type_name): | 636 def _DartType(self, type_name): |
| 656 return self._type_registry.DartType(type_name) | 637 return self._type_registry.DartType(type_name) |
| 657 | 638 |
| 658 def _IsPrivate(self, name): | 639 def _IsPrivate(self, name): |
| 659 return name.startswith('_') | 640 return name.startswith('_') |
| OLD | NEW |