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