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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', | 82 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource', |
83 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', | 83 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', |
84 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', | 84 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', |
85 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', | 85 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', |
86 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource', | 86 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource', |
87 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream', | 87 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream', |
88 } | 88 } |
89 | 89 |
90 _cpp_partial_map = {} | 90 _cpp_partial_map = {} |
91 | 91 |
| 92 _cpp_no_auto_scope_list = set([ |
| 93 ('Node', 'firstChild', 'Getter'), |
| 94 ('Node', 'lastChild', 'Getter'), |
| 95 ('Node', 'nextSibling', 'Getter'), |
| 96 ('Node', 'previousSibling', 'Getter'), |
| 97 ('Node', 'childNodes', 'Getter'), |
| 98 ('NodeList', 'length', 'Getter'), |
| 99 ('NodeList', 'item', 'Callback'), |
| 100 ('Document', 'body', 'Getter'), |
| 101 ]) |
| 102 |
92 def _GetCPPPartialNames(interface): | 103 def _GetCPPPartialNames(interface): |
93 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) | 104 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id) |
94 if not _cpp_partial_map: | 105 if not _cpp_partial_map: |
95 for (type, member) in _cpp_callback_map.keys(): | 106 for (type, member) in _cpp_callback_map.keys(): |
96 if type not in _cpp_partial_map: | 107 if type not in _cpp_partial_map: |
97 _cpp_partial_map[type] = set([]) | 108 _cpp_partial_map[type] = set([]) |
98 | 109 |
99 name_with_path = _cpp_callback_map[(type, member)] | 110 name_with_path = _cpp_callback_map[(type, member)] |
100 if name_with_path in _cpp_import_map: | 111 if name_with_path in _cpp_import_map: |
101 name_with_path = _cpp_import_map[name_with_path] | 112 name_with_path = _cpp_import_map[name_with_path] |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 ' static void returnToDart(Dart_NativeArguments args,\n' | 442 ' static void returnToDart(Dart_NativeArguments args,\n' |
432 ' NativeType* value)\n' | 443 ' NativeType* value)\n' |
433 ' {\n' | 444 ' {\n' |
434 ' if (value) {\n' | 445 ' if (value) {\n' |
435 ' DartDOMData* domData = static_cast<DartDOMData*>(\n' | 446 ' DartDOMData* domData = static_cast<DartDOMData*>(\n' |
436 ' Dart_GetNativeIsolateData(args));\n' | 447 ' Dart_GetNativeIsolateData(args));\n' |
437 ' Dart_WeakPersistentHandle result =\n' | 448 ' Dart_WeakPersistentHandle result =\n' |
438 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData
, value);\n' | 449 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData
, value);\n' |
439 ' if (result)\n' | 450 ' if (result)\n' |
440 ' Dart_SetWeakHandleReturnValue(args, result);\n' | 451 ' Dart_SetWeakHandleReturnValue(args, result);\n' |
441 ' else\n' | 452 ' else {\n' |
| 453 ' DartApiScope apiScope();\n' |
442 ' Dart_SetReturnValue(args, createWrapper(domData, value)
);\n' | 454 ' Dart_SetReturnValue(args, createWrapper(domData, value)
);\n' |
| 455 ' }\n' |
443 ' }\n' | 456 ' }\n' |
444 ' }\n', | 457 ' }\n', |
445 INTERFACE=self._interface.id) | 458 INTERFACE=self._interface.id) |
446 | 459 |
447 if ('CustomToV8' in ext_attrs or | 460 if ('CustomToV8' in ext_attrs or |
448 'PureInterface' in ext_attrs or | 461 'PureInterface' in ext_attrs or |
449 'CPPPureInterface' in ext_attrs or | 462 'CPPPureInterface' in ext_attrs or |
450 self._interface_type_info.custom_to_dart()): | 463 self._interface_type_info.custom_to_dart()): |
451 to_dart_emitter.Emit( | 464 to_dart_emitter.Emit( |
452 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType
* value);\n') | 465 ' static Dart_Handle createWrapper(DartDOMData* domData, NativeType
* value);\n') |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 value_expression, | 1066 value_expression, |
1054 self._interface.id, | 1067 self._interface.id, |
1055 ext_attrs) | 1068 ext_attrs) |
1056 set_return_value = '%s' % (return_to_dart_conversion) | 1069 set_return_value = '%s' % (return_to_dart_conversion) |
1057 invocation_emitter.Emit( | 1070 invocation_emitter.Emit( |
1058 ' $RETURN_VALUE;\n', | 1071 ' $RETURN_VALUE;\n', |
1059 RETURN_VALUE=set_return_value) | 1072 RETURN_VALUE=set_return_value) |
1060 | 1073 |
1061 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, | 1074 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, |
1062 native_suffix, is_custom, emit_metadata=True): | 1075 native_suffix, is_custom, emit_metadata=True): |
| 1076 |
| 1077 def _GenerateAutoSetupScope(self, idl_name, native_suffix): |
| 1078 if ((self._interface.id, idl_name, native_suffix) not in _cpp_no_auto_scop
e_list): |
| 1079 return 'true' |
| 1080 return 'false' |
| 1081 |
1063 metadata = [] | 1082 metadata = [] |
1064 if emit_metadata: | 1083 if emit_metadata: |
1065 metadata = self._metadata.GetFormattedMetadata( | 1084 metadata = self._metadata.GetFormattedMetadata( |
1066 self._renamer.GetLibraryName(self._interface), | 1085 self._renamer.GetLibraryName(self._interface), |
1067 self._interface, idl_name, ' ') | 1086 self._interface, idl_name, ' ') |
1068 | 1087 |
1069 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) | 1088 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) |
1070 self._members_emitter.Emit( | 1089 self._members_emitter.Emit( |
1071 '\n' | 1090 '\n' |
1072 ' $METADATA$DART_DECLARATION native "$NATIVE_BINDING";\n', | 1091 ' $METADATA$DART_DECLARATION native "$NATIVE_BINDING";\n', |
1073 DOMINTERFACE=self._interface.id, | 1092 DOMINTERFACE=self._interface.id, |
1074 METADATA=metadata, | 1093 METADATA=metadata, |
1075 DART_DECLARATION=dart_declaration, | 1094 DART_DECLARATION=dart_declaration, |
1076 NATIVE_BINDING=native_binding) | 1095 NATIVE_BINDING=native_binding) |
1077 | 1096 |
1078 cpp_callback_name = '%s%s' % (idl_name, native_suffix) | 1097 cpp_callback_name = '%s%s' % (idl_name, native_suffix) |
| 1098 auto_scope_setup = _GenerateAutoSetupScope(self, idl_name, native_suffix) |
1079 | 1099 |
1080 self._cpp_resolver_emitter.Emit( | 1100 self._cpp_resolver_emitter.Emit( |
1081 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' | 1101 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' |
1082 ' *autoSetupScope = true;\n' | 1102 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' |
1083 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' | 1103 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' |
1084 ' }\n', | 1104 ' }\n', |
1085 ARGC=argument_count, | 1105 ARGC=argument_count, |
1086 NATIVE_BINDING=native_binding, | 1106 NATIVE_BINDING=native_binding, |
1087 INTERFACE_NAME=self._interface.id, | 1107 INTERFACE_NAME=self._interface.id, |
| 1108 AUTO_SCOPE_SETUP=auto_scope_setup, |
1088 CPP_CALLBACK_NAME=cpp_callback_name) | 1109 CPP_CALLBACK_NAME=cpp_callback_name) |
1089 | 1110 |
1090 if is_custom: | 1111 if is_custom: |
1091 self._cpp_declarations_emitter.Emit( | 1112 self._cpp_declarations_emitter.Emit( |
1092 '\n' | 1113 '\n' |
1093 'void $CPP_CALLBACK_NAME(Dart_NativeArguments);\n', | 1114 'void $CPP_CALLBACK_NAME(Dart_NativeArguments);\n', |
1094 CPP_CALLBACK_NAME=cpp_callback_name) | 1115 CPP_CALLBACK_NAME=cpp_callback_name) |
1095 | 1116 |
1096 return cpp_callback_name | 1117 return cpp_callback_name |
1097 | 1118 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 e.Emit("};\n"); | 1302 e.Emit("};\n"); |
1282 e.Emit('\n'); | 1303 e.Emit('\n'); |
1283 e.Emit('} // namespace WebCore\n'); | 1304 e.Emit('} // namespace WebCore\n'); |
1284 | 1305 |
1285 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): | 1306 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): |
1286 return ( | 1307 return ( |
1287 interface.id.endswith('Event') and | 1308 interface.id.endswith('Event') and |
1288 operation.id.startswith('init') and | 1309 operation.id.startswith('init') and |
1289 argument.ext_attrs.get('Default') == 'Undefined' and | 1310 argument.ext_attrs.get('Default') == 'Undefined' and |
1290 argument.type.id == 'DOMString') | 1311 argument.type.id == 'DOMString') |
OLD | NEW |