| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 version[0] += 1 | 224 version[0] += 1 |
| 225 generate_call(stmts_emitter, call_emitter, | 225 generate_call(stmts_emitter, call_emitter, |
| 226 version[0], signature_index, argument_count) | 226 version[0], signature_index, argument_count) |
| 227 | 227 |
| 228 def GenerateChecksAndCall(signature_index, argument_count): | 228 def GenerateChecksAndCall(signature_index, argument_count): |
| 229 checks = [] | 229 checks = [] |
| 230 for i in range(0, argument_count): | 230 for i in range(0, argument_count): |
| 231 argument = signatures[signature_index][i] | 231 argument = signatures[signature_index][i] |
| 232 parameter_name = parameter_names[i] | 232 parameter_name = parameter_names[i] |
| 233 test_type = self._DartType(argument.type.id) | 233 test_type = self._DartType(argument.type.id) |
| 234 # TODO(antonm): temporary ugly hack to be able to work with existing |
| 235 # typed array types as well as dart:typeddata types until |
| 236 # the transition to dart:typeddata is complete for both dart2js |
| 237 # and dartium. |
| 238 from systemnative import DartiumBackend |
| 239 if isinstance(self, DartiumBackend): |
| 240 if argument.type.id == 'ArrayBufferView': |
| 241 checks.append( |
| 242 '(%(name)s is ArrayBufferView ' |
| 243 '|| %(name)s is _typeddata.TypedData ' |
| 244 '|| %(name)s == null)' % {'name': parameter_name}) |
| 245 continue |
| 246 if argument.type.id == 'ArrayBuffer': |
| 247 checks.append( |
| 248 '(%(name)s is ArrayBuffer ' |
| 249 '|| %(name)s is _typeddata.ByteBuffer ' |
| 250 '|| %(name)s == null)' % {'name': parameter_name}) |
| 251 continue |
| 252 # end of ugly hack. |
| 234 if test_type in ['dynamic', 'Object']: | 253 if test_type in ['dynamic', 'Object']: |
| 235 checks.append('?%s' % parameter_name) | 254 checks.append('?%s' % parameter_name) |
| 236 elif not can_omit_type_check(test_type, i): | 255 elif not can_omit_type_check(test_type, i): |
| 237 checks.append('(%s is %s || %s == null)' % ( | 256 checks.append('(%s is %s || %s == null)' % ( |
| 238 parameter_name, test_type, parameter_name)) | 257 parameter_name, test_type, parameter_name)) |
| 239 # There can be multiple presence checks. We need them all since a later | 258 # There can be multiple presence checks. We need them all since a later |
| 240 # optional argument could have been passed by name, leaving 'holes'. | 259 # optional argument could have been passed by name, leaving 'holes'. |
| 241 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) | 260 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]]
) |
| 242 | 261 |
| 243 GenerateCall(signature_index, argument_count, checks) | 262 GenerateCall(signature_index, argument_count, checks) |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 walk(interface.parents) | 622 walk(interface.parents) |
| 604 else: | 623 else: |
| 605 walk(interface.parents[1:]) | 624 walk(interface.parents[1:]) |
| 606 return result | 625 return result |
| 607 | 626 |
| 608 def _DartType(self, type_name): | 627 def _DartType(self, type_name): |
| 609 return self._type_registry.DartType(type_name) | 628 return self._type_registry.DartType(type_name) |
| 610 | 629 |
| 611 def _IsPrivate(self, name): | 630 def _IsPrivate(self, name): |
| 612 return name.startswith('_') | 631 return name.startswith('_') |
| OLD | NEW |