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

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

Issue 1832713002: Optimize dartium dart:html bindings so real world application performance is acceptable. Improves d… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: update cached patches Created 4 years, 8 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
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | tools/dom/src/dartium_CustomElementSupport.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 logging 10 import logging
11 import os 11 import os
12 from generator import * 12 from generator import *
13 from htmldartgenerator import * 13 from htmldartgenerator import *
14 from idlnode import IDLArgument, IDLAttribute, IDLEnum, IDLMember 14 from idlnode import IDLArgument, IDLAttribute, IDLEnum, IDLMember
15 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES 15 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES
16 16
17 _logger = logging.getLogger('systemnative') 17 _logger = logging.getLogger('systemnative')
18 18
19 # TODO(vsm): This should be recoverable from IDL, but we appear to not 19 # TODO(vsm): This should be recoverable from IDL, but we appear to not
20 # track the necessary info. 20 # track the necessary info.
21 _url_utils = ['hash', 'host', 'hostname', 'origin', 21 _url_utils = ['hash', 'host', 'hostname', 'origin',
22 'password', 'pathname', 'port', 'protocol', 22 'password', 'pathname', 'port', 'protocol',
23 'search', 'username'] 23 'search', 'username']
24 24
25 _promise_to_future = Conversion('convertNativePromiseToDartFuture', 'dynamic', ' Future')
26
25 def array_type(data_type): 27 def array_type(data_type):
26 matched = re.match(r'([\w\d_\s]+)\[\]', data_type) 28 matched = re.match(r'([\w\d_\s]+)\[\]', data_type)
27 if not matched: 29 if not matched:
28 return None 30 return None
29 return matched.group(1) 31 return matched.group(1)
30 32
31 _sequence_matcher = re.compile('sequence\<(.+)\>') 33 _sequence_matcher = re.compile('sequence\<(.+)\>')
32 34
33 def TypeIdToBlinkName(interface_id, database): 35 def TypeIdToBlinkName(interface_id, database):
34 # Maybe should use the type_registry here? 36 # Maybe should use the type_registry here?
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 103
102 def ImplementsMergedMembers(self): 104 def ImplementsMergedMembers(self):
103 # We could not add merged functions to implementation class because 105 # We could not add merged functions to implementation class because
104 # underlying c++ object doesn't implement them. Merged functions are 106 # underlying c++ object doesn't implement them. Merged functions are
105 # generated on merged interface implementation instead. 107 # generated on merged interface implementation instead.
106 return False 108 return False
107 109
108 def CustomJSMembers(self): 110 def CustomJSMembers(self):
109 return {} 111 return {}
110 112
113 def _OutputConversion(self, idl_type, member):
114 conversion = FindConversion(idl_type, 'get', self._interface.id, member)
115 # TODO(jacobr) handle promise consistently in dart2js and dartium.
116 if idl_type == 'Promise':
117 return _promise_to_future
118 if conversion:
119 if conversion.function_name in ('_convertNativeToDart_Window', '_convertNa tiveToDart_EventTarget', 'convertNativeToDart_DateTime', 'convertNativeToDart_Im ageData'):
120 return None
121 return conversion
122
111 def _InputConversion(self, idl_type, member): 123 def _InputConversion(self, idl_type, member):
112 return FindConversion(idl_type, 'set', self._interface.id, member) 124 return FindConversion(idl_type, 'set', self._interface.id, member)
113 125
114 def GenerateCallback(self, info): 126 def GenerateCallback(self, info):
115 return None 127 return None
116 128
117 def ImplementationTemplate(self): 129 def ImplementationTemplate(self):
118 template = None 130 template = None
119 interface_name = self._interface.doc_js_name 131 interface_name = self._interface.doc_js_name
120 if interface_name == self._interface.id or not self._database.HasInterface(i nterface_name): 132 if interface_name == self._interface.id or not self._database.HasInterface(i nterface_name):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 255
244 # Then we emit the impedance matching wrapper to call out to the 256 # Then we emit the impedance matching wrapper to call out to the
245 # toplevel wrapper 257 # toplevel wrapper
246 if not emit_to_native: 258 if not emit_to_native:
247 toplevel_name = \ 259 toplevel_name = \
248 self.DeriveQualifiedBlinkName(self._interface.id, 260 self.DeriveQualifiedBlinkName(self._interface.id,
249 dart_native_name) 261 dart_native_name)
250 self._members_emitter.Emit( 262 self._members_emitter.Emit(
251 '\n @DocsEditable()\n' 263 '\n @DocsEditable()\n'
252 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => ' 264 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => '
253 'wrap_jso($TOPLEVEL_NAME($OUTPARAMETERS));\n', 265 '$TOPLEVEL_NAME($OUTPARAMETERS);\n',
254 INTERFACE_NAME=self._interface_type_info.interface_name(), 266 INTERFACE_NAME=self._interface_type_info.interface_name(),
255 FACTORY_METHOD_NAME=factory_method_name, 267 FACTORY_METHOD_NAME=factory_method_name,
256 PARAMETERS=typed_formals, 268 PARAMETERS=typed_formals,
257 TOPLEVEL_NAME=toplevel_name, 269 TOPLEVEL_NAME=toplevel_name,
258 OUTPARAMETERS=parameters) 270 OUTPARAMETERS=parameters)
259 271
260 self._cpp_resolver_emitter.Emit( 272 self._cpp_resolver_emitter.Emit(
261 ' if (name == "$ID")\n' 273 ' if (name == "$ID")\n'
262 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n', 274 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n',
263 ID=constructor_callback_id, 275 ID=constructor_callback_id,
264 WEBKIT_INTERFACE_NAME=self._interface.id, 276 WEBKIT_INTERFACE_NAME=self._interface.id,
265 CPP_CALLBACK=constructor_callback_cpp_name) 277 CPP_CALLBACK=constructor_callback_cpp_name)
266 278
267 def GenerateCustomFactory(self, constructor_info): 279 def GenerateCustomFactory(self, constructor_info):
268 if 'CustomConstructor' not in self._interface.ext_attrs: 280 if 'CustomConstructor' not in self._interface.ext_attrs:
269 return False 281 return False
270 282
271 annotations = self._metadata.GetFormattedMetadata(self._library_name, 283 annotations = self._metadata.GetFormattedMetadata(self._library_name,
272 self._interface, self._interface.id, ' ') 284 self._interface, self._interface.id, ' ')
273 285
274 self._members_emitter.Emit( 286 self._members_emitter.Emit(
275 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => wrap_jso(_create($FACTORY_P ARAMS));\n', 287 '\n $(ANNOTATIONS)factory $CTOR($PARAMS) => _create($FACTORY_PARAMS);\n ',
276 ANNOTATIONS=annotations, 288 ANNOTATIONS=annotations,
277 CTOR=constructor_info._ConstructorFullName(self._DartType), 289 CTOR=constructor_info._ConstructorFullName(self._DartType),
278 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), 290 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
279 FACTORY_PARAMS= \ 291 FACTORY_PARAMS= \
280 constructor_info.ParametersAsArgumentList()) 292 constructor_info.ParametersAsArgumentList())
281 293
282 # MutationObserver has custom _create. TODO(terry): Consider table but this is only one. 294 # MutationObserver has custom _create. TODO(terry): Consider table but this is only one.
283 if self._interface.id != 'MutationObserver': 295 if self._interface.id != 'MutationObserver':
284 constructor_callback_cpp_name = 'constructorCallback' 296 constructor_callback_cpp_name = 'constructorCallback'
285 self._EmitConstructorInfrastructure( 297 self._EmitConstructorInfrastructure(
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 # Unwrap the type to get the JsObject if Type is: 541 # Unwrap the type to get the JsObject if Type is:
530 # 542 #
531 # - known IDL type 543 # - known IDL type
532 # - type_id is None then it's probably a union type or overloaded 544 # - type_id is None then it's probably a union type or overloaded
533 # it's a dynamic/any type 545 # it's a dynamic/any type
534 # - type is Object 546 # - type is Object
535 # 547 #
536 # JsObject maybe stored in the Dart class. 548 # JsObject maybe stored in the Dart class.
537 return_wrap_jso = wrap_return_type_blink(return_type, attr.type.id, self ._type_registry) 549 return_wrap_jso = wrap_return_type_blink(return_type, attr.type.id, self ._type_registry)
538 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec t 550 wrap_unwrap_list.append(return_wrap_jso) # wrap_jso the returned objec t
539 wrap_unwrap_list.append(self._dart_use_blink) # this must be unwrap_jso 551 wrap_unwrap_list.append(self._dart_use_blink)
540 552
541 # This seems to have been replaced with Custom=Getter (see above), but 553 # This seems to have been replaced with Custom=Getter (see above), but
542 # check to be sure we don't see the old syntax 554 # check to be sure we don't see the old syntax
543 assert(not ('CustomGetter' in attr.ext_attrs)) 555 assert(not ('CustomGetter' in attr.ext_attrs))
544 native_suffix = 'Getter' 556 native_suffix = 'Getter'
545 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) 557 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
546 native_entry = \ 558 native_entry = \
547 self.DeriveNativeEntry(attr.id, 'Getter', None) 559 self.DeriveNativeEntry(attr.id, 'Getter', None)
560 output_conversion = self._OutputConversion(attr.type.id, attr.id)
561
548 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 562 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
549 dart_declaration, attr.is_static, return_type, parameters, 563 dart_declaration, attr.is_static, return_type, parameters,
550 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry, 564 native_suffix, is_custom, auto_scope_setup, native_entry=native_entry,
551 wrap_unwrap_list=wrap_unwrap_list, dictionary_return=dictionary_returned ) 565 wrap_unwrap_list=wrap_unwrap_list, dictionary_return=dictionary_returned ,
566 output_conversion=output_conversion)
552 if is_custom: 567 if is_custom:
553 return 568 return
554 569
555 if 'Reflect' in attr.ext_attrs: 570 if 'Reflect' in attr.ext_attrs:
556 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 571 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
557 if 'URL' in attr.ext_attrs: 572 if 'URL' in attr.ext_attrs:
558 if 'NonEmpty' in attr.ext_attrs: 573 if 'NonEmpty' in attr.ext_attrs:
559 webcore_function_name = 'getNonEmptyURLAttribute' 574 webcore_function_name = 'getNonEmptyURLAttribute'
560 else: 575 else:
561 webcore_function_name = 'getURLAttribute' 576 webcore_function_name = 'getURLAttribute'
(...skipping 14 matching lines...) Expand all
576 attr.ext_attrs['RaisesException'] != 'Setter') 591 attr.ext_attrs['RaisesException'] != 'Setter')
577 592
578 def _AddSetter(self, attr, html_name): 593 def _AddSetter(self, attr, html_name):
579 return_type = 'void' 594 return_type = 'void'
580 ptype = self._DartType(attr.type.id) 595 ptype = self._DartType(attr.type.id)
581 596
582 type_info = self._TypeInfo(attr.type.id) 597 type_info = self._TypeInfo(attr.type.id)
583 598
584 # Is the setter value a DartClass (that has a JsObject) or the type is 599 # Is the setter value a DartClass (that has a JsObject) or the type is
585 # None (it's a dynamic/any type) then unwrap_jso before passing to blink. 600 # None (it's a dynamic/any type) then unwrap_jso before passing to blink.
586 parameters = ['unwrap_jso(value)' if (isinstance(type_info, InterfaceIDLType Info) or 601 parameters = ['value']
587 not(attr.type.id) or ptype == 'Object' )
588 else 'value']
589 602
590 dart_declaration = 'set %s(%s value)' % (html_name, ptype) 603 dart_declaration = 'set %s(%s value)' % (html_name, ptype)
591 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or 604 is_custom = _IsCustom(attr) and (_IsCustomValue(attr, None) or
592 _IsCustomValue(attr, 'Setter')) 605 _IsCustomValue(attr, 'Setter'))
593 # This seems to have been replaced with Custom=Setter (see above), but 606 # This seems to have been replaced with Custom=Setter (see above), but
594 # check to be sure we don't see the old syntax 607 # check to be sure we don't see the old syntax
595 assert(not ('CustomSetter' in attr.ext_attrs)) 608 assert(not ('CustomSetter' in attr.ext_attrs))
596 assert(not ('V8CustomSetter' in attr.ext_attrs)) 609 assert(not ('V8CustomSetter' in attr.ext_attrs))
597 native_suffix = 'Setter' 610 native_suffix = 'Setter'
598 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix) 611 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 # 657 #
645 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 658 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
646 # 659 #
647 dart_element_type = self._DartType(element_type) 660 dart_element_type = self._DartType(element_type)
648 if self._HasNativeIndexGetter(): 661 if self._HasNativeIndexGetter():
649 self._EmitNativeIndexGetter(dart_element_type) 662 self._EmitNativeIndexGetter(dart_element_type)
650 elif self._HasExplicitIndexedGetter(): 663 elif self._HasExplicitIndexedGetter():
651 self._EmitExplicitIndexedGetter(dart_element_type) 664 self._EmitExplicitIndexedGetter(dart_element_type)
652 else: 665 else:
653 is_custom = any((op.id == 'item' and _IsCustom(op)) for op in self._interf ace.operations) 666 is_custom = any((op.id == 'item' and _IsCustom(op)) for op in self._interf ace.operations)
667
668 output_conversion = self._OutputConversion(element_type, 'item')
669 conversion_name = ''
670 if output_conversion:
671 conversion_name = output_conversion.function_name
672
654 # First emit a toplevel function to do the native call 673 # First emit a toplevel function to do the native call
655 # Calls to this are emitted elsewhere, 674 # Calls to this are emitted elsewhere,
656 dart_native_name, resolver_string = \ 675 dart_native_name, resolver_string = \
657 self.DeriveNativeEntry("item", 'Method', 1) 676 self.DeriveNativeEntry("item", 'Method', 1)
658 677
659 # Emit the method which calls the toplevel function, along with 678 # Emit the method which calls the toplevel function, along with
660 # the [] operator. 679 # the [] operator.
661 dart_qualified_name = \ 680 dart_qualified_name = \
662 self.DeriveQualifiedBlinkName(self._interface.id, 681 self.DeriveQualifiedBlinkName(self._interface.id,
663 dart_native_name) 682 dart_native_name)
664 683
665 type_info = self._TypeInfo(element_type) 684 type_info = self._TypeInfo(element_type)
666 # Does nativeIndexGetter return a DartClass (JsObject) if so wrap_jso.
667 wrap_jso_start = ''
668 wrap_jso_end = ''
669 if (isinstance(type_info, InterfaceIDLTypeInfo) or
670 wrap_type_blink(type_info.narrow_dart_type(), self._type_registry)):
671 wrap_jso_start = 'wrap_jso('
672 wrap_jso_end = ')'
673 blinkNativeIndexed = """ 685 blinkNativeIndexed = """
674 $TYPE operator[](int index) { 686 $TYPE operator[](int index) {
675 if (index < 0 || index >= length) 687 if (index < 0 || index >= length)
676 throw new RangeError.index(index, this); 688 throw new RangeError.index(index, this);
677 return %s$(DART_NATIVE_NAME)(unwrap_jso(this), index)%s; 689 return _nativeIndexedGetter(index);
678 } 690 }
679 691
680 $TYPE _nativeIndexedGetter(int index) => %s$(DART_NATIVE_NAME)(unwrap_jso(this ), index)%s; 692 $TYPE _nativeIndexedGetter(int index) => $(CONVERSION_NAME)($(DART_NATIVE_NAME )(this, index));
681 """ % (wrap_jso_start, wrap_jso_end, wrap_jso_start, wrap_jso_end) 693 """
682 # Wrap the type to store the JsObject if Type is: 694 blinkNativeIndexedGetter = \
683 # 695 ' $(DART_NATIVE_NAME)(this, index);\n'
684 # - known IDL type
685 # - type_id is None then it's probably a union type or overloaded
686 # it's a dynamic/any type
687 # - type is Object
688 #
689 # JsObject maybe stored in the Dart class.
690 if isinstance(type_info, InterfaceIDLTypeInfo) or not(type_info) or dart_e lement_type == 'Object':
691 blinkNativeIndexedGetter = \
692 ' {0}$(DART_NATIVE_NAME)(unwrap_jso(this), index){1};\n'.format('w rap_jso(', ')')
693 else:
694 blinkNativeIndexedGetter = \
695 ' $(DART_NATIVE_NAME)(unwrap_jso(this), index);\n'
696 self._members_emitter.Emit(blinkNativeIndexed, 696 self._members_emitter.Emit(blinkNativeIndexed,
697 DART_NATIVE_NAME=dart_qualified_name, 697 DART_NATIVE_NAME=dart_qualified_name,
698 TYPE=self.SecureOutputType(element_type), 698 TYPE=self.SecureOutputType(element_type),
699 INTERFACE=self._interface.id) 699 INTERFACE=self._interface.id,
700 CONVERSION_NAME=conversion_name)
700 701
701 if self._HasNativeIndexSetter(): 702 if self._HasNativeIndexSetter():
702 self._EmitNativeIndexSetter(dart_element_type) 703 self._EmitNativeIndexSetter(dart_element_type)
703 else: 704 else:
704 self._members_emitter.Emit( 705 self._members_emitter.Emit(
705 '\n' 706 '\n'
706 ' void operator[]=(int index, $TYPE value) {\n' 707 ' void operator[]=(int index, $TYPE value) {\n'
707 ' throw new UnsupportedError("Cannot assign element of immutable Li st.");\n' 708 ' throw new UnsupportedError("Cannot assign element of immutable Li st.");\n'
708 ' }\n', 709 ' }\n',
709 TYPE=dart_element_type) 710 TYPE=dart_element_type)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 792
792 formals = info.ParametersAsDeclaration(self._DartType) 793 formals = info.ParametersAsDeclaration(self._DartType)
793 794
794 parameters = info.ParametersAsListOfVariables(None, 795 parameters = info.ParametersAsListOfVariables(None,
795 self._type_registry if self._d art_use_blink else None, 796 self._type_registry if self._d art_use_blink else None,
796 dart_js_interop, 797 dart_js_interop,
797 self) 798 self)
798 799
799 operation = info.operations[0] 800 operation = info.operations[0]
800 801
802 output_conversion = self._OutputConversion(operation.type.id, operation.id)
803
801 dictionary_returned = False 804 dictionary_returned = False
802 # Return type for dictionary is any (untyped). 805 # Return type for dictionary is any (untyped).
803 if operation.type.id == 'Dictionary': 806 if operation.type.id == 'Dictionary':
804 return_type = ''; 807 return_type = '';
805 dictionary_returned = True; 808 dictionary_returned = True;
806 809
807 dart_declaration = '%s%s %s(%s)' % ( 810 dart_declaration = '%s%s %s(%s)' % (
808 'static ' if info.IsStatic() else '', 811 'static ' if info.IsStatic() else '',
809 return_type, 812 return_type,
810 html_name, 813 html_name,
811 formals) 814 formals)
812 815
813 is_custom = _IsCustom(operation) 816 is_custom = _IsCustom(operation)
814 has_optional_arguments = any(IsOptional(argument) for argument in operation. arguments) 817 has_optional_arguments = any(IsOptional(argument) for argument in operation. arguments)
815 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 818 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
816 819
817 # Operation uses blink? 820 # Operation uses blink?
818 wrap_unwrap_list = []; 821 wrap_unwrap_list = [];
819 return_wrap_jso = False 822 return_wrap_jso = False
820 # return type wrapped? 823 # return type wrapped?
821 if self._dart_use_blink: 824 if self._dart_use_blink:
822 # Wrap the type to store the JsObject if Type is: 825 # Wrap the type to store the JsObject if Type is:
823 # 826 #
824 # - known IDL type
825 # - type_id is None then it's probably a union type or overloaded
826 # it's a dynamic/any type 827 # it's a dynamic/any type
827 # - type is Object 828 # - type is Object
828 # 829 #
829 # JsObject maybe stored in the Dart class. 830 # JsObject maybe stored in the Dart class.
830 return_wrap_jso = wrap_return_type_blink(return_type, info.type_name, se lf._type_registry) 831 return_wrap_jso = wrap_return_type_blink(return_type, info.type_name, se lf._type_registry)
831 return_type_info = self._type_registry.TypeInfo(info.type_name) 832 return_type_info = self._type_registry.TypeInfo(info.type_name)
832 if (isinstance(return_type_info, SequenceIDLTypeInfo) and
833 not isinstance(return_type_info._item_info, PrimitiveIDLTypeInfo)):
834 return_wrap_jso = True
835 # wrap_jso the returned object 833 # wrap_jso the returned object
836 wrap_unwrap_list.append(return_wrap_jso) 834 wrap_unwrap_list.append(return_wrap_jso)
837 # The 'this' parameter must be unwrap_jso
838 wrap_unwrap_list.append(self._dart_use_blink) 835 wrap_unwrap_list.append(self._dart_use_blink)
839 836
840 if info.callback_args: 837 if info.callback_args:
841 self._AddFutureifiedOperation(info, html_name) 838 self._AddFutureifiedOperation(info, html_name)
842 elif not needs_dispatcher: 839 elif not needs_dispatcher:
843 # Bind directly to native implementation 840 # Bind directly to native implementation
844 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 841 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
845 native_suffix = 'Callback' 842 native_suffix = 'Callback'
846 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) 843 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix)
847 native_entry = \ 844 native_entry = \
848 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos)) 845 self.DeriveNativeEntry(operation.id, 'Method', len(info.param_infos))
849 cpp_callback_name = self._GenerateNativeBinding( 846 cpp_callback_name = self._GenerateNativeBinding(
850 info.name, argument_count, dart_declaration, 847 info.name, argument_count, dart_declaration,
851 info.IsStatic(), return_type, parameters, 848 info.IsStatic(), return_type, parameters,
852 native_suffix, is_custom, auto_scope_setup, 849 native_suffix, is_custom, auto_scope_setup,
853 native_entry=native_entry, 850 native_entry=native_entry,
854 wrap_unwrap_list=wrap_unwrap_list, 851 wrap_unwrap_list=wrap_unwrap_list,
855 dictionary_return=dictionary_returned) 852 dictionary_return=dictionary_returned,
853 output_conversion=output_conversion)
856 if not is_custom: 854 if not is_custom:
857 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup) 855 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup)
858 else: 856 else:
859 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e) 857 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam e)
860 858
861 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): 859 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name):
862 860
863 def GenerateCall( 861 def GenerateCall(
864 stmts_emitter, call_emitter, version, operation, argument_count): 862 stmts_emitter, call_emitter, version, operation, argument_count):
865 native_suffix = 'Callback' 863 native_suffix = 'Callback'
866 actuals = info.ParametersAsListOfVariables(argument_count, 864 actuals = info.ParametersAsListOfVariables(argument_count,
867 self._type_registry if self._da rt_use_blink else None, 865 self._type_registry if self._da rt_use_blink else None,
868 self._dart_js_interop, 866 self._dart_js_interop,
869 self) 867 self)
870 actuals_s = ", ".join(actuals) 868 actuals_s = ", ".join(actuals)
871 formals=actuals 869 formals=actuals
872 return_type = self.SecureOutputType(operation.type.id) 870 return_type = self.SecureOutputType(operation.type.id)
873 871
874 return_wrap_jso = False 872 return_wrap_jso = False
875 if self._dart_use_blink: 873 if self._dart_use_blink:
876 return_wrap_jso = wrap_return_type_blink(return_type, info.type_name, self._type_registry) 874 return_wrap_jso = wrap_return_type_blink(return_type, info.type_name, self._type_registry)
877 875
878 native_suffix = 'Callback' 876 native_suffix = 'Callback'
879 is_custom = _IsCustom(operation) 877 is_custom = _IsCustom(operation)
880 base_name = '_%s_%s' % (operation.id, version) 878 base_name = '_%s_%s' % (operation.id, version)
881 static = True 879 static = True
882 if not operation.is_static: 880 if not operation.is_static:
883 actuals = ['unwrap_jso(this)' if self._dart_use_blink else 'this'] + act uals 881 actuals = ['this'] + actuals
884 formals = ['mthis'] + formals 882 formals = ['mthis'] + formals
885 actuals_s = ", ".join(actuals) 883 actuals_s = ", ".join(actuals)
886 formals_s = ", ".join(formals) 884 formals_s = ", ".join(formals)
887 dart_declaration = '%s(%s)' % ( 885 dart_declaration = '%s(%s)' % (
888 base_name, formals_s) 886 base_name, formals_s)
889 native_entry = \ 887 native_entry = \
890 self.DeriveNativeEntry(operation.id, 'Method', argument_count) 888 self.DeriveNativeEntry(operation.id, 'Method', argument_count)
891 overload_base_name = native_entry[0] 889 overload_base_name = native_entry[0]
892 overload_name = \ 890 overload_name = \
893 self.DeriveQualifiedBlinkName(self._interface.id, 891 self.DeriveQualifiedBlinkName(self._interface.id,
894 overload_base_name) 892 overload_base_name)
895 if return_wrap_jso: 893 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s)
896 call_emitter.Emit('wrap_jso($NAME($ARGS))', NAME=overload_name, ARGS=a ctuals_s)
897 else:
898 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s)
899 auto_scope_setup = \ 894 auto_scope_setup = \
900 self._GenerateAutoSetupScope(base_name, native_suffix) 895 self._GenerateAutoSetupScope(base_name, native_suffix)
901 cpp_callback_name = self._GenerateNativeBinding( 896 cpp_callback_name = self._GenerateNativeBinding(
902 base_name, (0 if static else 1) + argument_count, 897 base_name, (0 if static else 1) + argument_count,
903 dart_declaration, static, return_type, formals, 898 dart_declaration, static, return_type, formals,
904 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, 899 native_suffix, is_custom, auto_scope_setup, emit_metadata=False,
905 emit_to_native=True, native_entry=native_entry) 900 emit_to_native=True, native_entry=native_entry)
906 if not is_custom: 901 if not is_custom:
907 self._GenerateOperationNativeCallback(operation, 902 self._GenerateOperationNativeCallback(operation,
908 operation.arguments[:argument_count], cpp_callback_name, 903 operation.arguments[:argument_count], cpp_callback_name,
(...skipping 11 matching lines...) Expand all
920 pass 915 pass
921 916
922 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name, auto_scope_setup=True): 917 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name, auto_scope_setup=True):
923 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 918 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
924 919
925 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name) 920 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name)
926 921
927 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 922 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
928 static, return_type, parameters, native_suffix, is_custom, 923 static, return_type, parameters, native_suffix, is_custom,
929 auto_scope_setup=True, emit_metadata=True, emit_to_native=False, 924 auto_scope_setup=True, emit_metadata=True, emit_to_native=False,
930 native_entry=None, wrap_unwrap_list=[], dictionary_return=False): 925 native_entry=None, wrap_unwrap_list=[], dictionary_return=False, output_co nversion=None):
931 metadata = [] 926 metadata = []
932 if emit_metadata: 927 if emit_metadata:
933 metadata = self._metadata.GetFormattedMetadata( 928 metadata = self._metadata.GetFormattedMetadata(
934 self._renamer.GetLibraryName(self._interface), 929 self._renamer.GetLibraryName(self._interface),
935 self._interface, idl_name, ' ') 930 self._interface, idl_name, ' ')
936 931
937 if (native_entry): 932 if (native_entry):
938 dart_native_name, native_binding = native_entry 933 dart_native_name, native_binding = native_entry
939 else: 934 else:
940 dart_native_name = \ 935 dart_native_name = \
941 self.DeriveNativeName(idl_name, native_suffix) 936 self.DeriveNativeName(idl_name, native_suffix)
942 native_binding_id = self._interface.id 937 native_binding_id = self._interface.id
943 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) 938 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database)
944 native_binding = \ 939 native_binding = \
945 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) 940 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix)
946 941
947 if not static: 942 if not static:
948 formals = ", ".join(['mthis'] + parameters) 943 formals = ", ".join(['mthis'] + parameters)
949 if wrap_unwrap_list and wrap_unwrap_list[1]: 944 actuals = ", ".join(['this'] + parameters)
950 actuals = ", ".join(['unwrap_jso(this)'] + parameters)
951 else:
952 actuals = ", ".join(['this'] + parameters)
953 else: 945 else:
954 formals = ", ".join(parameters) 946 formals = ", ".join(parameters)
955 actuals = ", ".join(parameters) 947 actuals = ", ".join(parameters)
956 948
957 if not emit_to_native: 949 if not emit_to_native:
958 caller_emitter = self._members_emitter 950 caller_emitter = self._members_emitter
959 full_dart_name = \ 951 full_dart_name = \
960 self.DeriveQualifiedBlinkName(self._interface.id, 952 self.DeriveQualifiedBlinkName(self._interface.id,
961 dart_native_name) 953 dart_native_name)
962 if IsPureInterface(self._interface.id): 954 if IsPureInterface(self._interface.id):
963 caller_emitter.Emit( 955 caller_emitter.Emit(
964 '\n' 956 '\n'
965 ' $METADATA$DART_DECLARATION;\n', 957 ' $METADATA$DART_DECLARATION;\n',
966 METADATA=metadata, 958 METADATA=metadata,
967 DART_DECLARATION=dart_declaration) 959 DART_DECLARATION=dart_declaration)
968 else: 960 else:
969 emit_template = ''' 961 emit_template = '''
970 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS); 962 $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);
971 ''' 963 '''
972 if wrap_unwrap_list and wrap_unwrap_list[0]: 964 if output_conversion and not dictionary_return:
965 conversion_template = '''
966 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
967 '''
968 emit_template = conversion_template % output_conversion.function_n ame
969
970 elif wrap_unwrap_list and wrap_unwrap_list[0]:
973 if return_type == 'Rectangle': 971 if return_type == 'Rectangle':
974 jso_util_method = 'make_dart_rectangle' 972 jso_util_method = 'make_dart_rectangle'
975 elif wrap_unwrap_list[0]: 973 elif wrap_unwrap_list[0]:
976 jso_util_method = 'wrap_jso' 974 jso_util_method = ''
977 975
978 if dictionary_return: 976 if dictionary_return:
979 emit_jso_template = ''' 977 emit_jso_template = '''
980 $METADATA$DART_DECLARATION => convertNativeDictionaryToDartDictionary(%s($DART _NAME($ACTUALS))); 978 $METADATA$DART_DECLARATION => convertNativeDictionaryToDartDictionary(%s($DART _NAME($ACTUALS)));
981 ''' 979 '''
982 else: 980 else:
983 emit_jso_template = ''' 981 emit_jso_template = '''
984 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS)); 982 $METADATA$DART_DECLARATION => %s($DART_NAME($ACTUALS));
985 ''' 983 '''
986 emit_template = emit_jso_template % jso_util_method 984 emit_template = emit_jso_template % jso_util_method
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 1248
1251 def _IsCustom(op_or_attr): 1249 def _IsCustom(op_or_attr):
1252 assert(isinstance(op_or_attr, IDLMember)) 1250 assert(isinstance(op_or_attr, IDLMember))
1253 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr s 1251 return 'Custom' in op_or_attr.ext_attrs or 'DartCustom' in op_or_attr.ext_attr s
1254 1252
1255 def _IsCustomValue(op_or_attr, value): 1253 def _IsCustomValue(op_or_attr, value):
1256 if _IsCustom(op_or_attr): 1254 if _IsCustom(op_or_attr):
1257 return op_or_attr.ext_attrs.get('Custom') == value \ 1255 return op_or_attr.ext_attrs.get('Custom') == value \
1258 or op_or_attr.ext_attrs.get('DartCustom') == value 1256 or op_or_attr.ext_attrs.get('DartCustom') == value
1259 return False 1257 return False
OLDNEW
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | tools/dom/src/dartium_CustomElementSupport.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698