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

Side by Side Diff: client/dom/scripts/dartgenerator.py

Issue 9418008: Update DOM scripts after recent webkit merge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « client/dom/idl/dart/dart.idl ('k') | client/dom/scripts/databasebuilder.py » ('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 generates Dart APIs from the IDL database.""" 6 """This module generates Dart APIs from the IDL database."""
7 7
8 import emitter 8 import emitter
9 import idlnode 9 import idlnode
10 import logging 10 import logging
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 ' bool isEmpty() {\n' 1762 ' bool isEmpty() {\n'
1763 ' return length == 0;\n' 1763 ' return length == 0;\n'
1764 ' }\n' 1764 ' }\n'
1765 '\n' 1765 '\n'
1766 ' Iterator<$TYPE> iterator() {\n' 1766 ' Iterator<$TYPE> iterator() {\n'
1767 ' return new _FixedSizeListIterator<$TYPE>(this);\n' 1767 ' return new _FixedSizeListIterator<$TYPE>(this);\n'
1768 ' }\n', 1768 ' }\n',
1769 TYPE=element_type) 1769 TYPE=element_type)
1770 1770
1771 def _HasNativeIndexGetter(self, interface): 1771 def _HasNativeIndexGetter(self, interface):
1772 return ('HasIndexGetter' in interface.ext_attrs or 1772 return ('IndexedGetter' in interface.ext_attrs or
1773 'HasNumericIndexGetter' in interface.ext_attrs) 1773 'NumericIndexedGetter' in interface.ext_attrs)
1774 1774
1775 def _EmitNativeIndexGetter(self, interface, element_type): 1775 def _EmitNativeIndexGetter(self, interface, element_type):
1776 method_name = '_index' 1776 method_name = '_index'
1777 self._members_emitter.Emit( 1777 self._members_emitter.Emit(
1778 '\n' 1778 '\n'
1779 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n' 1779 ' $TYPE operator[](int index) { return $METHOD(this, index); }\n'
1780 ' static $TYPE $METHOD(var _this, int index) native;\n', 1780 ' static $TYPE $METHOD(var _this, int index) native;\n',
1781 TYPE=element_type, METHOD=method_name) 1781 TYPE=element_type, METHOD=method_name)
1782 1782
1783 def _HasNativeIndexSetter(self, interface): 1783 def _HasNativeIndexSetter(self, interface):
1784 return 'HasCustomIndexSetter' in interface.ext_attrs 1784 return 'CustomIndexedSetter' in interface.ext_attrs
1785 1785
1786 def _EmitNativeIndexSetter(self, interface, element_type): 1786 def _EmitNativeIndexSetter(self, interface, element_type):
1787 method_name = '_set_index' 1787 method_name = '_set_index'
1788 self._members_emitter.Emit( 1788 self._members_emitter.Emit(
1789 '\n' 1789 '\n'
1790 ' void operator[]=(int index, $TYPE value) {\n' 1790 ' void operator[]=(int index, $TYPE value) {\n'
1791 ' return $METHOD(this, index, value);\n' 1791 ' return $METHOD(this, index, value);\n'
1792 ' }\n' 1792 ' }\n'
1793 ' static $METHOD(_this, index, value) native;\n', 1793 ' static $METHOD(_this, index, value) native;\n',
1794 TYPE=element_type, METHOD=method_name) 1794 TYPE=element_type, METHOD=method_name)
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 # 2186 #
2187 # and 2187 # and
2188 # 2188 #
2189 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 2189 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
2190 # 2190 #
2191 self._members_emitter.Emit( 2191 self._members_emitter.Emit(
2192 '\n' 2192 '\n'
2193 ' $TYPE operator[](int index) native "return this[index];";\n', 2193 ' $TYPE operator[](int index) native "return this[index];";\n',
2194 TYPE=self._NarrowOutputType(element_type)) 2194 TYPE=self._NarrowOutputType(element_type))
2195 2195
2196 if 'HasCustomIndexSetter' in self._interface.ext_attrs: 2196 if 'CustomIndexedSetter' in self._interface.ext_attrs:
2197 self._members_emitter.Emit( 2197 self._members_emitter.Emit(
2198 '\n' 2198 '\n'
2199 ' void operator[]=(int index, $TYPE value) native "this[index] = valu e";\n', 2199 ' void operator[]=(int index, $TYPE value) native "this[index] = valu e";\n',
2200 TYPE=self._NarrowInputType(element_type)) 2200 TYPE=self._NarrowInputType(element_type))
2201 else: 2201 else:
2202 self._members_emitter.Emit( 2202 self._members_emitter.Emit(
2203 '\n' 2203 '\n'
2204 ' void operator[]=(int index, $TYPE value) {\n' 2204 ' void operator[]=(int index, $TYPE value) {\n'
2205 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 2205 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
2206 ' }\n', 2206 ' }\n',
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2738 RESOLVER=self._cpp_resolver_emitter.Fragments()) 2738 RESOLVER=self._cpp_resolver_emitter.Fragments())
2739 2739
2740 def _GenerateCppHeader(self): 2740 def _GenerateCppHeader(self):
2741 webcore_include = self._interface_type_info.webcore_include() 2741 webcore_include = self._interface_type_info.webcore_include()
2742 if webcore_include: 2742 if webcore_include:
2743 webcore_include = '#include "%s.h"\n' % webcore_include 2743 webcore_include = '#include "%s.h"\n' % webcore_include
2744 else: 2744 else:
2745 webcore_include = '' 2745 webcore_include = ''
2746 2746
2747 if ('CustomToJS' in self._interface.ext_attrs or 2747 if ('CustomToJS' in self._interface.ext_attrs or
2748 'CustomToJSObject' in self._interface.ext_attrs or
2748 'PureInterface' in self._interface.ext_attrs or 2749 'PureInterface' in self._interface.ext_attrs or
2750 'CPPPureInterface' in self._interface.ext_attrs or
2749 self._interface_type_info.custom_to_dart()): 2751 self._interface_type_info.custom_to_dart()):
2750 to_dart_value_template = ( 2752 to_dart_value_template = (
2751 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') 2753 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n')
2752 else: 2754 else:
2753 to_dart_value_template = ( 2755 to_dart_value_template = (
2754 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' 2756 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n'
2755 '{\n' 2757 '{\n'
2756 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 2758 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
2757 '}\n') 2759 '}\n')
2758 to_dart_value_emitter = emitter.Emitter() 2760 to_dart_value_emitter = emitter.Emitter()
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 arguments.append(attr.id) 2859 arguments.append(attr.id)
2858 parameter_definitions_emitter = emitter.Emitter() 2860 parameter_definitions_emitter = emitter.Emitter()
2859 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0) 2861 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0)
2860 parameter_definitions = parameter_definitions_emitter.Fragments() 2862 parameter_definitions = parameter_definitions_emitter.Fragments()
2861 self._GenerateNativeCallback(cpp_callback_name, attr, parameter_definitions, 2863 self._GenerateNativeCallback(cpp_callback_name, attr, parameter_definitions,
2862 webcore_function_name, arguments, idl_return_type=None, 2864 webcore_function_name, arguments, idl_return_type=None,
2863 raises_dart_exceptions=True, 2865 raises_dart_exceptions=True,
2864 raises_dom_exceptions=attr.set_raises) 2866 raises_dom_exceptions=attr.set_raises)
2865 2867
2866 def _HasNativeIndexGetter(self, interface): 2868 def _HasNativeIndexGetter(self, interface):
2867 return ('HasCustomIndexGetter' in interface.ext_attrs or 2869 return ('CustomIndexedGetter' in interface.ext_attrs or
2868 'HasNumericIndexGetter' in interface.ext_attrs) 2870 'NumericIndexedGetter' in interface.ext_attrs)
2869 2871
2870 def _EmitNativeIndexGetter(self, interface, element_type): 2872 def _EmitNativeIndexGetter(self, interface, element_type):
2871 dart_declaration = '%s operator[](int index)' % element_type 2873 dart_declaration = '%s operator[](int index)' % element_type
2872 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, 2874 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration,
2873 'Callback', True) 2875 'Callback', True)
2874 2876
2875 def _EmitNativeIndexSetter(self, interface, element_type): 2877 def _EmitNativeIndexSetter(self, interface, element_type):
2876 dart_declaration = 'void operator[]=(int index, %s value)' % element_type 2878 dart_declaration = 'void operator[]=(int index, %s value)' % element_type
2877 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, 2879 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration,
2878 'Callback', True) 2880 'Callback', True)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 argument_list) 2959 argument_list)
2958 is_custom = 'Custom' in operation.ext_attrs 2960 is_custom = 'Custom' in operation.ext_attrs
2959 cpp_callback_name = self._GenerateNativeBinding( 2961 cpp_callback_name = self._GenerateNativeBinding(
2960 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', 2962 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback',
2961 is_custom) 2963 is_custom)
2962 if is_custom: 2964 if is_custom:
2963 return 2965 return
2964 2966
2965 # Generate callback. 2967 # Generate callback.
2966 webcore_function_name = operation.id 2968 webcore_function_name = operation.id
2967 if 'ImplementationFunction' in operation.ext_attrs: 2969 if 'ImplementedAs' in operation.ext_attrs:
2968 webcore_function_name = operation.ext_attrs['ImplementationFunction'] 2970 webcore_function_name = operation.ext_attrs['ImplementedAs']
2969 2971
2970 parameter_definitions_emitter = emitter.Emitter() 2972 parameter_definitions_emitter = emitter.Emitter()
2971 raises_dart_exceptions = len(operation.arguments) > 0 or operation.raises 2973 raises_dart_exceptions = len(operation.arguments) > 0 or operation.raises
2972 arguments = [] 2974 arguments = []
2973 2975
2974 # Process 'CallWith' argument. 2976 # Process 'CallWith' argument.
2975 if ('CallWith' in operation.ext_attrs and 2977 if 'CallWith' in operation.ext_attrs:
2976 operation.ext_attrs['CallWith'] == 'ScriptExecutionContext'): 2978 call_with = operation.ext_attrs['CallWith']
2977 parameter_definitions_emitter.Emit( 2979 if call_with == 'ScriptExecutionContext':
2978 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n' 2980 parameter_definitions_emitter.Emit(
2979 ' if (!context)\n' 2981 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
2980 ' return;\n') 2982 ' if (!context)\n'
2981 arguments.append('context') 2983 ' return;\n')
2984 arguments.append('context')
2985 elif call_with == 'ScriptArguments|CallStack':
2986 raises_dart_exceptions = True
2987 self._cpp_impl_includes['ScriptArguments'] = 1
2988 self._cpp_impl_includes['ScriptCallStack'] = 1
2989 self._cpp_impl_includes['V8Proxy'] = 1
2990 self._cpp_impl_includes['v8'] = 1
2991 parameter_definitions_emitter.Emit(
2992 ' v8::HandleScope handleScope;\n'
2993 ' v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtil ities::domWindowForCurrentIsolate()->frame()));\n'
2994 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $ INDEX);\n'
2995 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::crea teScriptArguments(customArgument, exception));\n'
2996 ' if (!scriptArguments)\n'
2997 ' goto fail;\n'
2998 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::crea teScriptCallStack());\n'
2999 ' if (!scriptCallStack->size())\n'
3000 ' return;\n',
3001 INDEX=len(operation.arguments))
3002 arguments.extend(['scriptArguments', 'scriptCallStack'])
2982 3003
2983 # Process Dart arguments. 3004 # Process Dart arguments.
2984 for (i, argument) in enumerate(operation.arguments): 3005 for (i, argument) in enumerate(operation.arguments):
2985 if i == len(operation.arguments) - 1 and 'CustomArgumentHandling' in opera tion.ext_attrs: 3006 if i == len(operation.arguments) - 1 and self._interface.id == 'Console' a nd argument.id == 'arg':
2986 # FIXME: we are skipping last argument here because it was added in 3007 # FIXME: we are skipping last argument here because it was added in
2987 # supplemental dart.idl. Cleanup dart.idl and remove this check. 3008 # supplemental dart.idl. Cleanup dart.idl and remove this check.
2988 break 3009 break
2989 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i) 3010 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i)
2990 arguments.append(argument.id) 3011 arguments.append(argument.id)
2991 3012
2992 if operation.id in ['addEventListener', 'removeEventListener']: 3013 if operation.id in ['addEventListener', 'removeEventListener']:
2993 # addEventListener's and removeEventListener's last argument is marked 3014 # addEventListener's and removeEventListener's last argument is marked
2994 # as optional in idl, but is not optional in webcore implementation. 3015 # as optional in idl, but is not optional in webcore implementation.
2995 if len(operation.arguments) == 2: 3016 if len(operation.arguments) == 2:
2996 arguments.append('false') 3017 arguments.append('false')
2997 3018
2998 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': 3019 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty':
2999 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 3020 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
3000 # idl, but is not optional in webcore implementation. 3021 # idl, but is not optional in webcore implementation.
3001 if len(operation.arguments) == 2: 3022 if len(operation.arguments) == 2:
3002 arguments.append('String()') 3023 arguments.append('String()')
3003 3024
3004 # Process auxiliary arguments.
3005 if 'CustomArgumentHandling' in operation.ext_attrs:
3006 raises_dart_exceptions = True
3007 self._cpp_impl_includes['ScriptArguments'] = 1
3008 self._cpp_impl_includes['ScriptCallStack'] = 1
3009 self._cpp_impl_includes['V8Proxy'] = 1
3010 self._cpp_impl_includes['v8'] = 1
3011 parameter_definitions_emitter.Emit(
3012 ' v8::HandleScope handleScope;\n'
3013 ' v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtilit ies::domWindowForCurrentIsolate()->frame()));\n'
3014 ' Dart_Handle customArgument = Dart_GetNativeArgument(args, $IN DEX);\n'
3015 ' RefPtr<ScriptArguments> scriptArguments(DartUtilities::create ScriptArguments(customArgument, exception));\n'
3016 ' if (!scriptArguments)\n'
3017 ' goto fail;\n'
3018 ' RefPtr<ScriptCallStack> scriptCallStack(DartUtilities::create ScriptCallStack());\n'
3019 ' if (!scriptCallStack->size())\n'
3020 ' return;\n',
3021 INDEX=len(operation.arguments))
3022 arguments.extend(['scriptArguments', 'scriptCallStack'])
3023
3024 if 'NeedsUserGestureCheck' in operation.ext_attrs: 3025 if 'NeedsUserGestureCheck' in operation.ext_attrs:
3025 arguments.extend('DartUtilities::processingUserGesture') 3026 arguments.extend('DartUtilities::processingUserGesture')
3026 3027
3027 parameter_definitions = parameter_definitions_emitter.Fragments() 3028 parameter_definitions = parameter_definitions_emitter.Fragments()
3028 self._GenerateNativeCallback(cpp_callback_name, operation, 3029 self._GenerateNativeCallback(cpp_callback_name, operation,
3029 parameter_definitions, webcore_function_name, arguments, 3030 parameter_definitions, webcore_function_name, arguments,
3030 idl_return_type=operation.type, 3031 idl_return_type=operation.type,
3031 raises_dart_exceptions=raises_dart_exceptions, 3032 raises_dart_exceptions=raises_dart_exceptions,
3032 raises_dom_exceptions=operation.raises) 3033 raises_dom_exceptions=operation.raises)
3033 3034
(...skipping 22 matching lines...) Expand all
3056 elif return_type_info.idl_type() in svg_primitive_types: 3057 elif return_type_info.idl_type() in svg_primitive_types:
3057 conversion_cast = '%s::create($BODY)' 3058 conversion_cast = '%s::create($BODY)'
3058 else: 3059 else:
3059 conversion_cast = 'static_cast<%s*>($BODY)' 3060 conversion_cast = 'static_cast<%s*>($BODY)'
3060 conversion_cast = conversion_cast % return_type_info.native_type() 3061 conversion_cast = conversion_cast % return_type_info.native_type()
3061 nested_templates.append(conversion_cast) 3062 nested_templates.append(conversion_cast)
3062 3063
3063 if return_type_info.conversion_include(): 3064 if return_type_info.conversion_include():
3064 self._cpp_impl_includes[return_type_info.conversion_include()] = 1 3065 self._cpp_impl_includes[return_type_info.conversion_include()] = 1
3065 if (return_type_info.idl_type() in ['DOMString', 'AtomicString'] and 3066 if (return_type_info.idl_type() in ['DOMString', 'AtomicString'] and
3066 'ConvertNullStringTo' in idl_node.ext_attrs): 3067 'TreatReturnedNullStringAs' in idl_node.ext_attrs):
3067 nested_templates.append('$BODY, ConvertDefaultToNull') 3068 nested_templates.append('$BODY, ConvertDefaultToNull')
3068 nested_templates.append( 3069 nested_templates.append(
3069 ' Dart_Handle returnValue = toDartValue($BODY);\n' 3070 ' Dart_Handle returnValue = toDartValue($BODY);\n'
3070 ' if (returnValue)\n' 3071 ' if (returnValue)\n'
3071 ' Dart_SetReturnValue(args, returnValue);\n') 3072 ' Dart_SetReturnValue(args, returnValue);\n')
3072 else: 3073 else:
3073 nested_templates.append(' $BODY;\n') 3074 nested_templates.append(' $BODY;\n')
3074 3075
3075 if raises_dom_exceptions: 3076 if raises_dom_exceptions:
3076 nested_templates.append( 3077 nested_templates.append(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 namespace = 'HTMLNames' 3166 namespace = 'HTMLNames'
3166 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', 3167 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload',
3167 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 3168 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
3168 'onmouseup', 'onresize', 'onscroll', 'onunload'] 3169 'onmouseup', 'onresize', 'onscroll', 'onunload']
3169 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 3170 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
3170 namespace = 'SVGNames' 3171 namespace = 'SVGNames'
3171 self._cpp_impl_includes[namespace] = 1 3172 self._cpp_impl_includes[namespace] = 1
3172 3173
3173 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 3174 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
3174 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 3175 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
OLDNEW
« no previous file with comments | « client/dom/idl/dart/dart.idl ('k') | client/dom/scripts/databasebuilder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698