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

Unified Diff: lib/dom/scripts/systemnative.py

Issue 10822009: Refactor invocation emission. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dom/scripts/systemnative.py
diff --git a/lib/dom/scripts/systemnative.py b/lib/dom/scripts/systemnative.py
index 9f90d2894238775798df1a2de0e16e6551ae9d0b..3dfeba8d5cbe9c922fa25fe8bd07824839bfaef3 100644
--- a/lib/dom/scripts/systemnative.py
+++ b/lib/dom/scripts/systemnative.py
@@ -804,17 +804,40 @@ class NativeImplementationGenerator(systembase.BaseGenerator):
if 'NeedsUserGestureCheck' in ext_attrs:
cpp_arguments.append('DartUtilities::processingUserGesture');
- invocation = self._GenerateWebCoreInvocation(
- function_expression, cpp_arguments, return_type, ext_attrs, raises_dom_exception)
+ invocation_emitter = head_emitter
+ if raises_dom_exception:
+ cpp_arguments.append('ec')
+ invocation_emitter = head_emitter.Emit(
+ ' ExceptionCode ec = 0;\n'
+ '$!INVOCATION'
+ ' if (UNLIKELY(ec)) {\n'
+ ' exception = DartDOMWrapper::exceptionCodeToDartException(ec);\n'
+ ' goto fail;\n'
+ ' }\n')
+
+ function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
+ if return_type == 'void':
+ invocation_emitter.Emit(
+ ' $FUNCTION_CALL;\n',
+ FUNCTION_CALL=function_call)
+ else:
+ return_type_info = self._TypeInfo(return_type)
+ self._cpp_impl_includes |= set(return_type_info.conversion_includes())
+
+ # Generate to Dart conversion of C++ value.
+ to_dart_conversion = return_type_info.to_dart_conversion(function_call, self._interface.id, ext_attrs)
+ invocation_emitter.Emit(
+ ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n'
+ ' if (returnValue)\n'
+ ' Dart_SetReturnValue(args, returnValue);\n',
+ TO_DART_CONVERSION=to_dart_conversion)
body = emitter.Format(
' {\n'
'$HEAD'
- '$INVOCATION'
' return;\n'
' }\n',
- HEAD=head_emitter.Fragments(),
- INVOCATION=invocation)
+ HEAD=head_emitter.Fragments())
if raises_exceptions:
body = emitter.Format(
@@ -893,36 +916,6 @@ class NativeImplementationGenerator(systembase.BaseGenerator):
return '%s::%s' % (self._interface_type_info.idl_type(), function_name)
return '%s%s' % (self._interface_type_info.receiver(), function_name)
- def _GenerateWebCoreInvocation(self, function_expression, arguments,
- idl_return_type, attributes, raises_dom_exceptions):
- invocation_template = ' $FUNCTION_CALL;\n'
- if idl_return_type != 'void':
- return_type_info = self._TypeInfo(idl_return_type)
- self._cpp_impl_includes |= set(return_type_info.conversion_includes())
-
- # Generate to Dart conversion of C++ value.
- to_dart_conversion = return_type_info.to_dart_conversion('$FUNCTION_CALL', self._interface.id, attributes)
- invocation_template = emitter.Format(
- ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n'
- ' if (returnValue)\n'
- ' Dart_SetReturnValue(args, returnValue);\n',
- TO_DART_CONVERSION=to_dart_conversion)
-
- if raises_dom_exceptions:
- # Add 'ec' argument to WebCore invocation and convert DOM exception to Dart exception.
- arguments.append('ec')
- invocation_template = emitter.Format(
- ' ExceptionCode ec = 0;\n'
- '$INVOCATION'
- ' if (UNLIKELY(ec)) {\n'
- ' exception = DartDOMWrapper::exceptionCodeToDartException(ec);\n'
- ' goto fail;\n'
- ' }\n',
- INVOCATION=invocation_template)
-
- return emitter.Format(invocation_template,
- FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
-
def _TypeInfo(self, type_name):
return self._system._type_registry.TypeInfo(type_name)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698