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

Unified Diff: client/dom/scripts/dartgenerator.py

Issue 9416062: Support generation of constructors in the most common case. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/tests/client/client.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/dom/scripts/dartgenerator.py
diff --git a/client/dom/scripts/dartgenerator.py b/client/dom/scripts/dartgenerator.py
index e267c905996abb0c91c02932c43c029da3c663ef..06db322a2b8d726031e67661836fd6dc98d341a2 100755
--- a/client/dom/scripts/dartgenerator.py
+++ b/client/dom/scripts/dartgenerator.py
@@ -2705,21 +2705,67 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator):
self._cpp_resolver_emitter = emitter.Emitter()
# Generate constructor.
- # FIXME: add proper support for non-custom constructors.
- if ('CustomConstructor' in self._interface.ext_attrs or
- 'V8CustomConstructor' in self._interface.ext_attrs or
- self._interface.id in ['FileReader', 'WebKitCSSMatrix', 'XSLTProcessor']):
+ # WebKit IDLs may define constructors with arguments. Currently this form is not supported
+ # (see b/1721). There is custom implementation for some of them, the rest are just ignored
+ # for now.
+ SUPPORTED_CONSTRUCTORS_WITH_ARGS = [ 'WebKitCSSMatrix' ]
+ UNSUPPORTED_CONSTRUCTORS_WITH_ARGS = [
+ 'EventSource',
+ 'MediaStream',
+ 'PeerConnection',
+ 'ShadowRoot',
+ 'SharedWorker',
+ 'TextTrackCue',
+ 'Worker' ]
+ if self._IsConstructable() and self._interface.id not in UNSUPPORTED_CONSTRUCTORS_WITH_ARGS:
podivilov 2012/02/17 17:47:20 Please use early return.
self._cpp_resolver_emitter.Emit(
' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
INTERFACE_NAME=self._interface.id)
- self._cpp_declarations_emitter.Emit(
- '\n'
- 'void constructorCallback(Dart_NativeArguments);\n')
+
+ if self._interface.id not in SUPPORTED_CONSTRUCTORS_WITH_ARGS and 'Constructor' in self._interface.ext_attrs:
podivilov 2012/02/17 17:47:20 Early return as well: if custom, just emit declara
+ raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_attrs
+ raises_dart_exceptions = raises_dom_exceptions
+ type_info = GetIDLTypeInfo(self._interface)
+ arguments = []
+ parameter_definitions = ''
+ if 'CallWith' in self._interface.ext_attrs:
+ call_with = self._interface.ext_attrs['CallWith']
+ if call_with == 'ScriptExecutionContext':
+ raises_dart_exceptions = True
+ parameter_definitions = (
+ ' ScriptExecutionContext* context = DartUtilities::scriptExecutionContext();\n'
+ ' if (!context) {\n'
+ ' exception = Dart_NewString("Failed to create an object");\n'
+ ' goto fail;\n'
+ ' }\n')
+ arguments = ['context']
+ else:
+ raise Exception('Unsupported CallWith=%s attribute' % call_with)
+
+ self._GenerateNativeCallbackBase(
+ callback_name='constructorCallback',
+ idl_node=self._interface,
+ parameter_definitions=parameter_definitions,
+ function_name='%s::create' % type_info.native_type(),
+ arguments=arguments,
+ idl_return_type=self._interface,
+ raises_dart_exceptions=raises_dart_exceptions,
+ raises_dom_exceptions=raises_dom_exceptions,
+ needs_receiver=False)
+ else:
+ self._cpp_declarations_emitter.Emit(
+ '\n'
+ 'void constructorCallback(Dart_NativeArguments);\n')
+
def _ImplClassName(self, interface_name):
return interface_name + 'Implementation'
+ def _IsConstructable(self):
+ # FIXME: support ConstructorTemplate.
+ return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & set(self._interface.ext_attrs)
+
def FinishInterface(self):
base = self._BaseClassName(self._interface)
self._dart_impl_emitter.Emit(
@@ -3035,10 +3081,23 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator):
def _GenerateNativeCallback(self, callback_name, idl_node,
parameter_definitions, function_name, arguments, idl_return_type,
raises_dart_exceptions, raises_dom_exceptions):
- receiver = self._interface_type_info.receiver()
+ self._GenerateNativeCallbackBase(
podivilov 2012/02/17 17:47:20 I think such trampolines make the code messy. Coul
+ callback_name=callback_name,
+ idl_node=idl_node,
+ parameter_definitions=parameter_definitions,
+ function_name=self._interface_type_info.receiver() + function_name,
+ arguments=arguments,
+ idl_return_type=idl_return_type,
+ raises_dart_exceptions=raises_dart_exceptions,
+ raises_dom_exceptions=raises_dom_exceptions,
+ needs_receiver=True)
+
+ def _GenerateNativeCallbackBase(self, callback_name, idl_node,
+ parameter_definitions, function_name, arguments, idl_return_type,
+ raises_dart_exceptions, raises_dom_exceptions, needs_receiver):
if raises_dom_exceptions:
arguments.append('ec')
- callback = '%s%s(%s)' % (receiver, function_name, ', '.join(arguments))
+ callback = '%s(%s)' % (function_name, ', '.join(arguments))
podivilov 2012/02/17 17:47:20 Could you please replace "function_name, arguments
nested_templates = []
if idl_return_type and idl_return_type.id != 'void':
@@ -3084,9 +3143,7 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator):
nested_templates.append(
' {\n'
- ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WEBCORE_CLASS_NAME >(args);\n'
'$PARAMETER_DEFINITIONS'
- '\n'
'$BODY'
' return;\n'
' }\n')
@@ -3113,11 +3170,15 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator):
'WEBCORE_CLASS_NAME': self._interface_type_info.native_type(),
'PARAMETER_DEFINITIONS': parameter_definitions,
}
+ if needs_receiver:
+ template_parameters['PARAMETER_DEFINITIONS'] = emitter.Format(
+ ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WEBCORE_CLASS_NAME >(args);\n'
+ ' $PARAMETER_DEFINITIONS\n',
+ **template_parameters)
+
for template in nested_templates:
template_parameters['BODY'] = callback
- callback_emitter = emitter.Emitter()
- callback_emitter.Emit(template, **template_parameters)
- callback = ''.join(callback_emitter.Fragments())
+ callback = emitter.Format(template, **template_parameters)
self._cpp_definitions_emitter.Emit(callback)
« no previous file with comments | « no previous file | client/tests/client/client.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698