| 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 systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import re | 10 import re |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 # interface and member name, and by IDL return or field type name. Both are | 506 # interface and member name, and by IDL return or field type name. Both are |
| 507 # used to assemble the annotations: | 507 # used to assemble the annotations: |
| 508 # | 508 # |
| 509 # INTERFACE.MEMBER: annotations for member. | 509 # INTERFACE.MEMBER: annotations for member. |
| 510 # +TYPE: add annotations only if there are member annotations. | 510 # +TYPE: add annotations only if there are member annotations. |
| 511 # -TYPE: add annotations only if there are no member annotations. | 511 # -TYPE: add annotations only if there are no member annotations. |
| 512 # TYPE: add regardless of member annotations. | 512 # TYPE: add regardless of member annotations. |
| 513 | 513 |
| 514 dart2js_annotations = { | 514 dart2js_annotations = { |
| 515 | 515 |
| 516 'CanvasRenderingContext2D.createImageData': | 516 'CanvasRenderingContext2D.createImageData': [ |
| 517 "@Creates('ImageData|=Object')", | 517 "@Creates('ImageData|=Object')", |
| 518 ], |
| 518 | 519 |
| 519 'CanvasRenderingContext2D.getImageData': | 520 'CanvasRenderingContext2D.getImageData': [ |
| 520 "@Creates('ImageData|=Object')", | 521 "@Creates('ImageData|=Object')", |
| 522 ], |
| 521 | 523 |
| 522 'CanvasRenderingContext2D.webkitGetImageDataHD': | 524 'CanvasRenderingContext2D.webkitGetImageDataHD': [ |
| 523 "@Creates('ImageData|=Object')", | 525 "@Creates('ImageData|=Object')", |
| 526 ], |
| 524 | 527 |
| 525 'CanvasRenderingContext2D.fillStyle': | 528 'CanvasRenderingContext2D.fillStyle': [ |
| 526 "@Creates('String|CanvasGradient|CanvasPattern') " | 529 "@Creates('String|CanvasGradient|CanvasPattern')", |
| 527 "@Returns('String|CanvasGradient|CanvasPattern')", | 530 "@Returns('String|CanvasGradient|CanvasPattern')", |
| 531 ], |
| 528 | 532 |
| 529 'CanvasRenderingContext2D.strokeStyle': | 533 'CanvasRenderingContext2D.strokeStyle': [ |
| 530 "@Creates('String|CanvasGradient|CanvasPattern') " | 534 "@Creates('String|CanvasGradient|CanvasPattern')", |
| 531 "@Returns('String|CanvasGradient|CanvasPattern')", | 535 "@Returns('String|CanvasGradient|CanvasPattern')", |
| 536 ], |
| 532 | 537 |
| 533 # Methods returning Window can return a local window, or a cross-frame | 538 # Methods returning Window can return a local window, or a cross-frame |
| 534 # window (=Object) that needs wrapping. | 539 # window (=Object) that needs wrapping. |
| 535 'DOMWindow': | 540 'DOMWindow': [ |
| 536 "@Creates('Window|=Object') @Returns('Window|=Object')", | 541 "@Creates('Window|=Object')", |
| 542 "@Returns('Window|=Object')", |
| 543 ], |
| 537 | 544 |
| 538 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", | 545 'DOMWindow.openDatabase': [ |
| 546 "@Creates('Database')", |
| 547 "@Creates('DatabaseSync')", |
| 548 ], |
| 539 | 549 |
| 540 # Cross-frame windows are EventTargets. | 550 # Cross-frame windows are EventTargets. |
| 541 '-EventTarget': | 551 '-EventTarget': [ |
| 542 "@Creates('EventTarget|=Object') @Returns('EventTarget|=Object')", | 552 "@Creates('EventTarget|=Object')", |
| 553 "@Returns('EventTarget|=Object')", |
| 554 ], |
| 543 | 555 |
| 544 # To be in callback with the browser-created Event, we had to have called | 556 # To be in callback with the browser-created Event, we had to have called |
| 545 # addEventListener on the target, so we avoid | 557 # addEventListener on the target, so we avoid |
| 546 'Event.currentTarget': | 558 'Event.currentTarget': [ |
| 547 "@Creates('Null') @Returns('EventTarget|=Object')", | 559 "@Creates('Null')", |
| 560 "@Returns('EventTarget|=Object')", |
| 561 ], |
| 548 | 562 |
| 549 # Only nodes in the DOM bubble and have target !== currentTarget. | 563 # Only nodes in the DOM bubble and have target !== currentTarget. |
| 550 'Event.target': | 564 'Event.target': [ |
| 551 "@Creates('Node') @Returns('EventTarget|=Object')", | 565 "@Creates('Node')", |
| 566 "@Returns('EventTarget|=Object')", |
| 567 ], |
| 552 | 568 |
| 553 'MouseEvent.relatedTarget': | 569 'MouseEvent.relatedTarget': [ |
| 554 "@Creates('Node') @Returns('EventTarget|=Object')", | 570 "@Creates('Node')", |
| 571 "@Returns('EventTarget|=Object')", |
| 572 ], |
| 555 | 573 |
| 556 # Touch targets are Elements in a Document, or the Document. | 574 # Touch targets are Elements in a Document, or the Document. |
| 557 'Touch.target': | 575 'Touch.target': [ |
| 558 "@Creates('Element|Document') @Returns('Element|Document')", | 576 "@Creates('Element|Document')", |
| 577 "@Returns('Element|Document')", |
| 578 ], |
| 559 | 579 |
| 560 | 580 |
| 561 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", | 581 'FileReader.result': ["@Creates('String|ArrayBuffer|Null')"], |
| 562 | 582 |
| 563 # Rather than have the result of an IDBRequest as a union over all possible | 583 # Rather than have the result of an IDBRequest as a union over all possible |
| 564 # results, we mark the result as instantiating any classes, and mark | 584 # results, we mark the result as instantiating any classes, and mark |
| 565 # each operation with the classes that it could cause to be asynchronously | 585 # each operation with the classes that it could cause to be asynchronously |
| 566 # instantiated. | 586 # instantiated. |
| 567 'IDBRequest.result': "@Creates('Null')", | 587 'IDBRequest.result': ["@Creates('Null')"], |
| 568 | 588 |
| 569 # The source is usually a participant in the operation that generated the | 589 # The source is usually a participant in the operation that generated the |
| 570 # IDBRequest. | 590 # IDBRequest. |
| 571 'IDBRequest.source': "@Creates('Null')", | 591 'IDBRequest.source': ["@Creates('Null')"], |
| 572 | 592 |
| 573 'IDBFactory.open': "@Creates('Database')", | 593 'IDBFactory.open': ["@Creates('Database')"], |
| 574 | 594 |
| 575 'IDBObjectStore.put': "@_annotation_Creates_IDBKey", | 595 'IDBObjectStore.put': ["@_annotation_Creates_IDBKey"], |
| 576 'IDBObjectStore.add': "@_annotation_Creates_IDBKey", | 596 'IDBObjectStore.add': ["@_annotation_Creates_IDBKey"], |
| 577 'IDBObjectStore.get': "@annotation_Creates_SerializedScriptValue", | 597 'IDBObjectStore.get': ["@annotation_Creates_SerializedScriptValue"], |
| 578 'IDBObjectStore.openCursor': "@Creates('Cursor')", | 598 'IDBObjectStore.openCursor': ["@Creates('Cursor')"], |
| 579 | 599 |
| 580 'IDBIndex.get': "@annotation_Creates_SerializedScriptValue", | 600 'IDBIndex.get': ["@annotation_Creates_SerializedScriptValue"], |
| 581 'IDBIndex.getKey': | 601 'IDBIndex.getKey': [ |
| 582 "@annotation_Creates_SerializedScriptValue " | 602 "@annotation_Creates_SerializedScriptValue", |
| 583 # The source is the object store behind the index. | 603 # The source is the object store behind the index. |
| 584 "@Creates('ObjectStore')", | 604 "@Creates('ObjectStore')", |
| 585 'IDBIndex.openCursor': "@Creates('Cursor')", | 605 ], |
| 586 'IDBIndex.openKeyCursor': "@Creates('Cursor')", | 606 'IDBIndex.openCursor': ["@Creates('Cursor')"], |
| 607 'IDBIndex.openKeyCursor': ["@Creates('Cursor')"], |
| 587 | 608 |
| 588 'IDBCursorWithValue.value': | 609 'IDBCursorWithValue.value': [ |
| 589 '@annotation_Creates_SerializedScriptValue ' | 610 '@annotation_Creates_SerializedScriptValue', |
| 590 '@annotation_Returns_SerializedScriptValue', | 611 '@annotation_Returns_SerializedScriptValue', |
| 612 ], |
| 591 | 613 |
| 592 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", | 614 'IDBCursor.key': [ |
| 615 "@_annotation_Creates_IDBKey", |
| 616 "@_annotation_Returns_IDBKey", |
| 617 ], |
| 593 | 618 |
| 594 '+IDBRequest': "@Returns('Request') @Creates('Request')", | 619 '+IDBRequest': [ |
| 620 "@Returns('Request')", |
| 621 "@Creates('Request')", |
| 622 ], |
| 595 | 623 |
| 596 '+IDBOpenDBRequest': "@Returns('Request') @Creates('Request')", | 624 '+IDBOpenDBRequest': [ |
| 597 '+IDBVersionChangeRequest': "@Returns('Request') @Creates('Request')", | 625 "@Returns('Request')", |
| 626 "@Creates('Request')", |
| 627 ], |
| 628 '+IDBVersionChangeRequest': [ |
| 629 "@Returns('Request')", |
| 630 "@Creates('Request')", |
| 631 ], |
| 598 | 632 |
| 633 'MessageEvent.ports': ["@Creates('=List')"], |
| 599 | 634 |
| 600 'MessageEvent.ports': "@Creates('=List')", | 635 'MessageEvent.data': [ |
| 636 "@annotation_Creates_SerializedScriptValue", |
| 637 "@annotation_Returns_SerializedScriptValue", |
| 638 ], |
| 639 'PopStateEvent.state': [ |
| 640 "@annotation_Creates_SerializedScriptValue", |
| 641 "@annotation_Returns_SerializedScriptValue", |
| 642 ], |
| 643 'SerializedScriptValue': [ |
| 644 "@annotation_Creates_SerializedScriptValue", |
| 645 "@annotation_Returns_SerializedScriptValue", |
| 646 ], |
| 601 | 647 |
| 602 'MessageEvent.data': | 648 'SQLResultSetRowList.item': ["@Creates('=Object')"], |
| 603 "@annotation_Creates_SerializedScriptValue " | |
| 604 "@annotation_Returns_SerializedScriptValue", | |
| 605 'PopStateEvent.state': | |
| 606 "@annotation_Creates_SerializedScriptValue " | |
| 607 "@annotation_Returns_SerializedScriptValue", | |
| 608 'SerializedScriptValue': | |
| 609 "@annotation_Creates_SerializedScriptValue " | |
| 610 "@annotation_Returns_SerializedScriptValue", | |
| 611 | 649 |
| 612 'SQLResultSetRowList.item': "@Creates('=Object')", | 650 'XMLHttpRequest.response': [ |
| 613 | |
| 614 'XMLHttpRequest.response': | |
| 615 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", | 651 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", |
| 652 ], |
| 616 } | 653 } |
| 617 | 654 |
| 618 # Placeholder to add experimental flag, implementation for this is | 655 # Placeholder to add experimental flag, implementation for this is |
| 619 # pending in a separate CL. | 656 # pending in a separate CL. |
| 620 dart_annotations = { | 657 dart_annotations = { |
| 621 'Element.webkitMatchesSelector': ['@Experimental()'], | 658 'Element.webkitMatchesSelector': ['@Experimental()'], |
| 622 } | 659 } |
| 623 | 660 |
| 624 _indexed_db_annotations = [ | 661 _indexed_db_annotations = [ |
| 625 "@SupportedBrowser(SupportedBrowser.CHROME)", | 662 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", | 750 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", |
| 714 "@Experimental()", | 751 "@Experimental()", |
| 715 ], | 752 ], |
| 716 'HTMLTrackElement': [ | 753 'HTMLTrackElement': [ |
| 717 "@SupportedBrowser(SupportedBrowser.CHROME)", | 754 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| 718 "@SupportedBrowser(SupportedBrowser.IE, '10')", | 755 "@SupportedBrowser(SupportedBrowser.IE, '10')", |
| 719 "@SupportedBrowser(SupportedBrowser.SAFARI)", | 756 "@SupportedBrowser(SupportedBrowser.SAFARI)", |
| 720 ], | 757 ], |
| 721 'IDBFactory': _indexed_db_annotations, | 758 'IDBFactory': _indexed_db_annotations, |
| 722 'IDBDatabase': _indexed_db_annotations, | 759 'IDBDatabase': _indexed_db_annotations, |
| 760 'MutationObserver': [ |
| 761 "@SupportedBrowser(SupportedBrowser.CHROME)", |
| 762 "@SupportedBrowser(SupportedBrowser.FIREFOX)", |
| 763 "@SupportedBrowser(SupportedBrowser.SAFARI)", |
| 764 "@Experimental()", |
| 765 ], |
| 723 'NotificationCenter': _webkit_experimental_annotations, | 766 'NotificationCenter': _webkit_experimental_annotations, |
| 724 'Performance': _performance_annotations, | 767 'Performance': _performance_annotations, |
| 725 'ShadowRoot': [ | 768 'ShadowRoot': [ |
| 726 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", | 769 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", |
| 727 "@Experimental()", | 770 "@Experimental()", |
| 728 ], | 771 ], |
| 729 'WebSocket': _all_but_ie9_annotations, | 772 'WebSocket': _all_but_ie9_annotations, |
| 730 'WorkerContext.indexedDB': _indexed_db_annotations, | 773 'WorkerContext.indexedDB': _indexed_db_annotations, |
| 731 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, | 774 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, |
| 732 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, | 775 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 747 if (dart_annotations.get(key) != None): | 790 if (dart_annotations.get(key) != None): |
| 748 annotations.extend(dart_annotations.get(key)) | 791 annotations.extend(dart_annotations.get(key)) |
| 749 | 792 |
| 750 return annotations | 793 return annotations |
| 751 | 794 |
| 752 def FindDart2JSAnnotations(idl_type, interface_name, member_name): | 795 def FindDart2JSAnnotations(idl_type, interface_name, member_name): |
| 753 """ Finds all annotations for Dart2JS members- including annotations for | 796 """ Finds all annotations for Dart2JS members- including annotations for |
| 754 both dart2js and dartium. | 797 both dart2js and dartium. |
| 755 """ | 798 """ |
| 756 annotations = FindCommonAnnotations(interface_name, member_name) | 799 annotations = FindCommonAnnotations(interface_name, member_name) |
| 757 if annotations: | |
| 758 annotations = ' '.join(annotations) | |
| 759 | 800 |
| 760 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) | 801 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) |
| 761 if ann2: | 802 if ann2: |
| 762 if annotations: | 803 if annotations: |
| 763 annotations = annotations + ' ' + ann2 | 804 annotations.extend(ann2) |
| 764 else: | 805 else: |
| 765 annotations = ann2 | 806 annotations = ann2 |
| 766 return annotations | 807 return annotations |
| 767 | 808 |
| 768 def AnyConversionAnnotations(idl_type, interface_name, member_name): | 809 def AnyConversionAnnotations(idl_type, interface_name, member_name): |
| 769 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or | 810 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or |
| 770 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): | 811 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): |
| 771 return True | 812 return True |
| 772 else: | 813 else: |
| 773 return False | 814 return False |
| 774 | 815 |
| 816 def FormatAnnotations(annotations, indentation): |
| 817 if annotations: |
| 818 newline = '\n%s' % indentation |
| 819 result = newline.join(annotations) + newline |
| 820 return result |
| 821 return '' |
| 822 |
| 775 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): | 823 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): |
| 776 """ Finds dart2js-specific annotations. This does not include ones shared with | 824 """ Finds dart2js-specific annotations. This does not include ones shared with |
| 777 dartium. | 825 dartium. |
| 778 """ | 826 """ |
| 779 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | 827 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) |
| 780 if ann1: | 828 if ann1: |
| 781 ann2 = dart2js_annotations.get('+' + idl_type) | 829 ann2 = dart2js_annotations.get('+' + idl_type) |
| 782 if ann2: | 830 if ann2: |
| 783 return ann2 + ' ' + ann1 | 831 return ann1.extend(ann2) |
| 784 ann2 = dart2js_annotations.get(idl_type) | 832 ann2 = dart2js_annotations.get(idl_type) |
| 785 if ann2: | 833 if ann2: |
| 786 return ann2 + ' ' + ann1 | 834 return ann1.extend(ann2) |
| 787 return ann1 | 835 return ann1 |
| 788 | 836 |
| 789 ann2 = dart2js_annotations.get('-' + idl_type) | 837 ann2 = dart2js_annotations.get('-' + idl_type) |
| 790 if ann2: | 838 if ann2: |
| 791 return ann2 | 839 return ann2 |
| 792 ann2 = dart2js_annotations.get(idl_type) | 840 ann2 = dart2js_annotations.get(idl_type) |
| 793 return ann2 | 841 return ann2 |
| 794 | 842 |
| 795 # ------------------------------------------------------------------------------ | 843 # ------------------------------------------------------------------------------ |
| 796 | 844 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 self) | 1367 self) |
| 1320 | 1368 |
| 1321 if type_data.clazz == 'SVGTearOff': | 1369 if type_data.clazz == 'SVGTearOff': |
| 1322 dart_interface_name = self._renamer.RenameInterface( | 1370 dart_interface_name = self._renamer.RenameInterface( |
| 1323 self._database.GetInterface(type_name)) | 1371 self._database.GetInterface(type_name)) |
| 1324 return SVGTearOffIDLTypeInfo( | 1372 return SVGTearOffIDLTypeInfo( |
| 1325 type_name, type_data, dart_interface_name, self) | 1373 type_name, type_data, dart_interface_name, self) |
| 1326 | 1374 |
| 1327 class_name = '%sIDLTypeInfo' % type_data.clazz | 1375 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1328 return globals()[class_name](type_name, type_data) | 1376 return globals()[class_name](type_name, type_data) |
| OLD | NEW |