| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 'any set IDBObjectStore.put': _serialize_SSV, | 538 'any set IDBObjectStore.put': _serialize_SSV, |
| 539 'any set IDBCursor.update': _serialize_SSV, | 539 'any set IDBCursor.update': _serialize_SSV, |
| 540 | 540 |
| 541 # postMessage | 541 # postMessage |
| 542 'any set DedicatedWorkerContext.postMessage': _serialize_SSV, | 542 'any set DedicatedWorkerContext.postMessage': _serialize_SSV, |
| 543 'any set MessagePort.postMessage': _serialize_SSV, | 543 'any set MessagePort.postMessage': _serialize_SSV, |
| 544 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV, | 544 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV, |
| 545 'SerializedScriptValue set Worker.postMessage': _serialize_SSV, | 545 'SerializedScriptValue set Worker.postMessage': _serialize_SSV, |
| 546 | 546 |
| 547 # receiving message via MessageEvent | 547 # receiving message via MessageEvent |
| 548 '* get MessageEvent.data': | 548 'DOMObject get MessageEvent.data': |
| 549 Conversion('_convertNativeToDart_SerializedScriptValue', | 549 Conversion('_convertNativeToDart_SerializedScriptValue', |
| 550 'dynamic', 'dynamic'), | 550 'dynamic', 'dynamic'), |
| 551 | 551 |
| 552 '* get History.state': | 552 'DOMObject get PopStateEvent.state': |
| 553 Conversion('_convertNativeToDart_SerializedScriptValue', | 553 Conversion('_convertNativeToDart_SerializedScriptValue', |
| 554 'dynamic', 'dynamic'), | 554 'dynamic', 'dynamic'), |
| 555 | 555 |
| 556 '* get PopStateEvent.state': | |
| 557 Conversion('_convertNativeToDart_SerializedScriptValue', | |
| 558 'dynamic', 'dynamic'), | |
| 559 | |
| 560 # IDBAny is problematic. Some uses are just a union of other IDB types, | 556 # IDBAny is problematic. Some uses are just a union of other IDB types, |
| 561 # which need no conversion.. Others include data values which require | 557 # which need no conversion.. Others include data values which require |
| 562 # serialized script value processing. | 558 # serialized script value processing. |
| 563 'IDBAny get IDBCursorWithValue.value': | 559 'IDBAny get IDBCursorWithValue.value': |
| 564 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), | 560 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), |
| 565 | 561 |
| 566 # This is problematic. The result property of IDBRequest is used for | 562 # This is problematic. The result property of IDBRequest is used for |
| 567 # all requests. Read requests like IDBDataStore.getObject need | 563 # all requests. Read requests like IDBDataStore.getObject need |
| 568 # conversion, but other requests like opening a database return | 564 # conversion, but other requests like opening a database return |
| 569 # something that does not need conversion. | 565 # something that does not need conversion. |
| 570 'IDBAny get IDBRequest.result': | 566 'IDBAny get IDBRequest.result': |
| 571 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), | 567 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), |
| 572 | 568 |
| 573 # "source: On getting, returns the IDBObjectStore or IDBIndex that the | 569 # "source: On getting, returns the IDBObjectStore or IDBIndex that the |
| 574 # cursor is iterating. ...". So we should not try to convert it. | 570 # cursor is iterating. ...". So we should not try to convert it. |
| 575 'IDBAny get IDBCursor.source': None, | 571 'IDBAny get IDBCursor.source': None, |
| 576 | 572 |
| 577 # Should be either a DOMString, an Array of DOMStrings or null. | 573 # Should be either a DOMString, an Array of DOMStrings or null. |
| 578 'IDBAny get IDBObjectStore.keyPath': None, | 574 'IDBAny get IDBObjectStore.keyPath': None, |
| 579 } | 575 } |
| 580 | 576 |
| 581 def FindConversion(idl_type, direction, interface, member): | 577 def FindConversion(idl_type, direction, interface, member): |
| 582 table = dart2js_conversions | 578 table = dart2js_conversions |
| 583 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or | 579 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or |
| 584 table.get('* %s %s.%s' % (direction, interface, member)) or | |
| 585 table.get('%s %s %s.*' % (idl_type, direction, interface)) or | 580 table.get('%s %s %s.*' % (idl_type, direction, interface)) or |
| 586 table.get('%s %s' % (idl_type, direction))) | 581 table.get('%s %s' % (idl_type, direction))) |
| 587 return None | 582 return None |
| 588 | 583 |
| 589 # ------------------------------------------------------------------------------ | 584 # ------------------------------------------------------------------------------ |
| 590 | 585 |
| 591 # Annotations to be placed on native members. The table is indexed by the IDL | 586 # Annotations to be placed on members. The table is indexed by the IDL |
| 592 # interface and member name, and by IDL return or field type name. Both are | 587 # interface and member name, and by IDL return or field type name. Both are |
| 593 # used to assemble the annotations: | 588 # used to assemble the annotations: |
| 594 # | 589 # |
| 595 # INTERFACE.MEMBER: annotations for member. | 590 # INTERFACE.MEMBER: annotations for member. |
| 596 # +TYPE: add annotations only if there are member annotations. | 591 # +TYPE: add annotations only if there are member annotations. |
| 597 # TYPE: add regardless of member annotations. | 592 # TYPE: add regardless of member annotations. |
| 598 | 593 |
| 599 dart2js_annotations = { | 594 dart2js_annotations = { |
| 600 | 595 |
| 601 'CanvasRenderingContext2D.createImageData': | 596 'CanvasRenderingContext2D.createImageData': |
| 602 "@Creates('ImageData|=Object')", | 597 "@Creates('ImageData|=Object')", |
| 603 | 598 |
| 604 'CanvasRenderingContext2D.getImageData': | 599 'CanvasRenderingContext2D.getImageData': |
| 605 "@Creates('ImageData|=Object')", | 600 "@Creates('ImageData|=Object')", |
| 606 | 601 |
| 607 'CanvasRenderingContext2D.webkitGetImageDataHD': | 602 'CanvasRenderingContext2D.webkitGetImageDataHD': |
| 608 "@Creates('ImageData|=Object')", | 603 "@Creates('ImageData|=Object')", |
| 609 | 604 |
| 610 # Methods returning Window can return a local window, or a cross-frame | |
| 611 # window (=Object) that needs wrapping. | |
| 612 'DOMWindow': | |
| 613 "@Creates('LocalWindow|=Object') @Returns('LocalWindow|=Object')", | |
| 614 | |
| 615 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", | 605 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", |
| 616 | 606 |
| 617 # Cross-frame windows are EventTargets. | |
| 618 'EventTarget': | |
| 619 #"@Creates('Null') @Returns('EventTarget|=Object')", | |
| 620 "@Creates('EventTarget|=Object') @Returns('EventTarget|=Object')", | |
| 621 | |
| 622 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", | 607 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", |
| 623 | 608 |
| 624 # Rather than have the result of an IDBRequest as a union over all possible | 609 # Rather than have the result of an IDBRequest as a union over all possible |
| 625 # results, we mark the result as instantiating any classes, and mark | 610 # results, we mark the result as instantiating any classes, and mark |
| 626 # each operation with the classes that it could cause to be asynchronously | 611 # each operation with the classes that it could cause to be asynchronously |
| 627 # instantiated. | 612 # instantiated. |
| 628 'IDBRequest.result': "@Creates('Null')", | 613 'IDBRequest.result': "@Creates('Null')", |
| 629 | 614 |
| 630 # The source is usually a participant in the operation that generated the | 615 # The source is usually a participant in the operation that generated the |
| 631 # IDBRequest. | 616 # IDBRequest. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 653 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", | 638 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", |
| 654 | 639 |
| 655 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 640 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 656 | 641 |
| 657 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 642 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 658 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 643 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 659 | 644 |
| 660 | 645 |
| 661 'MessageEvent.ports': "@Creates('=List')", | 646 'MessageEvent.ports': "@Creates('=List')", |
| 662 | 647 |
| 663 'MessageEvent.data': | |
| 664 "@_annotation_Creates_SerializedScriptValue " | |
| 665 "@_annotation_Returns_SerializedScriptValue", | |
| 666 'PopStateEvent.state': | |
| 667 "@_annotation_Creates_SerializedScriptValue " | |
| 668 "@_annotation_Returns_SerializedScriptValue", | |
| 669 'SerializedScriptValue': | |
| 670 "@_annotation_Creates_SerializedScriptValue " | |
| 671 "@_annotation_Returns_SerializedScriptValue", | |
| 672 | |
| 673 'SQLResultSetRowList.item': "@Creates('=Object')", | 648 'SQLResultSetRowList.item': "@Creates('=Object')", |
| 674 | 649 |
| 675 'XMLHttpRequest.response': | 650 'XMLHttpRequest.response': |
| 676 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", | 651 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", |
| 677 } | 652 } |
| 678 | 653 |
| 679 def FindAnnotations(idl_type, interface_name, member_name): | 654 def FindAnnotations(idl_type, interface_name, member_name): |
| 680 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | 655 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) |
| 681 if ann1: | 656 if ann1: |
| 682 ann2 = dart2js_annotations.get('+' + idl_type) | 657 ann2 = dart2js_annotations.get('+' + idl_type) |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 'FileList': TypeData(clazz='Interface', item_type='File', | 1089 'FileList': TypeData(clazz='Interface', item_type='File', |
| 1115 suppress_interface=True), | 1090 suppress_interface=True), |
| 1116 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', | 1091 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', |
| 1117 suppress_interface=True), | 1092 suppress_interface=True), |
| 1118 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'), | 1093 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'), |
| 1119 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'), | 1094 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'), |
| 1120 'MediaStreamList': TypeData(clazz='Interface', | 1095 'MediaStreamList': TypeData(clazz='Interface', |
| 1121 item_type='MediaStream', suppress_interface=True), | 1096 item_type='MediaStream', suppress_interface=True), |
| 1122 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'), | 1097 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'), |
| 1123 'NodeList': TypeData(clazz='Interface', item_type='Node', | 1098 'NodeList': TypeData(clazz='Interface', item_type='Node', |
| 1124 suppress_interface=False, dart_type='List<Node>'), | 1099 suppress_interface=True), |
| 1125 'SVGAnimatedLengthList': TypeData(clazz='Interface', | 1100 'SVGAnimatedLengthList': TypeData(clazz='Interface', |
| 1126 item_type='SVGAnimatedLength'), | 1101 item_type='SVGAnimatedLength'), |
| 1127 'SVGAnimatedNumberList': TypeData(clazz='Interface', | 1102 'SVGAnimatedNumberList': TypeData(clazz='Interface', |
| 1128 item_type='SVGAnimatedNumber'), | 1103 item_type='SVGAnimatedNumber'), |
| 1129 'SVGAnimatedTransformList': TypeData(clazz='Interface', | 1104 'SVGAnimatedTransformList': TypeData(clazz='Interface', |
| 1130 item_type='SVGAnimateTransformElement'), | 1105 item_type='SVGAnimateTransformElement'), |
| 1131 'SVGElementInstanceList': TypeData(clazz='Interface', | 1106 'SVGElementInstanceList': TypeData(clazz='Interface', |
| 1132 item_type='SVGElementInstance', suppress_interface=True), | 1107 item_type='SVGElementInstance', suppress_interface=True), |
| 1133 'SourceBufferList': TypeData(clazz='Interface', item_type='SourceBuffer'), | 1108 'SourceBufferList': TypeData(clazz='Interface', item_type='SourceBuffer'), |
| 1134 'SpeechGrammarList': TypeData(clazz='Interface', item_type='SpeechGrammar'), | 1109 'SpeechGrammarList': TypeData(clazz='Interface', item_type='SpeechGrammar'), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 self) | 1201 self) |
| 1227 | 1202 |
| 1228 if type_data.clazz == 'SVGTearOff': | 1203 if type_data.clazz == 'SVGTearOff': |
| 1229 dart_interface_name = self._renamer.RenameInterface( | 1204 dart_interface_name = self._renamer.RenameInterface( |
| 1230 self._database.GetInterface(type_name)) | 1205 self._database.GetInterface(type_name)) |
| 1231 return SVGTearOffIDLTypeInfo( | 1206 return SVGTearOffIDLTypeInfo( |
| 1232 type_name, type_data, dart_interface_name, self) | 1207 type_name, type_data, dart_interface_name, self) |
| 1233 | 1208 |
| 1234 class_name = '%sIDLTypeInfo' % type_data.clazz | 1209 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1235 return globals()[class_name](type_name, type_data) | 1210 return globals()[class_name](type_name, type_data) |
| OLD | NEW |