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

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 113743003: Add more functions to the list of leaf functions which do not need an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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 | « tools/dom/scripts/generator.py ('k') | tools/dom/templates/html/dartium/cpp_header.template » ('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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream', 86 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream',
87 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource', 87 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource',
88 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource', 88 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource',
89 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource', 89 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource',
90 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream', 90 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream',
91 } 91 }
92 92
93 _cpp_partial_map = {} 93 _cpp_partial_map = {}
94 94
95 _cpp_no_auto_scope_list = set([ 95 _cpp_no_auto_scope_list = set([
96 ('Document', 'body', 'Getter'),
97 ('Document', 'getElementById', 'Callback'),
98 ('Document', 'getElementsByName', 'Callback'),
99 ('Document', 'getElementsByTagName', 'Callback'),
100 ('Element', 'getAttribute', 'Callback'),
101 ('Element', 'getAttributeNS', 'Callback'),
102 ('Element', 'id', 'Getter'),
103 ('Element', 'id', 'Setter'),
104 ('Element', 'setAttribute', 'Callback'),
105 ('Element', 'setAttributeNS', 'Callback'),
96 ('Node', 'firstChild', 'Getter'), 106 ('Node', 'firstChild', 'Getter'),
97 ('Node', 'lastChild', 'Getter'), 107 ('Node', 'lastChild', 'Getter'),
98 ('Node', 'nextSibling', 'Getter'), 108 ('Node', 'nextSibling', 'Getter'),
99 ('Node', 'previousSibling', 'Getter'), 109 ('Node', 'previousSibling', 'Getter'),
100 ('Node', 'childNodes', 'Getter'), 110 ('Node', 'childNodes', 'Getter'),
111 ('Node', 'nodeType', 'Getter'),
101 ('NodeList', 'length', 'Getter'), 112 ('NodeList', 'length', 'Getter'),
102 ('NodeList', 'item', 'Callback'), 113 ('NodeList', 'item', 'Callback'),
103 ('Document', 'body', 'Getter'),
104 ]) 114 ])
105 115
106 # TODO(vsm): This should be recoverable from IDL, but we appear to not 116 # TODO(vsm): This should be recoverable from IDL, but we appear to not
107 # track the necessary info. 117 # track the necessary info.
108 _url_utils = ['hash', 'host', 'hostname', 'origin', 118 _url_utils = ['hash', 'host', 'hostname', 'origin',
109 'password', 'pathname', 'port', 'protocol', 119 'password', 'pathname', 'port', 'protocol',
110 'search', 'username'] 120 'search', 'username']
111 _cpp_static_call_map = { 121 _cpp_static_call_map = {
112 'DOMURL': _url_utils + ['href', 'toString'], 122 'DOMURL': _url_utils + ['href', 'toString'],
113 'HTMLAnchorElement': _url_utils, 123 'HTMLAnchorElement': _url_utils,
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 create_function = 'createForJSConstructor' 386 create_function = 'createForJSConstructor'
377 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 387 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
378 self._GenerateNativeCallback( 388 self._GenerateNativeCallback(
379 constructor_callback_cpp_name, 389 constructor_callback_cpp_name,
380 False, 390 False,
381 function_expression, 391 function_expression,
382 self._interface, 392 self._interface,
383 arguments, 393 arguments,
384 self._interface.id, 394 self._interface.id,
385 False, 395 False,
386 'ConstructorRaisesException' in ext_attrs or 'RaisesException' in ext_at trs) 396 'ConstructorRaisesException' in ext_attrs or 'RaisesException' in ext_at trs,
397 True)
387 398
388 def HasSupportCheck(self): 399 def HasSupportCheck(self):
389 # Need to omit a support check if it is conditional in JS. 400 # Need to omit a support check if it is conditional in JS.
390 return self._interface.doc_js_name in js_support_checks 401 return self._interface.doc_js_name in js_support_checks
391 402
392 def GetSupportCheck(self): 403 def GetSupportCheck(self):
393 # Assume that everything is supported on Dartium. 404 # Assume that everything is supported on Dartium.
394 value = js_support_checks.get(self._interface.doc_js_name) 405 value = js_support_checks.get(self._interface.doc_js_name)
395 if type(value) == tuple: 406 if type(value) == tuple:
396 return (value[0], 'true') 407 return (value[0], 'true')
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 ' if (!value)\n' 475 ' if (!value)\n'
465 ' return Dart_Null();\n' 476 ' return Dart_Null();\n'
466 ' DartDOMData* domData = DartDOMData::current();\n' 477 ' DartDOMData* domData = DartDOMData::current();\n'
467 ' Dart_WeakPersistentHandle result =\n' 478 ' Dart_WeakPersistentHandle result =\n'
468 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData, va lue);\n' 479 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData, va lue);\n'
469 ' if (result)\n' 480 ' if (result)\n'
470 ' return Dart_HandleFromWeakPersistent(result);\n' 481 ' return Dart_HandleFromWeakPersistent(result);\n'
471 ' return createWrapper(domData, value);\n' 482 ' return createWrapper(domData, value);\n'
472 ' }\n' 483 ' }\n'
473 ' static void returnToDart(Dart_NativeArguments args,\n' 484 ' static void returnToDart(Dart_NativeArguments args,\n'
474 ' NativeType* value)\n' 485 ' NativeType* value,\n'
486 ' bool autoDartScope = true)\n'
475 ' {\n' 487 ' {\n'
476 ' if (value) {\n' 488 ' if (value) {\n'
477 ' DartDOMData* domData = static_cast<DartDOMData*>(\n' 489 ' DartDOMData* domData = static_cast<DartDOMData*>(\n'
478 ' Dart_GetNativeIsolateData(args));\n' 490 ' Dart_GetNativeIsolateData(args));\n'
479 ' Dart_WeakPersistentHandle result =\n' 491 ' Dart_WeakPersistentHandle result =\n'
480 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData , value);\n' 492 ' DartDOMWrapper::lookupWrapper<Dart$(INTERFACE)>(domData , value);\n'
481 ' if (result)\n' 493 ' if (result)\n'
482 ' Dart_SetWeakHandleReturnValue(args, result);\n' 494 ' Dart_SetWeakHandleReturnValue(args, result);\n'
483 ' else {\n' 495 ' else {\n'
484 ' DartApiScope apiScope;\n' 496 ' if (autoDartScope) {\n'
485 ' Dart_SetReturnValue(args, createWrapper(domData, value) );\n' 497 ' Dart_SetReturnValue(args, createWrapper(domData, va lue));\n'
498 ' } else {\n'
499 ' DartApiScope apiScope;\n'
500 ' Dart_SetReturnValue(args, createWrapper(domData, va lue));\n'
501 ' }\n'
486 ' }\n' 502 ' }\n'
487 ' }\n' 503 ' }\n'
488 ' }\n', 504 ' }\n',
489 INTERFACE=self._interface.id) 505 INTERFACE=self._interface.id)
490 506
491 if ('CustomToV8' in ext_attrs or 507 if ('CustomToV8' in ext_attrs or
492 'PureInterface' in ext_attrs or 508 'PureInterface' in ext_attrs or
493 'CPPPureInterface' in ext_attrs or 509 'CPPPureInterface' in ext_attrs or
494 'SpecialWrapFor' in ext_attrs or 510 'SpecialWrapFor' in ext_attrs or
495 self._interface_type_info.custom_to_dart()): 511 self._interface_type_info.custom_to_dart()):
(...skipping 28 matching lines...) Expand all
524 IS_ACTIVE=TypeCheckHelper(is_active_test), 540 IS_ACTIVE=TypeCheckHelper(is_active_test),
525 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), 541 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test),
526 TO_NATIVE=to_native_emitter.Fragments(), 542 TO_NATIVE=to_native_emitter.Fragments(),
527 TO_DART=to_dart_emitter.Fragments()) 543 TO_DART=to_dart_emitter.Fragments())
528 544
529 def EmitAttribute(self, attribute, html_name, read_only): 545 def EmitAttribute(self, attribute, html_name, read_only):
530 self._AddGetter(attribute, html_name, read_only) 546 self._AddGetter(attribute, html_name, read_only)
531 if not read_only: 547 if not read_only:
532 self._AddSetter(attribute, html_name) 548 self._AddSetter(attribute, html_name)
533 549
550 def _GenerateAutoSetupScope(self, idl_name, native_suffix):
551 return (self._interface.id, idl_name, native_suffix) not in _cpp_no_auto_sco pe_list
552
534 def _AddGetter(self, attr, html_name, read_only): 553 def _AddGetter(self, attr, html_name, read_only):
535 # Temporary hack to force dart:scalarlist clamped array for ImageData.data. 554 # Temporary hack to force dart:scalarlist clamped array for ImageData.data.
536 # TODO(antonm): solve in principled way. 555 # TODO(antonm): solve in principled way.
537 if self._interface.id == 'ImageData' and html_name == 'data': 556 if self._interface.id == 'ImageData' and html_name == 'data':
538 html_name = '_data' 557 html_name = '_data'
539 type_info = self._TypeInfo(attr.type.id) 558 type_info = self._TypeInfo(attr.type.id)
540 dart_declaration = '%s get %s' % ( 559 dart_declaration = '%s get %s' % (
541 self.SecureOutputType(attr.type.id, False, read_only), html_name) 560 self.SecureOutputType(attr.type.id, False, read_only), html_name)
542 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 561 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
562 native_suffix = 'Getter'
563 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
543 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 564 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
544 dart_declaration, 'Getter', is_custom) 565 dart_declaration, native_suffix, is_custom, auto_scope_setup)
545 if is_custom: 566 if is_custom:
546 return 567 return
547 568
548 if 'Reflect' in attr.ext_attrs: 569 if 'Reflect' in attr.ext_attrs:
549 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 570 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
550 if 'URL' in attr.ext_attrs: 571 if 'URL' in attr.ext_attrs:
551 if 'NonEmpty' in attr.ext_attrs: 572 if 'NonEmpty' in attr.ext_attrs:
552 webcore_function_name = 'getNonEmptyURLAttribute' 573 webcore_function_name = 'getNonEmptyURLAttribute'
553 else: 574 else:
554 webcore_function_name = 'getURLAttribute' 575 webcore_function_name = 'getURLAttribute'
(...skipping 11 matching lines...) Expand all
566 587
567 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 588 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
568 self._GenerateNativeCallback( 589 self._GenerateNativeCallback(
569 cpp_callback_name, 590 cpp_callback_name,
570 True, 591 True,
571 function_expression, 592 function_expression,
572 attr, 593 attr,
573 [], 594 [],
574 attr.type.id, 595 attr.type.id,
575 attr.type.nullable, 596 attr.type.nullable,
576 'GetterRaisesException' in attr.ext_attrs or 'RaisesException' in attr.e xt_attrs) 597 'GetterRaisesException' in attr.ext_attrs or 'RaisesException' in attr.e xt_attrs,
598 auto_scope_setup)
577 599
578 def _AddSetter(self, attr, html_name): 600 def _AddSetter(self, attr, html_name):
579 type_info = self._TypeInfo(attr.type.id) 601 type_info = self._TypeInfo(attr.type.id)
580 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id)) 602 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id))
581 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 603 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
604 native_suffix = 'Setter'
605 auto_scope_setup = self._GenerateAutoSetupScope(attr.id, native_suffix)
582 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 606 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
583 dart_declaration, 'Setter', is_custom) 607 dart_declaration, native_suffix, is_custom, auto_scope_setup)
584 if is_custom: 608 if is_custom:
585 return 609 return
586 610
587 if 'Reflect' in attr.ext_attrs: 611 if 'Reflect' in attr.ext_attrs:
588 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() 612 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name()
589 else: 613 else:
590 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)', 614 webcore_function_name = re.sub(r'^(xml|css|(?=[A-Z])|\w)',
591 lambda s: s.group(1).upper(), 615 lambda s: s.group(1).upper(),
592 attr.id) 616 attr.id)
593 webcore_function_name = 'set%s' % webcore_function_name 617 webcore_function_name = 'set%s' % webcore_function_name
594 618
595 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 619 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
596 self._GenerateNativeCallback( 620 self._GenerateNativeCallback(
597 cpp_callback_name, 621 cpp_callback_name,
598 True, 622 True,
599 function_expression, 623 function_expression,
600 attr, 624 attr,
601 [attr], 625 [attr],
602 'void', 626 'void',
603 False, 627 False,
604 'SetterRaisesException' in attr.ext_attrs, 628 'SetterRaisesException' in attr.ext_attrs,
629 auto_scope_setup,
605 generate_custom_element_scope_if_needed=True) 630 generate_custom_element_scope_if_needed=True)
606 631
607 def AddIndexer(self, element_type): 632 def AddIndexer(self, element_type):
608 """Adds all the methods required to complete implementation of List.""" 633 """Adds all the methods required to complete implementation of List."""
609 # We would like to simply inherit the implementation of everything except 634 # We would like to simply inherit the implementation of everything except
610 # length, [], and maybe []=. It is possible to extend from a base 635 # length, [], and maybe []=. It is possible to extend from a base
611 # array implementation class only when there is no other implementation 636 # array implementation class only when there is no other implementation
612 # inheritance. There might be no implementation inheritance other than 637 # inheritance. There might be no implementation inheritance other than
613 # DOMBaseWrapper for many classes, but there might be some where the 638 # DOMBaseWrapper for many classes, but there might be some where the
614 # array-ness is introduced by a non-root interface: 639 # array-ness is introduced by a non-root interface:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 if self._HasNativeIndexSetter(): 692 if self._HasNativeIndexSetter():
668 self._EmitNativeIndexSetter(dart_element_type) 693 self._EmitNativeIndexSetter(dart_element_type)
669 694
670 def _HasNativeIndexGetter(self): 695 def _HasNativeIndexGetter(self):
671 return 'CustomIndexedGetter' in self._interface.ext_attrs 696 return 'CustomIndexedGetter' in self._interface.ext_attrs
672 697
673 def _EmitNativeIndexGetter(self, element_type): 698 def _EmitNativeIndexGetter(self, element_type):
674 dart_declaration = '%s operator[](int index)' % \ 699 dart_declaration = '%s operator[](int index)' % \
675 self.SecureOutputType(element_type, True) 700 self.SecureOutputType(element_type, True)
676 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, 701 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration,
677 'Callback', True) 702 'Callback', True, False)
678 703
679 def _HasExplicitIndexedGetter(self): 704 def _HasExplicitIndexedGetter(self):
680 return any(op.id == 'getItem' for op in self._interface.operations) 705 return any(op.id == 'getItem' for op in self._interface.operations)
681 706
682 def _EmitExplicitIndexedGetter(self, dart_element_type): 707 def _EmitExplicitIndexedGetter(self, dart_element_type):
683 if any(op.id == 'getItem' for op in self._interface.operations): 708 if any(op.id == 'getItem' for op in self._interface.operations):
684 indexed_getter = 'getItem' 709 indexed_getter = 'getItem'
685 710
686 self._members_emitter.Emit( 711 self._members_emitter.Emit(
687 '\n' 712 '\n'
688 ' $TYPE operator[](int index) {\n' 713 ' $TYPE operator[](int index) {\n'
689 ' if (index < 0 || index >= length)\n' 714 ' if (index < 0 || index >= length)\n'
690 ' throw new RangeError.range(index, 0, length);\n' 715 ' throw new RangeError.range(index, 0, length);\n'
691 ' return $INDEXED_GETTER(index);\n' 716 ' return $INDEXED_GETTER(index);\n'
692 ' }\n', 717 ' }\n',
693 TYPE=dart_element_type, 718 TYPE=dart_element_type,
694 INDEXED_GETTER=indexed_getter) 719 INDEXED_GETTER=indexed_getter)
695 720
696 def _HasNativeIndexSetter(self): 721 def _HasNativeIndexSetter(self):
697 return 'CustomIndexedSetter' in self._interface.ext_attrs 722 return 'CustomIndexedSetter' in self._interface.ext_attrs
698 723
699 def _EmitNativeIndexSetter(self, element_type): 724 def _EmitNativeIndexSetter(self, element_type):
700 dart_declaration = 'void operator[]=(int index, %s value)' % element_type 725 dart_declaration = 'void operator[]=(int index, %s value)' % element_type
701 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, 726 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration,
702 'Callback', True) 727 'Callback', True, False)
703 728
704 def EmitOperation(self, info, html_name): 729 def EmitOperation(self, info, html_name):
705 """ 730 """
706 Arguments: 731 Arguments:
707 info: An OperationInfo object. 732 info: An OperationInfo object.
708 """ 733 """
709 734
710 dart_declaration = '%s%s %s(%s)' % ( 735 dart_declaration = '%s%s %s(%s)' % (
711 'static ' if info.IsStatic() else '', 736 'static ' if info.IsStatic() else '',
712 self.SecureOutputType(info.type_name, False, True), 737 self.SecureOutputType(info.type_name, False, True),
713 html_name, 738 html_name,
714 info.ParametersDeclaration(self._DartType)) 739 info.ParametersDeclaration(self._DartType))
715 740
716 operation = info.operations[0] 741 operation = info.operations[0]
717 is_custom = 'Custom' in operation.ext_attrs 742 is_custom = 'Custom' in operation.ext_attrs
718 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) 743 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments)
719 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 744 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
720 745
721 if info.callback_args: 746 if info.callback_args:
722 self._AddFutureifiedOperation(info, html_name) 747 self._AddFutureifiedOperation(info, html_name)
723 elif not needs_dispatcher: 748 elif not needs_dispatcher:
724 # Bind directly to native implementation 749 # Bind directly to native implementation
725 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 750 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
751 native_suffix = 'Callback'
752 auto_scope_setup = self._GenerateAutoSetupScope(info.name, native_suffix)
726 cpp_callback_name = self._GenerateNativeBinding( 753 cpp_callback_name = self._GenerateNativeBinding(
727 info.name, argument_count, dart_declaration, 'Callback', is_custom) 754 info.name, argument_count, dart_declaration, native_suffix, is_custom,
755 auto_scope_setup)
728 if not is_custom: 756 if not is_custom:
729 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name) 757 self._GenerateOperationNativeCallback(operation, operation.arguments, cp p_callback_name, auto_scope_setup)
730 else: 758 else:
731 self._GenerateDispatcher(info, info.operations, dart_declaration) 759 self._GenerateDispatcher(info, info.operations, dart_declaration)
732 760
733 def _GenerateDispatcher(self, info, operations, dart_declaration): 761 def _GenerateDispatcher(self, info, operations, dart_declaration):
734 762
735 def GenerateCall( 763 def GenerateCall(
736 stmts_emitter, call_emitter, version, operation, argument_count): 764 stmts_emitter, call_emitter, version, operation, argument_count):
737 overload_name = '_%s_%s' % (operation.id, version) 765 overload_name = '_%s_%s' % (operation.id, version)
738 argument_list = ', '.join( 766 argument_list = ', '.join(
739 [p.name for p in info.param_infos[:argument_count]]) 767 [p.name for p in info.param_infos[:argument_count]])
740 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list) 768 call_emitter.Emit('$NAME($ARGS)', NAME=overload_name, ARGS=argument_list)
741 769
742 dart_declaration = '%s%s %s(%s)' % ( 770 dart_declaration = '%s%s %s(%s)' % (
743 'static ' if operation.is_static else '', 771 'static ' if operation.is_static else '',
744 self.SecureOutputType(operation.type.id), 772 self.SecureOutputType(operation.type.id),
745 overload_name, argument_list) 773 overload_name, argument_list)
746 is_custom = 'Custom' in operation.ext_attrs 774 is_custom = 'Custom' in operation.ext_attrs
775 native_suffix = 'Callback'
776 auto_scope_setup = self._GenerateAutoSetupScope(overload_name, native_suff ix)
747 cpp_callback_name = self._GenerateNativeBinding( 777 cpp_callback_name = self._GenerateNativeBinding(
748 overload_name, (0 if operation.is_static else 1) + argument_count, 778 overload_name, (0 if operation.is_static else 1) + argument_count,
749 dart_declaration, 'Callback', is_custom, emit_metadata=False) 779 dart_declaration, 'Callback', is_custom, auto_scope_setup,
780 emit_metadata=False)
750 if not is_custom: 781 if not is_custom:
751 self._GenerateOperationNativeCallback(operation, operation.arguments[:ar gument_count], cpp_callback_name) 782 self._GenerateOperationNativeCallback(operation, operation.arguments[:ar gument_count], cpp_callback_name, auto_scope_setup)
752 783
753 self._GenerateDispatcherBody( 784 self._GenerateDispatcherBody(
754 info, 785 info,
755 operations, 786 operations,
756 dart_declaration, 787 dart_declaration,
757 GenerateCall, 788 GenerateCall,
758 self._IsArgumentOptionalInWebCore) 789 self._IsArgumentOptionalInWebCore)
759 790
760 def SecondaryContext(self, interface): 791 def SecondaryContext(self, interface):
761 pass 792 pass
762 793
763 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): 794 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name, auto_scope_setup=True):
764 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 795 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
765 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name) 796 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name)
766 self._GenerateNativeCallback( 797 self._GenerateNativeCallback(
767 cpp_callback_name, 798 cpp_callback_name,
768 not operation.is_static, 799 not operation.is_static,
769 function_expression, 800 function_expression,
770 operation, 801 operation,
771 arguments, 802 arguments,
772 operation.type.id, 803 operation.type.id,
773 operation.type.nullable, 804 operation.type.nullable,
774 'RaisesException' in operation.ext_attrs, 805 'RaisesException' in operation.ext_attrs,
806 auto_scope_setup,
775 generate_custom_element_scope_if_needed=True) 807 generate_custom_element_scope_if_needed=True)
776 808
777 def _GenerateNativeCallback(self, 809 def _GenerateNativeCallback(self,
778 callback_name, 810 callback_name,
779 needs_receiver, 811 needs_receiver,
780 function_expression, 812 function_expression,
781 node, 813 node,
782 arguments, 814 arguments,
783 return_type, 815 return_type,
784 return_type_is_nullable, 816 return_type_is_nullable,
785 raises_dom_exception, 817 raises_dom_exception,
818 auto_scope_setup=True,
786 generate_custom_element_scope_if_needed=False): 819 generate_custom_element_scope_if_needed=False):
787 820
788 ext_attrs = node.ext_attrs 821 ext_attrs = node.ext_attrs
789 if self._IsStatic(node.id): 822 if self._IsStatic(node.id):
790 needs_receiver = True 823 needs_receiver = True
791 824
792 cpp_arguments = [] 825 cpp_arguments = []
793 runtime_check = None 826 runtime_check = None
794 raises_exceptions = raises_dom_exception or arguments 827 raises_exceptions = raises_dom_exception or arguments
795 needs_custom_element_callbacks = False 828 needs_custom_element_callbacks = False
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 1037
1005 if AllowsNull(): 1038 if AllowsNull():
1006 function += 'WithNullCheck' 1039 function += 'WithNullCheck'
1007 1040
1008 argument_name = DartDomNameOfAttribute(argument) 1041 argument_name = DartDomNameOfAttribute(argument)
1009 if type_info.pass_native_by_ref(): 1042 if type_info.pass_native_by_ref():
1010 invocation_template =\ 1043 invocation_template =\
1011 ' $TYPE $ARGUMENT_NAME;\n'\ 1044 ' $TYPE $ARGUMENT_NAME;\n'\
1012 ' $CLS::$FUNCTION(args, $INDEX, $ARGUMENT_NAME, exception);\n ' 1045 ' $CLS::$FUNCTION(args, $INDEX, $ARGUMENT_NAME, exception);\n '
1013 else: 1046 else:
1014 invocation_template =\ 1047 if not auto_scope_setup and type_info.native_type() == 'String':
1015 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, except ion);\n' 1048 invocation_template =\
1049 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, exce ption, false);\n'
1050 else:
1051 invocation_template =\
1052 ' $TYPE $ARGUMENT_NAME = $CLS::$FUNCTION(args, $INDEX, exce ption);\n'
1016 body_emitter.Emit( 1053 body_emitter.Emit(
1017 '\n' + 1054 '\n' +
1018 invocation_template + 1055 invocation_template +
1019 ' if (exception)\n' 1056 ' if (exception)\n'
1020 ' goto fail;\n', 1057 ' goto fail;\n',
1021 TYPE=type, 1058 TYPE=type,
1022 ARGUMENT_NAME=argument_name, 1059 ARGUMENT_NAME=argument_name,
1023 CLS=cls, 1060 CLS=cls,
1024 FUNCTION=function, 1061 FUNCTION=function,
1025 INDEX=start_index + i) 1062 INDEX=start_index + i)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 if return_type_info.native_type() == 'unsigned': 1121 if return_type_info.native_type() == 'unsigned':
1085 set_return_value = 'DartUtilities::setDartUnsignedReturnValue(args, %s )' % (value_expression) 1122 set_return_value = 'DartUtilities::setDartUnsignedReturnValue(args, %s )' % (value_expression)
1086 elif return_type_info.native_type() == 'unsigned long long': 1123 elif return_type_info.native_type() == 'unsigned long long':
1087 set_return_value = 'DartUtilities::setDartUnsignedLongLongReturnValue( args, %s)' % (value_expression) 1124 set_return_value = 'DartUtilities::setDartUnsignedLongLongReturnValue( args, %s)' % (value_expression)
1088 else: 1125 else:
1089 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long') 1126 assert (return_type_info.native_type() == 'int' or return_type_info.na tive_type() == 'long long')
1090 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression) 1127 set_return_value = 'DartUtilities::setDartIntegerReturnValue(args, %s) ' % (value_expression)
1091 elif return_type_info.dart_type() == 'double': 1128 elif return_type_info.dart_type() == 'double':
1092 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) 1129 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1093 elif return_type_info.dart_type() == 'String': 1130 elif return_type_info.dart_type() == 'String':
1131 auto_dart_scope='true' if auto_scope_setup else 'false'
1094 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs: 1132 if ext_attrs and 'TreatReturnedNullStringAs' in ext_attrs:
1095 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s)' % (value_expression) 1133 set_return_value = 'DartUtilities::setDartStringReturnValueWithNullChe ck(args, %s, %s)' % (value_expression, auto_dart_scope)
1096 else: 1134 else:
1097 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s)' % (value_expression) 1135 set_return_value = 'DartUtilities::setDartStringReturnValue(args, %s, %s)' % (value_expression, auto_dart_scope)
1098 elif return_type_info.dart_type() == 'num' and return_type_info.native_typ e() == 'double': 1136 elif return_type_info.dart_type() == 'num' and return_type_info.native_typ e() == 'double':
1099 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion) 1137 set_return_value = 'Dart_SetDoubleReturnValue(args, %s)' % (value_expres sion)
1100 else: 1138 else:
1101 return_to_dart_conversion = return_type_info.return_to_dart_conversion( 1139 return_to_dart_conversion = return_type_info.return_to_dart_conversion(
1102 value_expression, 1140 value_expression,
1141 auto_scope_setup,
1103 self._interface.id, 1142 self._interface.id,
1104 ext_attrs) 1143 ext_attrs)
1105 set_return_value = '%s' % (return_to_dart_conversion) 1144 set_return_value = '%s' % (return_to_dart_conversion)
1106 invocation_emitter.Emit( 1145 invocation_emitter.Emit(
1107 ' $RETURN_VALUE;\n', 1146 ' $RETURN_VALUE;\n',
1108 RETURN_VALUE=set_return_value) 1147 RETURN_VALUE=set_return_value)
1109 1148
1110 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 1149 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
1111 native_suffix, is_custom, emit_metadata=True): 1150 native_suffix, is_custom, auto_scope_setup=True, emit_metadata=True):
1112
1113 def _GenerateAutoSetupScope(self, idl_name, native_suffix):
1114 if ((self._interface.id, idl_name, native_suffix) not in _cpp_no_auto_scop e_list):
1115 return 'true'
1116 return 'false'
1117 1151
1118 metadata = [] 1152 metadata = []
1119 if emit_metadata: 1153 if emit_metadata:
1120 metadata = self._metadata.GetFormattedMetadata( 1154 metadata = self._metadata.GetFormattedMetadata(
1121 self._renamer.GetLibraryName(self._interface), 1155 self._renamer.GetLibraryName(self._interface),
1122 self._interface, idl_name, ' ') 1156 self._interface, idl_name, ' ')
1123 1157
1124 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 1158 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
1125 self._members_emitter.Emit( 1159 self._members_emitter.Emit(
1126 '\n' 1160 '\n'
1127 ' $METADATA$DART_DECLARATION native "$NATIVE_BINDING";\n', 1161 ' $METADATA$DART_DECLARATION native "$NATIVE_BINDING";\n',
1128 DOMINTERFACE=self._interface.id, 1162 DOMINTERFACE=self._interface.id,
1129 METADATA=metadata, 1163 METADATA=metadata,
1130 DART_DECLARATION=dart_declaration, 1164 DART_DECLARATION=dart_declaration,
1131 NATIVE_BINDING=native_binding) 1165 NATIVE_BINDING=native_binding)
1132 1166
1133 cpp_callback_name = '%s%s' % (idl_name, native_suffix) 1167 cpp_callback_name = '%s%s' % (idl_name, native_suffix)
1134 auto_scope_setup = _GenerateAutoSetupScope(self, idl_name, native_suffix)
1135 1168
1136 self._cpp_resolver_emitter.Emit( 1169 self._cpp_resolver_emitter.Emit(
1137 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n' 1170 ' if (argumentCount == $ARGC && name == "$NATIVE_BINDING") {\n'
1138 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n' 1171 ' *autoSetupScope = $AUTO_SCOPE_SETUP;\n'
1139 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n' 1172 ' return Dart$(INTERFACE_NAME)Internal::$CPP_CALLBACK_NAME;\n'
1140 ' }\n', 1173 ' }\n',
1141 ARGC=argument_count, 1174 ARGC=argument_count,
1142 NATIVE_BINDING=native_binding, 1175 NATIVE_BINDING=native_binding,
1143 INTERFACE_NAME=self._interface.id, 1176 INTERFACE_NAME=self._interface.id,
1144 AUTO_SCOPE_SETUP=auto_scope_setup, 1177 AUTO_SCOPE_SETUP='true' if auto_scope_setup else 'false',
1145 CPP_CALLBACK_NAME=cpp_callback_name) 1178 CPP_CALLBACK_NAME=cpp_callback_name)
1146 1179
1147 if is_custom: 1180 if is_custom:
1148 self._cpp_declarations_emitter.Emit( 1181 self._cpp_declarations_emitter.Emit(
1149 '\n' 1182 '\n'
1150 'void $CPP_CALLBACK_NAME(Dart_NativeArguments);\n', 1183 'void $CPP_CALLBACK_NAME(Dart_NativeArguments);\n',
1151 CPP_CALLBACK_NAME=cpp_callback_name) 1184 CPP_CALLBACK_NAME=cpp_callback_name)
1152 1185
1153 return cpp_callback_name 1186 return cpp_callback_name
1154 1187
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 e.Emit("};\n"); 1377 e.Emit("};\n");
1345 e.Emit('\n'); 1378 e.Emit('\n');
1346 e.Emit('} // namespace WebCore\n'); 1379 e.Emit('} // namespace WebCore\n');
1347 1380
1348 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1381 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1349 return ( 1382 return (
1350 interface.id.endswith('Event') and 1383 interface.id.endswith('Event') and
1351 operation.id.startswith('init') and 1384 operation.id.startswith('init') and
1352 argument.ext_attrs.get('Default') == 'Undefined' and 1385 argument.ext_attrs.get('Default') == 'Undefined' and
1353 argument.type.id == 'DOMString') 1386 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/templates/html/dartium/cpp_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698