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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 constructor_info = AnalyzeConstructor(self._interface) | 269 constructor_info = AnalyzeConstructor(self._interface) |
270 if constructor_info is None: | 270 if constructor_info is None: |
271 # We have a custom implementation for it. | 271 # We have a custom implementation for it. |
272 self._cpp_declarations_emitter.Emit( | 272 self._cpp_declarations_emitter.Emit( |
273 '\n' | 273 '\n' |
274 'void constructorCallback(Dart_NativeArguments);\n') | 274 'void constructorCallback(Dart_NativeArguments);\n') |
275 return | 275 return |
276 | 276 |
277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs | 277 raises_dom_exceptions = 'ConstructorRaisesException' in self._interface.ext_ attrs |
278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a rgs) > 0 | 278 raises_dart_exceptions = raises_dom_exceptions or len(constructor_info.idl_a rgs) > 0 |
279 type_info = GetIDLTypeInfo(self._interface) | |
280 arguments = [] | 279 arguments = [] |
281 parameter_definitions_emitter = emitter.Emitter() | 280 parameter_definitions_emitter = emitter.Emitter() |
282 if 'CallWith' in self._interface.ext_attrs: | 281 if 'CallWith' in self._interface.ext_attrs: |
283 call_with = self._interface.ext_attrs['CallWith'] | 282 call_with = self._interface.ext_attrs['CallWith'] |
284 if call_with == 'ScriptExecutionContext': | 283 if call_with == 'ScriptExecutionContext': |
285 raises_dart_exceptions = True | 284 raises_dart_exceptions = True |
286 parameter_definitions_emitter.Emit( | 285 parameter_definitions_emitter.Emit( |
287 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' | 286 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' |
288 ' if (!context) {\n' | 287 ' if (!context) {\n' |
289 ' exception = Dart_NewString("Failed to create an object" );\n' | 288 ' exception = Dart_NewString("Failed to create an object" );\n' |
290 ' goto fail;\n' | 289 ' goto fail;\n' |
291 ' }\n') | 290 ' }\n') |
292 arguments.append('context') | 291 arguments.append('context') |
293 else: | 292 else: |
294 raise Exception('Unsupported CallWith=%s attribute' % call_with) | 293 raise Exception('Unsupported CallWith=%s attribute' % call_with) |
295 | 294 |
296 # Process constructor arguments. | 295 # Process constructor arguments. |
297 for (i, arg) in enumerate(constructor_info.idl_args): | 296 for (i, arg) in enumerate(constructor_info.idl_args): |
298 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) | 297 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) |
299 arguments.append(arg.id) | 298 arguments.append(arg.id) |
300 | 299 |
301 self._GenerateNativeCallback( | 300 function_expression = '%s::create' % self._interface_type_info.native_type() |
302 callback_name='constructorCallback', | 301 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
303 idl_node=self._interface, | 302 self._interface, self._interface.ext_attrs, raises_dom_exceptions) |
303 self._GenerateNativeCallback(callback_name='constructorCallback', | |
antonm
2012/02/27 13:17:33
nit: I'd prefer to callback_name='...' on a separa
| |
304 parameter_definitions=parameter_definitions_emitter.Fragments(), | 304 parameter_definitions=parameter_definitions_emitter.Fragments(), |
305 needs_receiver=False, function_name='%s::create' % type_info.native_type (), | 305 needs_receiver=False, invocation=invocation, |
306 arguments=arguments, | 306 raises_exceptions=raises_dart_exceptions) |
307 idl_return_type=self._interface, | |
308 raises_dart_exceptions=raises_dart_exceptions, | |
309 raises_dom_exceptions=raises_dom_exceptions) | |
310 | |
311 | 307 |
312 def _ImplClassName(self, interface_name): | 308 def _ImplClassName(self, interface_name): |
313 return interface_name + 'Implementation' | 309 return interface_name + 'Implementation' |
314 | 310 |
315 def _IsConstructable(self): | 311 def _IsConstructable(self): |
316 # FIXME: support ConstructorTemplate. | 312 # FIXME: support ConstructorTemplate. |
317 # FIXME: support NamedConstructor. | 313 # FIXME: support NamedConstructor. |
318 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se t(self._interface.ext_attrs) | 314 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor']) & se t(self._interface.ext_attrs) |
319 | 315 |
320 def FinishInterface(self): | 316 def FinishInterface(self): |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) | 366 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) |
371 | 367 |
372 def AddAttribute(self, getter, setter): | 368 def AddAttribute(self, getter, setter): |
373 # FIXME: Dartium does not support attribute event listeners. However, JS | 369 # FIXME: Dartium does not support attribute event listeners. However, JS |
374 # implementation falls back to them when addEventListener is not available. | 370 # implementation falls back to them when addEventListener is not available. |
375 # Make sure addEventListener is available in all EventTargets and remove | 371 # Make sure addEventListener is available in all EventTargets and remove |
376 # this check. | 372 # this check. |
377 if (getter or setter).type.id == 'EventListener': | 373 if (getter or setter).type.id == 'EventListener': |
378 return | 374 return |
379 | 375 |
380 # FIXME: support 'ImplementedBy'. | |
381 if 'ImplementedBy' in (getter or setter).ext_attrs: | |
382 return | |
383 | |
384 # FIXME: these should go away. | 376 # FIXME: these should go away. |
385 classes_with_unsupported_custom_getters = [ | 377 classes_with_unsupported_custom_getters = [ |
386 'Clipboard', 'Console', 'Coordinates', 'DeviceMotionEvent', | 378 'Clipboard', 'Console', 'Coordinates', 'DeviceMotionEvent', |
387 'DeviceOrientationEvent', 'FileReader', 'JavaScriptCallFrame', | 379 'DeviceOrientationEvent', 'FileReader', 'JavaScriptCallFrame', |
388 'HTMLInputElement', 'HTMLOptionsCollection', 'HTMLOutputElement', | 380 'HTMLInputElement', 'HTMLOptionsCollection', 'HTMLOutputElement', |
389 'ScriptProfileNode', 'WebKitAnimation'] | 381 'ScriptProfileNode', 'WebKitAnimation'] |
390 if (self._interface.id in classes_with_unsupported_custom_getters and | 382 if (self._interface.id in classes_with_unsupported_custom_getters and |
391 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)): | 383 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)): |
392 return | 384 return |
393 | 385 |
(...skipping 27 matching lines...) Expand all Loading... | |
421 else: | 413 else: |
422 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', | 414 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', |
423 lambda s: s.group(1).lower(), | 415 lambda s: s.group(1).lower(), |
424 attr.id) | 416 attr.id) |
425 webcore_function_name = re.sub(r'^(create|exclusive)', | 417 webcore_function_name = re.sub(r'^(create|exclusive)', |
426 lambda s: 'is' + s.group(1).capitalize(), | 418 lambda s: 'is' + s.group(1).capitalize(), |
427 webcore_function_name) | 419 webcore_function_name) |
428 if attr.type.id.startswith('SVGAnimated'): | 420 if attr.type.id.startswith('SVGAnimated'): |
429 webcore_function_name += 'Animated' | 421 webcore_function_name += 'Animated' |
430 | 422 |
431 self._GenerateNativeCallback(cpp_callback_name, attr, '', | 423 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) |
432 True, webcore_function_name, arguments, idl_return_type=attr.type, | 424 invocation = self._GenerateWebCoreInvocation(function_expression, |
433 raises_dart_exceptions=attr.get_raises, | 425 arguments, attr.type, attr.ext_attrs, attr.get_raises) |
434 raises_dom_exceptions=attr.get_raises) | 426 self._GenerateNativeCallback(cpp_callback_name, '', True, invocation, |
427 raises_exceptions=attr.get_raises) | |
435 | 428 |
436 def _AddSetter(self, attr): | 429 def _AddSetter(self, attr): |
437 dart_declaration = 'void set %s(%s)' % (attr.id, attr.type.id) | 430 dart_declaration = 'void set %s(%s)' % (attr.id, attr.type.id) |
438 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) | 431 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) |
439 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, | 432 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, |
440 dart_declaration, 'Setter', is_custom) | 433 dart_declaration, 'Setter', is_custom) |
441 if is_custom: | 434 if is_custom: |
442 return | 435 return |
443 | 436 |
444 arguments = [] | 437 arguments = [] |
445 if 'Reflect' in attr.ext_attrs: | 438 if 'Reflect' in attr.ext_attrs: |
446 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_setter_name() | 439 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_setter_name() |
447 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) | 440 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) |
448 else: | 441 else: |
449 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', | 442 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', |
450 lambda s: s.group(1).upper(), | 443 lambda s: s.group(1).upper(), |
451 attr.id) | 444 attr.id) |
452 webcore_function_name = 'set%s' % webcore_function_name | 445 webcore_function_name = 'set%s' % webcore_function_name |
453 if attr.type.id.startswith('SVGAnimated'): | 446 if attr.type.id.startswith('SVGAnimated'): |
454 webcore_function_name += 'Animated' | 447 webcore_function_name += 'Animated' |
455 | 448 |
456 arguments.append(attr.id) | 449 arguments.append(attr.id) |
450 | |
457 parameter_definitions_emitter = emitter.Emitter() | 451 parameter_definitions_emitter = emitter.Emitter() |
458 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0) | 452 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0) |
459 parameter_definitions = parameter_definitions_emitter.Fragments() | 453 parameter_definitions = parameter_definitions_emitter.Fragments() |
460 self._GenerateNativeCallback(cpp_callback_name, attr, parameter_definitions, | 454 |
461 True, webcore_function_name, arguments, idl_return_type=None, | 455 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) |
462 raises_dart_exceptions=True, | 456 invocation = self._GenerateWebCoreInvocation(function_expression, |
463 raises_dom_exceptions=attr.set_raises) | 457 arguments, None, attr.ext_attrs, attr.set_raises) |
458 | |
459 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions, | |
460 True, invocation, raises_exceptions=True) | |
464 | 461 |
465 def _HasNativeIndexGetter(self, interface): | 462 def _HasNativeIndexGetter(self, interface): |
466 return ('CustomIndexedGetter' in interface.ext_attrs or | 463 return ('CustomIndexedGetter' in interface.ext_attrs or |
467 'NumericIndexedGetter' in interface.ext_attrs) | 464 'NumericIndexedGetter' in interface.ext_attrs) |
468 | 465 |
469 def _EmitNativeIndexGetter(self, interface, element_type): | 466 def _EmitNativeIndexGetter(self, interface, element_type): |
470 dart_declaration = '%s operator[](int index)' % element_type | 467 dart_declaration = '%s operator[](int index)' % element_type |
471 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, | 468 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, |
472 'Callback', True) | 469 'Callback', True) |
473 | 470 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 def GenerateSingleOperation(self, dispatch_emitter, info, indent, operation): | 508 def GenerateSingleOperation(self, dispatch_emitter, info, indent, operation): |
512 """Generates a call to a single operation. | 509 """Generates a call to a single operation. |
513 | 510 |
514 Arguments: | 511 Arguments: |
515 dispatch_emitter: an dispatch_emitter for the body of a block of code. | 512 dispatch_emitter: an dispatch_emitter for the body of a block of code. |
516 info: the compound information about the operation and its overloads. | 513 info: the compound information about the operation and its overloads. |
517 indent: an indentation string for generated code. | 514 indent: an indentation string for generated code. |
518 operation: the IDLOperation to call. | 515 operation: the IDLOperation to call. |
519 """ | 516 """ |
520 | 517 |
521 # FIXME: support ImplementedBy callbacks. | |
522 if 'ImplementedBy' in operation.ext_attrs: | |
523 return | |
524 | |
525 for op in self._interface.operations: | 518 for op in self._interface.operations: |
526 if op.id != operation.id or len(op.arguments) <= len(operation.arguments): | 519 if op.id != operation.id or len(op.arguments) <= len(operation.arguments): |
527 continue | 520 continue |
528 next_argument = op.arguments[len(operation.arguments)] | 521 next_argument = op.arguments[len(operation.arguments)] |
529 if next_argument.is_optional and 'Callback' in next_argument.ext_attrs: | 522 if next_argument.is_optional and 'Callback' in next_argument.ext_attrs: |
530 # FIXME: '[Optional, Callback]' arguments could be non-optional in | 523 # FIXME: '[Optional, Callback]' arguments could be non-optional in |
531 # webcore. We need to fix overloads handling to generate native | 524 # webcore. We need to fix overloads handling to generate native |
532 # callbacks properly. | 525 # callbacks properly. |
533 return | 526 return |
534 | 527 |
(...skipping 20 matching lines...) Expand all Loading... | |
555 dart_declaration = '%s _%s(%s)' % (info.type_name, native_name, | 548 dart_declaration = '%s _%s(%s)' % (info.type_name, native_name, |
556 argument_list) | 549 argument_list) |
557 is_custom = 'Custom' in operation.ext_attrs | 550 is_custom = 'Custom' in operation.ext_attrs |
558 cpp_callback_name = self._GenerateNativeBinding( | 551 cpp_callback_name = self._GenerateNativeBinding( |
559 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', | 552 native_name, 1 + len(operation.arguments), dart_declaration, 'Callback', |
560 is_custom) | 553 is_custom) |
561 if is_custom: | 554 if is_custom: |
562 return | 555 return |
563 | 556 |
564 # Generate callback. | 557 # Generate callback. |
565 webcore_function_name = operation.id | 558 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) |
566 if 'ImplementedAs' in operation.ext_attrs: | |
567 webcore_function_name = operation.ext_attrs['ImplementedAs'] | |
568 | 559 |
569 parameter_definitions_emitter = emitter.Emitter() | 560 parameter_definitions_emitter = emitter.Emitter() |
570 raises_dart_exceptions = len(operation.arguments) > 0 or operation.raises | 561 raises_dart_exceptions = len(operation.arguments) > 0 or operation.raises |
571 arguments = [] | 562 arguments = [] |
572 | 563 |
573 # Process 'CallWith' argument. | 564 # Process 'CallWith' argument. |
574 if 'CallWith' in operation.ext_attrs: | 565 if 'CallWith' in operation.ext_attrs: |
575 call_with = operation.ext_attrs['CallWith'] | 566 call_with = operation.ext_attrs['CallWith'] |
576 if call_with == 'ScriptExecutionContext': | 567 if call_with == 'ScriptExecutionContext': |
577 parameter_definitions_emitter.Emit( | 568 parameter_definitions_emitter.Emit( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 if len(operation.arguments) == 2: | 604 if len(operation.arguments) == 2: |
614 arguments.append('false') | 605 arguments.append('false') |
615 | 606 |
616 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': | 607 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': |
617 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart | 608 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart |
618 # idl, but is not optional in webcore implementation. | 609 # idl, but is not optional in webcore implementation. |
619 if len(operation.arguments) == 2: | 610 if len(operation.arguments) == 2: |
620 arguments.append('String()') | 611 arguments.append('String()') |
621 | 612 |
622 if 'NeedsUserGestureCheck' in operation.ext_attrs: | 613 if 'NeedsUserGestureCheck' in operation.ext_attrs: |
623 arguments.extend('DartUtilities::processingUserGesture') | 614 arguments.append('DartUtilities::processingUserGesture') |
624 | 615 |
625 parameter_definitions = parameter_definitions_emitter.Fragments() | 616 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) |
626 self._GenerateNativeCallback(cpp_callback_name, operation, parameter_definit ions, | 617 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
627 True, webcore_function_name, arguments, idl_return_type=operation.type, | 618 operation.type, operation.ext_attrs, operation.raises) |
628 raises_dart_exceptions=raises_dart_exceptions, | 619 self._GenerateNativeCallback(cpp_callback_name, |
629 raises_dom_exceptions=operation.raises) | 620 parameter_definitions=parameter_definitions_emitter.Fragments(), |
621 needs_receiver=True, invocation=invocation, | |
622 raises_exceptions=raises_dart_exceptions) | |
630 | 623 |
631 def _GenerateNativeCallback(self, callback_name, idl_node, | 624 def _GenerateNativeCallback(self, callback_name, parameter_definitions, |
632 parameter_definitions, needs_receiver, function_name, arguments, idl_retur n_type, | 625 needs_receiver, invocation, raises_exceptions): |
633 raises_dart_exceptions, raises_dom_exceptions): | |
634 if raises_dom_exceptions: | |
635 arguments.append('ec') | |
636 prefix = '' | |
637 if needs_receiver: prefix = self._interface_type_info.receiver() | |
638 callback = '%s%s(%s)' % (prefix, function_name, ', '.join(arguments)) | |
639 | 626 |
640 nested_templates = [] | 627 if needs_receiver: |
641 if idl_return_type and idl_return_type.id != 'void': | 628 parameter_definitions = emitter.Format( |
642 return_type_info = GetIDLTypeInfo(idl_return_type) | 629 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n' |
643 conversion_cast = return_type_info.conversion_cast('$BODY') | 630 ' $PARAMETER_DEFINITIONS\n', |
644 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): | 631 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
645 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | 632 PARAMETER_DEFINITIONS=parameter_definitions) |
646 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | |
647 conversion_cast = '%s::create($BODY)' | |
648 if self._interface.id.startswith('SVGAnimated'): | |
649 conversion_cast = 'static_cast<%s*>($BODY)' | |
650 elif return_type_info.idl_type() == 'SVGStringList': | |
651 conversion_cast = '%s::create(receiver, $BODY)' | |
652 elif self._interface.id.endswith('List'): | |
653 conversion_cast = 'static_cast<%s*>($BODY.get())' | |
654 elif return_type_info.idl_type() in svg_primitive_types: | |
655 conversion_cast = '%s::create($BODY)' | |
656 else: | |
657 conversion_cast = 'static_cast<%s*>($BODY)' | |
658 conversion_cast = conversion_cast % return_type_info.native_type() | |
659 nested_templates.append(conversion_cast) | |
660 | 633 |
661 if return_type_info.conversion_include(): | 634 body = emitter.Format( |
662 self._cpp_impl_includes[return_type_info.conversion_include()] = 1 | |
663 if (return_type_info.idl_type() in ['DOMString', 'AtomicString'] and | |
664 'TreatReturnedNullStringAs' in idl_node.ext_attrs): | |
665 nested_templates.append('$BODY, ConvertDefaultToNull') | |
666 nested_templates.append( | |
667 ' Dart_Handle returnValue = toDartValue($BODY);\n' | |
668 ' if (returnValue)\n' | |
669 ' Dart_SetReturnValue(args, returnValue);\n') | |
670 else: | |
671 nested_templates.append(' $BODY;\n') | |
672 | |
673 if raises_dom_exceptions: | |
674 nested_templates.append( | |
675 ' ExceptionCode ec = 0;\n' | |
676 '$BODY' | |
677 ' if (UNLIKELY(ec)) {\n' | |
678 ' exception = DartDOMWrapper::exceptionCodeToDartException( ec);\n' | |
679 ' goto fail;\n' | |
680 ' }\n') | |
681 | |
682 nested_templates.append( | |
683 ' {\n' | 635 ' {\n' |
684 '$PARAMETER_DEFINITIONS' | 636 '$PARAMETER_DEFINITIONS' |
685 '$BODY' | 637 '$INVOCATION' |
686 ' return;\n' | 638 ' return;\n' |
687 ' }\n') | 639 ' }\n', |
640 PARAMETER_DEFINITIONS=parameter_definitions, | |
641 INVOCATION=invocation) | |
688 | 642 |
689 if raises_dart_exceptions: | 643 if raises_exceptions: |
690 nested_templates.append( | 644 body = emitter.Format( |
691 ' Dart_Handle exception;\n' | 645 ' Dart_Handle exception;\n' |
692 '$BODY' | 646 '$BODY' |
693 '\n' | 647 '\n' |
694 'fail:\n' | 648 'fail:\n' |
695 ' Dart_ThrowException(exception);\n' | 649 ' Dart_ThrowException(exception);\n' |
696 ' ASSERT_NOT_REACHED();\n') | 650 ' ASSERT_NOT_REACHED();\n', |
651 BODY=body) | |
697 | 652 |
698 nested_templates.append( | 653 self._cpp_definitions_emitter.Emit( |
699 '\n' | 654 '\n' |
700 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' | 655 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' |
701 '{\n' | 656 '{\n' |
702 ' DartApiScope dartApiScope;\n' | 657 ' DartApiScope dartApiScope;\n' |
703 '$BODY' | 658 '$BODY' |
704 '}\n') | 659 '}\n', |
705 | 660 CALLBACK_NAME=callback_name, |
706 template_parameters = { | 661 BODY=body) |
707 'CALLBACK_NAME': callback_name, | |
708 'WEBCORE_CLASS_NAME': self._interface_type_info.native_type(), | |
709 'PARAMETER_DEFINITIONS': parameter_definitions, | |
710 } | |
711 if needs_receiver: | |
712 template_parameters['PARAMETER_DEFINITIONS'] = emitter.Format( | |
713 ' $WEBCORE_CLASS_NAME* receiver = DartDOMWrapper::receiver< $WE BCORE_CLASS_NAME >(args);\n' | |
714 ' $PARAMETER_DEFINITIONS\n', | |
715 **template_parameters) | |
716 | |
717 for template in nested_templates: | |
718 template_parameters['BODY'] = callback | |
719 callback = emitter.Format(template, **template_parameters) | |
720 | |
721 self._cpp_definitions_emitter.Emit(callback) | |
722 | 662 |
723 def _GenerateParameterAdapter(self, emitter, idl_argument, index): | 663 def _GenerateParameterAdapter(self, emitter, idl_argument, index): |
724 type_info = GetIDLTypeInfo(idl_argument.type) | 664 type_info = GetIDLTypeInfo(idl_argument.type) |
725 (adapter_type, include_name) = type_info.parameter_adapter_info() | 665 (adapter_type, include_name) = type_info.parameter_adapter_info() |
726 if include_name: | 666 if include_name: |
727 self._cpp_impl_includes[include_name] = 1 | 667 self._cpp_impl_includes[include_name] = 1 |
728 flags = '' | 668 flags = '' |
729 if idl_argument.ext_attrs.get('Optionial') == 'DefaultIsNullString': | 669 if idl_argument.ext_attrs.get('Optionial') == 'DefaultIsNullString': |
730 flags = ', DartUtilities::ConvertNullToEmptyString' | 670 flags = ', DartUtilities::ConvertNullToEmptyString' |
731 emitter.Emit( | 671 emitter.Emit( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 namespace = 'HTMLNames' | 709 namespace = 'HTMLNames' |
770 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', | 710 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', |
771 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', | 711 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', |
772 'onmouseup', 'onresize', 'onscroll', 'onunload'] | 712 'onmouseup', 'onresize', 'onscroll', 'onunload'] |
773 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: | 713 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: |
774 namespace = 'SVGNames' | 714 namespace = 'SVGNames' |
775 self._cpp_impl_includes[namespace] = 1 | 715 self._cpp_impl_includes[namespace] = 1 |
776 | 716 |
777 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() | 717 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() |
778 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) | 718 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) |
719 | |
720 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): | |
721 if 'ImplementedBy' in idl_node.ext_attrs: | |
722 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) | |
723 return '%s%s' % (self._interface_type_info.receiver(), function_name) | |
724 | |
725 def _GenerateWebCoreInvocation(self, function_expression, arguments, | |
726 idl_return_type, attributes, raises_dom_exceptions): | |
727 invocation_template = ' $FUNCTION_CALL;\n' | |
728 if idl_return_type and idl_return_type.id != 'void': | |
729 return_type_info = GetIDLTypeInfo(idl_return_type) | |
730 if return_type_info.conversion_include(): | |
731 self._cpp_impl_includes[return_type_info.conversion_include()] = 1 | |
732 | |
733 # Generate C++ cast based on idl return type. | |
734 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL') | |
735 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): | |
736 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', | |
737 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] | |
738 conversion_cast = '%s::create($FUNCTION_CALL)' | |
739 if self._interface.id.startswith('SVGAnimated'): | |
740 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' | |
741 elif return_type_info.idl_type() == 'SVGStringList': | |
742 conversion_cast = '%s::create(receiver, $FUNCTION_CALL)' | |
743 elif self._interface.id.endswith('List'): | |
744 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL.get())' | |
745 elif return_type_info.idl_type() in svg_primitive_types: | |
746 conversion_cast = '%s::create($FUNCTION_CALL)' | |
747 else: | |
748 conversion_cast = 'static_cast<%s*>($FUNCTION_CALL)' | |
749 conversion_cast = conversion_cast % return_type_info.native_type() | |
750 | |
751 # Generate to Dart conversion of C++ value. | |
752 conversion_arguments = [conversion_cast] | |
753 if (return_type_info.idl_type() in ['DOMString', 'AtomicString'] and | |
754 'TreatReturnedNullStringAs' in attributes): | |
755 conversion_arguments.append('ConvertDefaultToNull') | |
756 | |
757 invocation_template = emitter.Format( | |
758 ' Dart_Handle returnValue = toDartValue($ARGUMENTS);\n' | |
759 ' if (returnValue)\n' | |
760 ' Dart_SetReturnValue(args, returnValue);\n', | |
761 ARGUMENTS=', '.join(conversion_arguments)) | |
762 | |
763 if raises_dom_exceptions: | |
764 # Add 'ec' argument to WebCore invocation and convert DOM exception to Dar t exception. | |
765 arguments.append('ec') | |
766 invocation_template = emitter.Format( | |
767 ' ExceptionCode ec = 0;\n' | |
768 '$INVOCATION' | |
769 ' if (UNLIKELY(ec)) {\n' | |
770 ' exception = DartDOMWrapper::exceptionCodeToDartException( ec);\n' | |
771 ' goto fail;\n' | |
772 ' }\n', | |
773 INVOCATION=invocation_template) | |
774 | |
775 if 'ImplementedBy' in attributes: | |
776 arguments.insert(0, 'receiver') | |
777 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 | |
778 | |
779 return emitter.Format(invocation_template, | |
780 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) | |
OLD | NEW |