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 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. | |
|
Mads Ager (google)
2013/03/11 14:13:18
Let's expand on the comment?
Temporary ugly hack
Anton Muhin
2013/03/11 14:35:27
Done.
| |
| 235 from systemnative import DartiumBackend | |
| 236 if isinstance(self, DartiumBackend): | |
| 237 if argument.type.id == 'ArrayBufferView': | |
| 238 checks.append( | |
| 239 '(%(name)s is ArrayBufferView ' | |
| 240 '|| %(name)s is _typeddata.TypedData ' | |
| 241 '|| %(name)s == null)' % {'name': parameter_name}) | |
| 242 continue | |
| 243 if argument.type.id == 'ArrayBuffer': | |
| 244 checks.append( | |
| 245 '(%(name)s is ArrayBuffer ' | |
| 246 '|| %(name)s is _typeddata.ByteBuffer ' | |
| 247 '|| %(name)s == null)' % {'name': parameter_name}) | |
| 248 continue | |
| 249 # end of ugly hack. | |
| 234 if test_type in ['dynamic', 'Object']: | 250 if test_type in ['dynamic', 'Object']: |
| 235 checks.append('?%s' % parameter_name) | 251 checks.append('?%s' % parameter_name) |
| 236 elif not can_omit_type_check(test_type, i): | 252 elif not can_omit_type_check(test_type, i): |
| 237 checks.append('(%s is %s || %s == null)' % ( | 253 checks.append('(%s is %s || %s == null)' % ( |
| 238 parameter_name, test_type, parameter_name)) | 254 parameter_name, test_type, parameter_name)) |
| 239 # There can be multiple presence checks. We need them all since a later | 255 # There can be multiple presence checks. We need them all since a later |
| 240 # optional argument could have been passed by name, leaving 'holes'. | 256 # optional argument could have been passed by name, leaving 'holes'. |
| 241 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) | 257 checks.extend(['!?%s' % name for name in parameter_names[argument_count:]] ) |
| 242 | 258 |
| 243 GenerateCall(signature_index, argument_count, checks) | 259 GenerateCall(signature_index, argument_count, checks) |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 walk(interface.parents) | 619 walk(interface.parents) |
| 604 else: | 620 else: |
| 605 walk(interface.parents[1:]) | 621 walk(interface.parents[1:]) |
| 606 return result | 622 return result |
| 607 | 623 |
| 608 def _DartType(self, type_name): | 624 def _DartType(self, type_name): |
| 609 return self._type_registry.DartType(type_name) | 625 return self._type_registry.DartType(type_name) |
| 610 | 626 |
| 611 def _IsPrivate(self, name): | 627 def _IsPrivate(self, name): |
| 612 return name.startswith('_') | 628 return name.startswith('_') |
| OLD | NEW |