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/systemnative.py

Issue 9465011: Support arguments in constructors. (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/scripts/generator.py ('k') | client/dom/src/native_FactoryProviders.dart » ('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 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 self._interface_type_info = GetIDLTypeInfoByName(self._interface.id) 248 self._interface_type_info = GetIDLTypeInfoByName(self._interface.id)
249 self._members_emitter = emitter.Emitter() 249 self._members_emitter = emitter.Emitter()
250 self._cpp_declarations_emitter = emitter.Emitter() 250 self._cpp_declarations_emitter = emitter.Emitter()
251 self._cpp_impl_includes = {} 251 self._cpp_impl_includes = {}
252 self._cpp_definitions_emitter = emitter.Emitter() 252 self._cpp_definitions_emitter = emitter.Emitter()
253 self._cpp_resolver_emitter = emitter.Emitter() 253 self._cpp_resolver_emitter = emitter.Emitter()
254 254
255 self._GenerateConstructors() 255 self._GenerateConstructors()
256 256
257 def _GenerateConstructors(self): 257 def _GenerateConstructors(self):
258 # WebKit IDLs may define constructors with arguments. Currently this form i s not supported 258 if not self._IsConstructable():
259 # (see b/1721). There is custom implementation for some of them, the rest a re just ignored
260 # for now.
261 SUPPORTED_CONSTRUCTORS_WITH_ARGS = [ 'WebKitCSSMatrix' ]
262 UNSUPPORTED_CONSTRUCTORS_WITH_ARGS = [
263 'EventSource',
264 'MediaStream',
265 'PeerConnection',
266 'ShadowRoot',
267 'SharedWorker',
268 'TextTrackCue',
269 'Worker' ]
270 if not self._IsConstructable() or self._interface.id in UNSUPPORTED_CONSTRUC TORS_WITH_ARGS:
271 return 259 return
272 260
273 # TODO(antonm): currently we don't have information about number of argument s expected by 261 # TODO(antonm): currently we don't have information about number of argument s expected by
274 # the constructor, so name only dispatch. 262 # the constructor, so name only dispatch.
275 self._cpp_resolver_emitter.Emit( 263 self._cpp_resolver_emitter.Emit(
276 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 264 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
277 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', 265 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
278 INTERFACE_NAME=self._interface.id) 266 INTERFACE_NAME=self._interface.id)
279 267
280 268
281 if self._interface.id in SUPPORTED_CONSTRUCTORS_WITH_ARGS or 'Constructor' n ot in self._interface.ext_attrs: 269 constructor_info = AnalyzeConstructor(self._interface)
270 if constructor_info is None:
282 # We have a custom implementation for it. 271 # We have a custom implementation for it.
283 self._cpp_declarations_emitter.Emit( 272 self._cpp_declarations_emitter.Emit(
284 '\n' 273 '\n'
285 'void constructorCallback(Dart_NativeArguments);\n') 274 'void constructorCallback(Dart_NativeArguments);\n')
286 return 275 return
287 276
288 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs 277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs
289 raises_dart_exceptions = raises_dom_exceptions 278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a rgs) > 0
290 type_info = GetIDLTypeInfo(self._interface) 279 type_info = GetIDLTypeInfo(self._interface)
291 arguments = [] 280 arguments = []
292 parameter_definitions = '' 281 parameter_definitions_emitter = emitter.Emitter()
293 if 'CallWith' in self._interface.ext_attrs: 282 if 'CallWith' in self._interface.ext_attrs:
294 call_with = self._interface.ext_attrs['CallWith'] 283 call_with = self._interface.ext_attrs['CallWith']
295 if call_with == 'ScriptExecutionContext': 284 if call_with == 'ScriptExecutionContext':
296 raises_dart_exceptions = True 285 raises_dart_exceptions = True
297 parameter_definitions = ( 286 parameter_definitions_emitter.Emit(
298 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' 287 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
299 ' if (!context) {\n' 288 ' if (!context) {\n'
300 ' exception = Dart_NewString("Failed to create an object" );\n' 289 ' exception = Dart_NewString("Failed to create an object" );\n'
301 ' goto fail;\n' 290 ' goto fail;\n'
302 ' }\n') 291 ' }\n')
303 arguments = ['context'] 292 arguments.append('context')
304 else: 293 else:
305 raise Exception('Unsupported CallWith=%s attribute' % call_with) 294 raise Exception('Unsupported CallWith=%s attribute' % call_with)
306 295
296 # Process constructor arguments.
297 for (i, arg) in enumerate(constructor_info.idl_args):
298 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1)
299 arguments.append(arg.id)
300
307 self._GenerateNativeCallback( 301 self._GenerateNativeCallback(
308 callback_name='constructorCallback', 302 callback_name='constructorCallback',
309 idl_node=self._interface, 303 idl_node=self._interface,
310 parameter_definitions=parameter_definitions, 304 parameter_definitions=parameter_definitions_emitter.Fragments(),
311 needs_receiver=False, function_name='%s::create' % type_info.native_type (), 305 needs_receiver=False, function_name='%s::create' % type_info.native_type (),
312 arguments=arguments, 306 arguments=arguments,
313 idl_return_type=self._interface, 307 idl_return_type=self._interface,
314 raises_dart_exceptions=raises_dart_exceptions, 308 raises_dart_exceptions=raises_dart_exceptions,
315 raises_dom_exceptions=raises_dom_exceptions) 309 raises_dom_exceptions=raises_dom_exceptions)
316 310
317 311
318 def _ImplClassName(self, interface_name): 312 def _ImplClassName(self, interface_name):
319 return interface_name + 'Implementation' 313 return interface_name + 'Implementation'
320 314
321 def _IsConstructable(self): 315 def _IsConstructable(self):
322 # FIXME: support ConstructorTemplate. 316 # FIXME: support ConstructorTemplate.
317 # FIXME: support NamedConstructor.
323 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se t(self._interface.ext_attrs) 318 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se t(self._interface.ext_attrs)
324 319
325 def FinishInterface(self): 320 def FinishInterface(self):
326 base = self._BaseClassName(self._interface) 321 base = self._BaseClassName(self._interface)
327 self._dart_impl_emitter.Emit( 322 self._dart_impl_emitter.Emit(
328 self._templates.Load('dart_implementation.darttemplate'), 323 self._templates.Load('dart_implementation.darttemplate'),
329 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, 324 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id,
330 MEMBERS=self._members_emitter.Fragments()) 325 MEMBERS=self._members_emitter.Fragments())
331 326
332 self._GenerateCppHeader() 327 self._GenerateCppHeader()
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 namespace = 'HTMLNames' 769 namespace = 'HTMLNames'
775 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', 770 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload',
776 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 771 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
777 'onmouseup', 'onresize', 'onscroll', 'onunload'] 772 'onmouseup', 'onresize', 'onscroll', 'onunload']
778 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 773 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
779 namespace = 'SVGNames' 774 namespace = 'SVGNames'
780 self._cpp_impl_includes[namespace] = 1 775 self._cpp_impl_includes[namespace] = 1
781 776
782 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 777 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
783 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 778 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
OLDNEW
« no previous file with comments | « client/dom/scripts/generator.py ('k') | client/dom/src/native_FactoryProviders.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698