Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/dom/scripts/htmldartgenerator.py

Issue 2875773003: Roll 50: Updated for push to origin/master. (Closed)
Patch Set: Roll 50: Updated to latest Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 if is_void: 387 if is_void:
388 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n') 388 call_emitter = call_emitter.Emit('$(INDENT)$!CALL;\n$(INDENT)return;\n')
389 else: 389 else:
390 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n') 390 call_emitter = call_emitter.Emit('$(INDENT)return $!CALL;\n')
391 391
392 version[0] += 1 392 version[0] += 1
393 generate_call(stmts_emitter, call_emitter, 393 generate_call(stmts_emitter, call_emitter,
394 version[0], signature_index, argument_count) 394 version[0], signature_index, argument_count)
395 395
396 def IsTypeChecking(interface_argument):
397 return 'LegacyInterfaceTypeChecking' in interface_argument.ext_attrs or \
398 self._database.HasInterface(interface_argument.id)
399
396 def GenerateChecksAndCall(signature_index, argument_count): 400 def GenerateChecksAndCall(signature_index, argument_count):
397 checks = [] 401 checks = []
398 typechecked_interface = \ 402 typechecked_interface = IsTypeChecking(self._interface)
399 ('TypeChecking' in self._interface.ext_attrs) and \
400 ('Interface' in self._interface.ext_attrs['TypeChecking'])
401 403
402 for i in reversed(range(0, argument_count)): 404 for i in reversed(range(0, argument_count)):
403 argument = signatures[signature_index][i] 405 argument = signatures[signature_index][i]
404 parameter_name = parameter_names[i] 406 parameter_name = parameter_names[i]
405 407
406 test_type = self._NarrowToImplementationType(argument.type.id) 408 test_type = self._NarrowToImplementationType(argument.type.id)
407 409
408 if test_type in ['dynamic', 'Object']: 410 if test_type in ['dynamic', 'Object']:
409 checks.append('%s != null' % parameter_name) 411 checks.append('%s != null' % parameter_name)
410 elif not can_omit_type_check(test_type, i): 412 elif not can_omit_type_check(test_type, i):
411 typechecked = typechecked_interface or \ 413 typechecked = typechecked_interface or IsTypeChecking(argument)
412 ('TypeChecking' in argument.ext_attrs) and \
413 ('Interface' in argument.ext_attrs['TypeChecking'])
414 converts_null = \ 414 converts_null = \
415 ('TreatNullAs' in argument.ext_attrs) or \ 415 ('TreatNullAs' in argument.ext_attrs) or \
416 (argument.default_value is not None) or \ 416 (argument.default_value is not None) or \
417 (argument.default_value_is_null) 417 (argument.default_value_is_null)
418 if argument.type.nullable or converts_null or not typechecked: 418 if argument.type.nullable or converts_null or not typechecked:
419 checks.append('(%s is %s || %s == null)' % ( 419 checks.append('(%s is %s || %s == null)' % (
420 parameter_name, test_type, parameter_name)) 420 parameter_name, test_type, parameter_name))
421 else: 421 else:
422 checks.append('(%s is %s)' % ( 422 checks.append('(%s is %s)' % (
423 parameter_name, test_type)) 423 parameter_name, test_type))
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 factory_constructor_name - The name of the constructor on the 534 factory_constructor_name - The name of the constructor on the
535 factory_name to call (calls an autogenerated FactoryProvider 535 factory_name to call (calls an autogenerated FactoryProvider
536 if unspecified) 536 if unspecified)
537 """ 537 """
538 for constructor_info in constructors: 538 for constructor_info in constructors:
539 self._AddConstructor( 539 self._AddConstructor(
540 constructor_info, factory_name, factory_constructor_name) 540 constructor_info, factory_name, factory_constructor_name)
541 541
542 def _AddConstructor(self, 542 def _AddConstructor(self,
543 constructor_info, factory_name, factory_constructor_name): 543 constructor_info, factory_name, factory_constructor_name):
544 # Hack to ignore the Image constructor used by JavaScript. 544 # Hack to ignore the constructor used by JavaScript.
545 if ((self._interface.id == 'HTMLImageElement' or 545 if ((self._interface.id == 'HTMLImageElement' or
546 self._interface.id == 'Blob' or 546 self._interface.id == 'Blob' or
547 self._interface.id == 'TouchEvent' or
547 self._interface.id == 'DOMException') 548 self._interface.id == 'DOMException')
548 and not constructor_info.pure_dart_constructor): 549 and not constructor_info.pure_dart_constructor):
549 return 550 return
550 551
551 if self.GenerateCustomFactory(constructor_info): 552 if self.GenerateCustomFactory(constructor_info):
552 return 553 return
553 554
554 metadata = self._metadata.GetFormattedMetadata( 555 metadata = self._metadata.GetFormattedMetadata(
555 self._library_name, self._interface, self._interface.id, ' ') 556 self._library_name, self._interface, self._interface.id, ' ')
556 557
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 def _InputType(self, type_name, info): 893 def _InputType(self, type_name, info):
893 conversion = self._InputConversion(type_name, info.declared_name) 894 conversion = self._InputConversion(type_name, info.declared_name)
894 if conversion: 895 if conversion:
895 return conversion.input_type 896 return conversion.input_type
896 else: 897 else:
897 # If typedef it's a union return dynamic. 898 # If typedef it's a union return dynamic.
898 if self._database.HasTypeDef(type_name): 899 if self._database.HasTypeDef(type_name):
899 return 'dynamic' 900 return 'dynamic'
900 else: 901 else:
901 return self._NarrowInputType(type_name) if type_name else 'dynamic' 902 return self._NarrowInputType(type_name) if type_name else 'dynamic'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698