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 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 os | 10 import os |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 auxiliary_dir = os.path.relpath(auxiliary_dir, dartium_output_dir) | 408 auxiliary_dir = os.path.relpath(auxiliary_dir, dartium_output_dir) |
409 emitter = \ | 409 emitter = \ |
410 library_emitter.Emit(template, | 410 library_emitter.Emit(template, |
411 AUXILIARY_DIR=massage_path(auxiliary_dir)) | 411 AUXILIARY_DIR=massage_path(auxiliary_dir)) |
412 return emitter | 412 return emitter |
413 | 413 |
414 class DartiumBackend(HtmlDartGenerator): | 414 class DartiumBackend(HtmlDartGenerator): |
415 """Generates Dart implementation for one DOM IDL interface.""" | 415 """Generates Dart implementation for one DOM IDL interface.""" |
416 | 416 |
417 def __init__(self, interface, native_library_emitter, | 417 def __init__(self, interface, native_library_emitter, |
418 cpp_library_emitter, options, dart_use_blink): | 418 cpp_library_emitter, options): |
419 super(DartiumBackend, self).__init__(interface, options, dart_use_blink) | 419 super(DartiumBackend, self).__init__(interface, options, True) |
420 | 420 |
421 self._interface = interface | 421 self._interface = interface |
422 self._cpp_library_emitter = cpp_library_emitter | 422 self._cpp_library_emitter = cpp_library_emitter |
423 self._native_library_emitter = native_library_emitter | 423 self._native_library_emitter = native_library_emitter |
424 self._database = options.database | 424 self._database = options.database |
425 self._template_loader = options.templates | 425 self._template_loader = options.templates |
426 self._type_registry = options.type_registry | 426 self._type_registry = options.type_registry |
427 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 427 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
428 self._metadata = options.metadata | 428 self._metadata = options.metadata |
429 # These get initialized by StartInterface | 429 # These get initialized by StartInterface |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 INTERFACE_NAME=self._interface.id) | 619 INTERFACE_NAME=self._interface.id) |
620 | 620 |
621 self._cpp_impl_includes.add('"DartArrayBufferViewCustom.h"'); | 621 self._cpp_impl_includes.add('"DartArrayBufferViewCustom.h"'); |
622 self._cpp_definitions_emitter.Emit( | 622 self._cpp_definitions_emitter.Emit( |
623 '\n' | 623 '\n' |
624 'static void constructorCallback(Dart_NativeArguments args)\n' | 624 'static void constructorCallback(Dart_NativeArguments args)\n' |
625 '{\n' | 625 '{\n' |
626 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT
ERFACE_NAME)>(args);\n' | 626 ' WebCore::DartArrayBufferViewInternal::constructWebGLArray<Dart$(INT
ERFACE_NAME)>(args);\n' |
627 '}\n', | 627 '}\n', |
628 INTERFACE_NAME=self._interface.id); | 628 INTERFACE_NAME=self._interface.id); |
629 if self._dart_use_blink: | 629 self._native_class_emitter = self._native_library_emitter.Emit( |
630 self._native_class_emitter = self._native_library_emitter.Emit( | 630 '\n' |
631 '\n' | 631 'class $INTERFACE_NAME {' |
632 'class $INTERFACE_NAME {' | 632 '$!METHODS' |
633 '$!METHODS' | 633 '}\n', |
634 '}\n', | 634 INTERFACE_NAME=DeriveBlinkClassName(self._interface.id)) |
635 INTERFACE_NAME=DeriveBlinkClassName(self._interface.id)) | |
636 | 635 |
637 def _EmitConstructorInfrastructure(self, | 636 def _EmitConstructorInfrastructure(self, |
638 constructor_info, cpp_prefix, cpp_suffix, factory_method_name, | 637 constructor_info, cpp_prefix, cpp_suffix, factory_method_name, |
639 arguments=None, emit_to_native=False, is_custom=False): | 638 arguments=None, emit_to_native=False, is_custom=False): |
640 | 639 |
641 constructor_callback_cpp_name = cpp_prefix + cpp_suffix | 640 constructor_callback_cpp_name = cpp_prefix + cpp_suffix |
642 | 641 |
643 if arguments is None: | 642 if arguments is None: |
644 if self._dart_use_blink: | 643 arguments = constructor_info.idl_args[0] |
645 arguments = constructor_info.idl_args[0] | 644 argument_count = len(arguments) |
646 argument_count = len(arguments) | |
647 else: | |
648 argument_count = len(constructor_info.param_infos) | |
649 else: | 645 else: |
650 argument_count = len(arguments) | 646 argument_count = len(arguments) |
651 | 647 |
652 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) | 648 typed_formals = constructor_info.ParametersAsArgumentList(argument_count) |
653 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) | 649 parameters = constructor_info.ParametersAsStringOfVariables(argument_count) |
654 interface_name = self._interface_type_info.interface_name() | 650 interface_name = self._interface_type_info.interface_name() |
655 | 651 |
656 if self._dart_use_blink: | 652 type_ids = [p.type.id for p in arguments[:argument_count]] |
657 type_ids = [p.type.id for p in arguments[:argument_count]] | 653 constructor_callback_id = \ |
| 654 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids, sel
f._database, is_custom) |
| 655 |
| 656 # First we emit the toplevel function |
| 657 dart_native_name = \ |
| 658 self.DeriveNativeName(constructor_callback_cpp_name) |
| 659 if constructor_callback_id in _cpp_resolver_string_map: |
658 constructor_callback_id = \ | 660 constructor_callback_id = \ |
659 DeriveResolverString(self._interface.id, cpp_suffix, None, type_ids,
self._database, is_custom) | 661 _cpp_resolver_string_map[constructor_callback_id] |
660 else: | 662 self._native_class_emitter.Emit( |
661 constructor_callback_id = self._interface.id + '_' + constructor_callbac
k_cpp_name | 663 '\n' |
| 664 ' static $FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', |
| 665 FACTORY_METHOD_NAME=dart_native_name, |
| 666 PARAMETERS=parameters, |
| 667 ID=constructor_callback_id) |
662 | 668 |
663 if self._dart_use_blink: | 669 # Then we emit the impedance matching wrapper to call out to the |
664 # First we emit the toplevel function | 670 # toplevel wrapper |
665 dart_native_name = \ | 671 if not emit_to_native: |
666 self.DeriveNativeName(constructor_callback_cpp_name) | 672 toplevel_name = \ |
667 if constructor_callback_id in _cpp_resolver_string_map: | 673 self.DeriveQualifiedBlinkName(self._interface.id, |
668 constructor_callback_id = \ | 674 dart_native_name) |
669 _cpp_resolver_string_map[constructor_callback_id] | |
670 self._native_class_emitter.Emit( | |
671 '\n' | |
672 ' static $FACTORY_METHOD_NAME($PARAMETERS) native "$ID";\n', | |
673 FACTORY_METHOD_NAME=dart_native_name, | |
674 PARAMETERS=parameters, | |
675 ID=constructor_callback_id) | |
676 | |
677 # Then we emit the impedance matching wrapper to call out to the | |
678 # toplevel wrapper | |
679 if not emit_to_native: | |
680 toplevel_name = \ | |
681 self.DeriveQualifiedBlinkName(self._interface.id, | |
682 dart_native_name) | |
683 self._members_emitter.Emit( | |
684 '\n @DocsEditable()\n' | |
685 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => ' | |
686 '$TOPLEVEL_NAME($OUTPARAMETERS);\n', | |
687 INTERFACE_NAME=self._interface_type_info.interface_name(), | |
688 FACTORY_METHOD_NAME=factory_method_name, | |
689 PARAMETERS=typed_formals, | |
690 TOPLEVEL_NAME=toplevel_name, | |
691 OUTPARAMETERS=parameters) | |
692 else: | |
693 self._members_emitter.Emit( | 675 self._members_emitter.Emit( |
694 '\n @DocsEditable()\n' | 676 '\n @DocsEditable()\n' |
695 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) ' | 677 ' static $INTERFACE_NAME $FACTORY_METHOD_NAME($PARAMETERS) => ' |
696 'native "$ID";\n', | 678 '$TOPLEVEL_NAME($OUTPARAMETERS);\n', |
697 INTERFACE_NAME=self._interface_type_info.interface_name(), | 679 INTERFACE_NAME=self._interface_type_info.interface_name(), |
698 FACTORY_METHOD_NAME=factory_method_name, | 680 FACTORY_METHOD_NAME=factory_method_name, |
699 PARAMETERS=typed_formals, | 681 PARAMETERS=typed_formals, |
700 ID=constructor_callback_id) | 682 TOPLEVEL_NAME=toplevel_name, |
| 683 OUTPARAMETERS=parameters) |
701 | 684 |
702 self._cpp_resolver_emitter.Emit( | 685 self._cpp_resolver_emitter.Emit( |
703 ' if (name == "$ID")\n' | 686 ' if (name == "$ID")\n' |
704 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n', | 687 ' return Dart$(WEBKIT_INTERFACE_NAME)Internal::$CPP_CALLBACK;\n', |
705 ID=constructor_callback_id, | 688 ID=constructor_callback_id, |
706 WEBKIT_INTERFACE_NAME=self._interface.id, | 689 WEBKIT_INTERFACE_NAME=self._interface.id, |
707 CPP_CALLBACK=constructor_callback_cpp_name) | 690 CPP_CALLBACK=constructor_callback_cpp_name) |
708 | 691 |
709 def GenerateCustomFactory(self, constructor_info): | 692 def GenerateCustomFactory(self, constructor_info): |
710 if 'CustomConstructor' not in self._interface.ext_attrs: | 693 if 'CustomConstructor' not in self._interface.ext_attrs: |
(...skipping 22 matching lines...) Expand all Loading... |
733 | 716 |
734 return True | 717 return True |
735 | 718 |
736 def IsConstructorArgumentOptional(self, argument): | 719 def IsConstructorArgumentOptional(self, argument): |
737 return False | 720 return False |
738 | 721 |
739 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): | 722 def EmitStaticFactoryOverload(self, constructor_info, name, arguments): |
740 constructor_callback_cpp_name = name + 'constructorCallback' | 723 constructor_callback_cpp_name = name + 'constructorCallback' |
741 self._EmitConstructorInfrastructure( | 724 self._EmitConstructorInfrastructure( |
742 constructor_info, name, 'constructorCallback', name, arguments, | 725 constructor_info, name, 'constructorCallback', name, arguments, |
743 emit_to_native=self._dart_use_blink, | 726 emit_to_native=True, |
744 is_custom=False) | 727 is_custom=False) |
745 | 728 |
746 ext_attrs = self._interface.ext_attrs | 729 ext_attrs = self._interface.ext_attrs |
747 | 730 |
748 create_function = 'create' | 731 create_function = 'create' |
749 if 'NamedConstructor' in ext_attrs: | 732 if 'NamedConstructor' in ext_attrs: |
750 create_function = 'createForJSConstructor' | 733 create_function = 'createForJSConstructor' |
751 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 734 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
752 self._GenerateNativeCallback( | 735 self._GenerateNativeCallback( |
753 constructor_callback_cpp_name, | 736 constructor_callback_cpp_name, |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 # and | 1058 # and |
1076 # | 1059 # |
1077 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 1060 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
1078 # | 1061 # |
1079 dart_element_type = self._DartType(element_type) | 1062 dart_element_type = self._DartType(element_type) |
1080 if self._HasNativeIndexGetter(): | 1063 if self._HasNativeIndexGetter(): |
1081 self._EmitNativeIndexGetter(dart_element_type) | 1064 self._EmitNativeIndexGetter(dart_element_type) |
1082 elif self._HasExplicitIndexedGetter(): | 1065 elif self._HasExplicitIndexedGetter(): |
1083 self._EmitExplicitIndexedGetter(dart_element_type) | 1066 self._EmitExplicitIndexedGetter(dart_element_type) |
1084 else: | 1067 else: |
1085 if self._dart_use_blink: | 1068 is_custom = any((op.id == 'item' and 'Custom' in op.ext_attrs) for op in s
elf._interface.operations) |
1086 is_custom = any((op.id == 'item' and 'Custom' in op.ext_attrs) for op
in self._interface.operations) | 1069 dart_native_name = \ |
1087 dart_native_name = \ | 1070 self.DeriveNativeName("NativeIndexed", "Getter") |
1088 self.DeriveNativeName("NativeIndexed", "Getter") | 1071 # First emit a toplevel function to do the native call |
1089 # First emit a toplevel function to do the native call | 1072 # Calls to this are emitted elsewhere, |
1090 # Calls to this are emitted elsewhere, | 1073 resolver_string = \ |
| 1074 DeriveResolverString(self._interface.id, "item", "Callback", |
| 1075 ["unsigned long"], self._database, is_custom) |
| 1076 if resolver_string in _cpp_resolver_string_map: |
1091 resolver_string = \ | 1077 resolver_string = \ |
1092 DeriveResolverString(self._interface.id, "item", "Callback", | 1078 _cpp_resolver_string_map[resolver_string] |
1093 ["unsigned long"], self._database, is_custom) | 1079 self._native_class_emitter.Emit( |
1094 if resolver_string in _cpp_resolver_string_map: | 1080 '\n' |
1095 resolver_string = \ | 1081 ' static $(DART_NATIVE_NAME)(mthis, index) ' |
1096 _cpp_resolver_string_map[resolver_string] | 1082 'native "$(RESOLVER_STRING)";\n', |
1097 self._native_class_emitter.Emit( | 1083 DART_NATIVE_NAME = dart_native_name, |
1098 '\n' | 1084 RESOLVER_STRING=resolver_string) |
1099 ' static $(DART_NATIVE_NAME)(mthis, index) ' | |
1100 'native "$(RESOLVER_STRING)";\n', | |
1101 DART_NATIVE_NAME = dart_native_name, | |
1102 RESOLVER_STRING=resolver_string) | |
1103 | 1085 |
1104 # Emit the method which calls the toplevel function, along with | 1086 # Emit the method which calls the toplevel function, along with |
1105 # the [] operator. | 1087 # the [] operator. |
1106 dart_qualified_name = \ | 1088 dart_qualified_name = \ |
1107 self.DeriveQualifiedBlinkName(self._interface.id, | 1089 self.DeriveQualifiedBlinkName(self._interface.id, |
1108 dart_native_name) | 1090 dart_native_name) |
1109 self._members_emitter.Emit( | 1091 self._members_emitter.Emit( |
1110 '\n' | 1092 '\n' |
1111 ' $TYPE operator[](int index) {\n' | 1093 ' $TYPE operator[](int index) {\n' |
1112 ' if (index < 0 || index >= length)\n' | 1094 ' if (index < 0 || index >= length)\n' |
1113 ' throw new RangeError.range(index, 0, length);\n' | 1095 ' throw new RangeError.range(index, 0, length);\n' |
1114 ' return $(DART_NATIVE_NAME)(this, index);\n' | 1096 ' return $(DART_NATIVE_NAME)(this, index);\n' |
1115 ' }\n\n' | 1097 ' }\n\n' |
1116 ' $TYPE _nativeIndexedGetter(int index) =>' | 1098 ' $TYPE _nativeIndexedGetter(int index) =>' |
1117 ' $(DART_NATIVE_NAME)(this, index);\n', | 1099 ' $(DART_NATIVE_NAME)(this, index);\n', |
1118 DART_NATIVE_NAME=dart_qualified_name, | 1100 DART_NATIVE_NAME=dart_qualified_name, |
1119 TYPE=self.SecureOutputType(element_type), | 1101 TYPE=self.SecureOutputType(element_type), |
1120 INTERFACE=self._interface.id) | 1102 INTERFACE=self._interface.id) |
1121 else: | |
1122 # Emit the method which calls the toplevel function, along with | |
1123 # the [] operator. | |
1124 self._members_emitter.Emit( | |
1125 '\n' | |
1126 ' $TYPE operator[](int index) {\n' | |
1127 ' if (index < 0 || index >= length)\n' | |
1128 ' throw new RangeError.range(index, 0, length);\n' | |
1129 ' return _nativeIndexedGetter(index);\n' | |
1130 ' }\n' | |
1131 ' $TYPE _nativeIndexedGetter(int index)' | |
1132 ' native "$(INTERFACE)_item_Callback";\n', | |
1133 TYPE=self.SecureOutputType(element_type), | |
1134 INTERFACE=self._interface.id) | |
1135 | 1103 |
1136 if self._HasNativeIndexSetter(): | 1104 if self._HasNativeIndexSetter(): |
1137 self._EmitNativeIndexSetter(dart_element_type) | 1105 self._EmitNativeIndexSetter(dart_element_type) |
1138 else: | 1106 else: |
1139 self._members_emitter.Emit( | 1107 self._members_emitter.Emit( |
1140 '\n' | 1108 '\n' |
1141 ' void operator[]=(int index, $TYPE value) {\n' | 1109 ' void operator[]=(int index, $TYPE value) {\n' |
1142 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' | 1110 ' throw new UnsupportedError("Cannot assign element of immutable Li
st.");\n' |
1143 ' }\n', | 1111 ' }\n', |
1144 TYPE=dart_element_type) | 1112 TYPE=dart_element_type) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) | 1187 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar
gument) for argument in operation.arguments) |
1220 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) | 1188 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option
al_arguments) |
1221 | 1189 |
1222 if info.callback_args: | 1190 if info.callback_args: |
1223 self._AddFutureifiedOperation(info, html_name) | 1191 self._AddFutureifiedOperation(info, html_name) |
1224 elif not needs_dispatcher: | 1192 elif not needs_dispatcher: |
1225 # Bind directly to native implementation | 1193 # Bind directly to native implementation |
1226 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) | 1194 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) |
1227 native_suffix = 'Callback' | 1195 native_suffix = 'Callback' |
1228 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) | 1196 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix) |
1229 if self._dart_use_blink: | 1197 type_ids = [argument.type.id |
1230 type_ids = [argument.type.id | 1198 for argument in operation.arguments[:len(info.param_infos)]] |
1231 for argument in operation.arguments[:len(info.param_infos)
]] | 1199 resolver_string = \ |
1232 resolver_string = \ | 1200 DeriveResolverString(self._interface.id, operation.id, |
1233 DeriveResolverString(self._interface.id, operation.id, | 1201 native_suffix, type_ids, self._database, is_custo
m) |
1234 native_suffix, type_ids, self._database, is_c
ustom) | |
1235 else: | |
1236 resolver_string = None | |
1237 cpp_callback_name = self._GenerateNativeBinding( | 1202 cpp_callback_name = self._GenerateNativeBinding( |
1238 info.name, argument_count, dart_declaration, | 1203 info.name, argument_count, dart_declaration, |
1239 info.IsStatic(), return_type, parameters, | 1204 info.IsStatic(), return_type, parameters, |
1240 native_suffix, is_custom, auto_scope_setup, | 1205 native_suffix, is_custom, auto_scope_setup, |
1241 resolver_string=resolver_string) | 1206 resolver_string=resolver_string) |
1242 if not is_custom: | 1207 if not is_custom: |
1243 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) | 1208 self._GenerateOperationNativeCallback(operation, operation.arguments, cp
p_callback_name, auto_scope_setup) |
1244 else: | 1209 else: |
1245 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) | 1210 self._GenerateDispatcher(info, info.operations, dart_declaration, html_nam
e) |
1246 | 1211 |
1247 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): | 1212 def _GenerateDispatcher(self, info, operations, dart_declaration, html_name): |
1248 | 1213 |
1249 def GenerateCall( | 1214 def GenerateCall( |
1250 stmts_emitter, call_emitter, version, operation, argument_count): | 1215 stmts_emitter, call_emitter, version, operation, argument_count): |
1251 native_suffix = 'Callback' | 1216 native_suffix = 'Callback' |
1252 actuals = info.ParametersAsListOfVariables(argument_count) | 1217 actuals = info.ParametersAsListOfVariables(argument_count) |
1253 actuals_s = ", ".join(actuals) | 1218 actuals_s = ", ".join(actuals) |
1254 formals=actuals | 1219 formals=actuals |
1255 return_type = self.SecureOutputType(operation.type.id) | 1220 return_type = self.SecureOutputType(operation.type.id) |
1256 native_suffix = 'Callback' | 1221 native_suffix = 'Callback' |
1257 is_custom = 'Custom' in operation.ext_attrs | 1222 is_custom = 'Custom' in operation.ext_attrs |
1258 if self._dart_use_blink: | 1223 base_name = '_%s_%s' % (operation.id, version) |
1259 base_name = '_%s_%s' % (operation.id, version) | 1224 overload_base_name = \ |
1260 overload_base_name = \ | 1225 self.DeriveNativeName(base_name, native_suffix) |
1261 self.DeriveNativeName(base_name, native_suffix) | 1226 overload_name = \ |
1262 overload_name = \ | 1227 self.DeriveQualifiedBlinkName(self._interface.id, |
1263 self.DeriveQualifiedBlinkName(self._interface.id, | 1228 overload_base_name) |
1264 overload_base_name) | 1229 static = True |
1265 static = True | 1230 if not operation.is_static: |
1266 if not operation.is_static: | 1231 actuals = ['this'] + actuals |
1267 actuals = ['this'] + actuals | 1232 formals = ['mthis'] + formals |
1268 formals = ['mthis'] + formals | 1233 actuals_s = ", ".join(actuals) |
1269 actuals_s = ", ".join(actuals) | 1234 formals_s = ", ".join(formals) |
1270 formals_s = ", ".join(formals) | 1235 dart_declaration = '%s(%s)' % ( |
1271 dart_declaration = '%s(%s)' % ( | 1236 base_name, formals_s) |
1272 base_name, formals_s) | 1237 type_ids = [argument.type.id |
1273 type_ids = [argument.type.id | 1238 for argument in operation.arguments[:argument_count]] |
1274 for argument in operation.arguments[:argument_count]] | 1239 resolver_string = \ |
1275 resolver_string = \ | 1240 DeriveResolverString(self._interface.id, operation.id, |
1276 DeriveResolverString(self._interface.id, operation.id, | 1241 native_suffix, type_ids, self._database, is_custo
m) |
1277 native_suffix, type_ids, self._database, is_c
ustom) | |
1278 else: | |
1279 base_name = '_%s_%s' % (operation.id, version) | |
1280 overload_name = base_name | |
1281 static = operation.is_static | |
1282 dart_declaration = '%s%s %s(%s)' % ( | |
1283 'static ' if static else '', | |
1284 return_type, | |
1285 overload_name, actuals_s) | |
1286 resolver_string = None | |
1287 | 1242 |
1288 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) | 1243 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=actuals_s) |
1289 auto_scope_setup = \ | 1244 auto_scope_setup = \ |
1290 self._GenerateAutoSetupScope(base_name, native_suffix) | 1245 self._GenerateAutoSetupScope(base_name, native_suffix) |
1291 cpp_callback_name = self._GenerateNativeBinding( | 1246 cpp_callback_name = self._GenerateNativeBinding( |
1292 base_name, (0 if static else 1) + argument_count, | 1247 base_name, (0 if static else 1) + argument_count, |
1293 dart_declaration, static, return_type, formals, | 1248 dart_declaration, static, return_type, formals, |
1294 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, | 1249 native_suffix, is_custom, auto_scope_setup, emit_metadata=False, |
1295 emit_to_native=self._dart_use_blink, resolver_string=resolver_string) | 1250 emit_to_native=True, resolver_string=resolver_string) |
1296 if not is_custom: | 1251 if not is_custom: |
1297 self._GenerateOperationNativeCallback(operation, | 1252 self._GenerateOperationNativeCallback(operation, |
1298 operation.arguments[:argument_count], cpp_callback_name, | 1253 operation.arguments[:argument_count], cpp_callback_name, |
1299 auto_scope_setup) | 1254 auto_scope_setup) |
1300 | 1255 |
1301 | 1256 |
1302 self._GenerateDispatcherBody( | 1257 self._GenerateDispatcherBody( |
1303 info, | 1258 info, |
1304 operations, | 1259 operations, |
1305 dart_declaration, | 1260 dart_declaration, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 | 1442 |
1488 body_emitter.Emit( | 1443 body_emitter.Emit( |
1489 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' | 1444 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIsol
ate();\n' |
1490 ' if (!domWindow) {\n' | 1445 ' if (!domWindow) {\n' |
1491 ' exception = Dart_NewStringFromCString("Failed to fetch do
mWindow");\n' | 1446 ' exception = Dart_NewStringFromCString("Failed to fetch do
mWindow");\n' |
1492 ' goto fail;\n' | 1447 ' goto fail;\n' |
1493 ' }\n' | 1448 ' }\n' |
1494 ' Document& document = *domWindow->document();\n') | 1449 ' Document& document = *domWindow->document();\n') |
1495 | 1450 |
1496 if needs_receiver: | 1451 if needs_receiver: |
1497 if self._dart_use_blink: | 1452 body_emitter.Emit( |
1498 body_emitter.Emit( | 1453 ' $WEBCORE_CLASS_NAME* receiver = ' |
1499 ' $WEBCORE_CLASS_NAME* receiver = ' | 1454 'DartDOMWrapper::receiverChecked<Dart$INTERFACE>(args, exception);\n' |
1500 'DartDOMWrapper::receiverChecked<Dart$INTERFACE>(args, exception);\n
' | 1455 ' if (exception)\n' |
1501 ' if (exception)\n' | 1456 ' goto fail;\n', |
1502 ' goto fail;\n', | 1457 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
1503 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 1458 INTERFACE=self._interface.id) |
1504 INTERFACE=self._interface.id) | |
1505 else: | |
1506 body_emitter.Emit( | |
1507 ' $WEBCORE_CLASS_NAME* receiver = ' | |
1508 'DartDOMWrapper::receiver< $WEBCORE_CLASS_NAME >(args);\n' | |
1509 ' if (exception)\n' | |
1510 ' goto fail;\n', | |
1511 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) | |
1512 | 1459 |
1513 if requires_stack_info: | 1460 if requires_stack_info: |
1514 self._cpp_impl_includes.add('"ScriptArguments.h"') | 1461 self._cpp_impl_includes.add('"ScriptArguments.h"') |
1515 body_emitter.Emit( | 1462 body_emitter.Emit( |
1516 '\n' | 1463 '\n' |
1517 ' ScriptState* currentState = DartUtilities::currentScriptState
();\n' | 1464 ' ScriptState* currentState = DartUtilities::currentScriptState
();\n' |
1518 ' if (!currentState) {\n' | 1465 ' if (!currentState) {\n' |
1519 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' | 1466 ' exception = Dart_NewStringFromCString("Failed to retrieve
a script state");\n' |
1520 ' goto fail;\n' | 1467 ' goto fail;\n' |
1521 ' }\n' | 1468 ' }\n' |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 metadata = self._metadata.GetFormattedMetadata( | 1652 metadata = self._metadata.GetFormattedMetadata( |
1706 self._renamer.GetLibraryName(self._interface), | 1653 self._renamer.GetLibraryName(self._interface), |
1707 self._interface, idl_name, ' ') | 1654 self._interface, idl_name, ' ') |
1708 dart_native_name = \ | 1655 dart_native_name = \ |
1709 self.DeriveNativeName(idl_name, native_suffix) | 1656 self.DeriveNativeName(idl_name, native_suffix) |
1710 | 1657 |
1711 if (resolver_string): | 1658 if (resolver_string): |
1712 native_binding = resolver_string | 1659 native_binding = resolver_string |
1713 else: | 1660 else: |
1714 native_binding_id = self._interface.id | 1661 native_binding_id = self._interface.id |
1715 if self._dart_use_blink: | 1662 native_binding_id = TypeIdToBlinkName(native_binding_id, self._database) |
1716 native_binding_id = TypeIdToBlinkName(native_binding_id, self._databas
e) | |
1717 native_binding = \ | 1663 native_binding = \ |
1718 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) | 1664 '%s_%s_%s' % (native_binding_id, idl_name, native_suffix) |
1719 | 1665 |
1720 if self._dart_use_blink: | 1666 if not static: |
1721 if not static: | 1667 formals = ", ".join(['mthis'] + parameters) |
1722 formals = ", ".join(['mthis'] + parameters) | 1668 actuals = ", ".join(['this'] + parameters) |
1723 actuals = ", ".join(['this'] + parameters) | 1669 else: |
1724 else: | 1670 formals = ", ".join(parameters) |
1725 formals = ", ".join(parameters) | 1671 actuals = ", ".join(parameters) |
1726 actuals = ", ".join(parameters) | 1672 if native_binding in _cpp_resolver_string_map: |
1727 if native_binding in _cpp_resolver_string_map: | 1673 native_binding = \ |
1728 native_binding = \ | 1674 _cpp_resolver_string_map[native_binding] |
1729 _cpp_resolver_string_map[native_binding] | 1675 self._native_class_emitter.Emit( |
1730 self._native_class_emitter.Emit( | 1676 '\n' |
| 1677 ' static $DART_NAME($FORMALS) native "$NATIVE_BINDING";\n', |
| 1678 DART_NAME=dart_native_name, |
| 1679 FORMALS=formals, |
| 1680 NATIVE_BINDING=native_binding) |
| 1681 |
| 1682 if not emit_to_native: |
| 1683 caller_emitter = self._members_emitter |
| 1684 full_dart_name = \ |
| 1685 self.DeriveQualifiedBlinkName(self._interface.id, |
| 1686 dart_native_name) |
| 1687 caller_emitter.Emit( |
1731 '\n' | 1688 '\n' |
1732 ' static $DART_NAME($FORMALS) native "$NATIVE_BINDING";\n', | 1689 ' $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);\n', |
1733 DART_NAME=dart_native_name, | |
1734 FORMALS=formals, | |
1735 NATIVE_BINDING=native_binding) | |
1736 | |
1737 if not emit_to_native: | |
1738 caller_emitter = self._members_emitter | |
1739 full_dart_name = \ | |
1740 self.DeriveQualifiedBlinkName(self._interface.id, | |
1741 dart_native_name) | |
1742 caller_emitter.Emit( | |
1743 '\n' | |
1744 ' $METADATA$DART_DECLARATION => $DART_NAME($ACTUALS);\n', | |
1745 METADATA=metadata, | |
1746 DART_DECLARATION=dart_declaration, | |
1747 DART_NAME=full_dart_name, | |
1748 ACTUALS=actuals) | |
1749 else: | |
1750 self._members_emitter.Emit( | |
1751 '\n' | |
1752 ' $METADATA$DART_DECLARATION native "$NATIVE_BINDING";\n', | |
1753 METADATA=metadata, | 1690 METADATA=metadata, |
1754 DART_DECLARATION=dart_declaration, | 1691 DART_DECLARATION=dart_declaration, |
1755 NATIVE_BINDING=native_binding) | 1692 DART_NAME=full_dart_name, |
| 1693 ACTUALS=actuals) |
1756 cpp_callback_name = '%s%s' % (idl_name, native_suffix) | 1694 cpp_callback_name = '%s%s' % (idl_name, native_suffix) |
1757 | 1695 |
1758 self._cpp_resolver_emitter.Emit( | 1696 self._cpp_resolver_emitter.Emit( |
1759 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' | 1697 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' |
1760 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' | 1698 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' |
1761 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' | 1699 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' |
1762 ' }\n', | 1700 ' }\n', |
1763 ARGC=argument_count, | 1701 ARGC=argument_count, |
1764 NATIVE_BINDING=native_binding, | 1702 NATIVE_BINDING=native_binding, |
1765 INTERFACE_NAME=self._interface.id, | 1703 INTERFACE_NAME=self._interface.id, |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 e.Emit("};\n"); | 1952 e.Emit("};\n"); |
2015 e.Emit('\n'); | 1953 e.Emit('\n'); |
2016 e.Emit('} // namespace WebCore\n'); | 1954 e.Emit('} // namespace WebCore\n'); |
2017 | 1955 |
2018 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1956 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
2019 return ( | 1957 return ( |
2020 interface.id.endswith('Event') and | 1958 interface.id.endswith('Event') and |
2021 operation.id.startswith('init') and | 1959 operation.id.startswith('init') and |
2022 argument.ext_attrs.get('Default') == 'Undefined' and | 1960 argument.ext_attrs.get('Default') == 'Undefined' and |
2023 argument.type.id == 'DOMString') | 1961 argument.type.id == 'DOMString') |
OLD | NEW |