| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 Attributes: | 301 Attributes: |
| 302 overloads: A list of IDL operation overloads with the same name. | 302 overloads: A list of IDL operation overloads with the same name. |
| 303 name: A string, the simple name of the operation. | 303 name: A string, the simple name of the operation. |
| 304 constructor_name: A string, the name of the constructor iff the constructor | 304 constructor_name: A string, the name of the constructor iff the constructor |
| 305 is named, e.g. 'fromList' in Int8Array.fromList(list). | 305 is named, e.g. 'fromList' in Int8Array.fromList(list). |
| 306 type_name: A string, the name of the return type of the operation. | 306 type_name: A string, the name of the return type of the operation. |
| 307 param_infos: A list of ParamInfo. | 307 param_infos: A list of ParamInfo. |
| 308 factory_parameters: A list of parameters used for custom designed Factory | 308 factory_parameters: A list of parameters used for custom designed Factory |
| 309 calls. | 309 calls. |
| 310 """ | 310 """ |
| 311 | 311 |
| 312 def __init__(self): | 312 def __init__(self): |
| 313 self.factory_parameters = None | 313 self.factory_parameters = None |
| 314 | 314 |
| 315 def ParametersDeclaration(self, rename_type, force_optional=False): | 315 def ParametersDeclaration(self, rename_type, force_optional=False): |
| 316 def FormatParam(param): | 316 def FormatParam(param): |
| 317 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic' | 317 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic' |
| 318 return '%s%s' % (TypeOrNothing(dart_type, param.type_id), param.name) | 318 return '%s%s' % (TypeOrNothing(dart_type, param.type_id), param.name) |
| 319 | 319 |
| 320 required = [] | 320 required = [] |
| 321 optional = [] | 321 optional = [] |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' | 413 ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| 414 ' }\n', | 414 ' }\n', |
| 415 OPT_PARAM_NAME=self.param_infos[index].name, | 415 OPT_PARAM_NAME=self.param_infos[index].name, |
| 416 FACTORY=factory_provider, | 416 FACTORY=factory_provider, |
| 417 CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type), | 417 CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type), |
| 418 FACTORY_PARAMS=self.ParametersAsArgumentList(index)) | 418 FACTORY_PARAMS=self.ParametersAsArgumentList(index)) |
| 419 | 419 |
| 420 for index, param_info in enumerate(self.param_infos): | 420 for index, param_info in enumerate(self.param_infos): |
| 421 if param_info.is_optional: | 421 if param_info.is_optional: |
| 422 EmitOptionalParameterInvocation(index) | 422 EmitOptionalParameterInvocation(index) |
| 423 | 423 |
| 424 def _GenerateFactoryOptParamsWithoutFactoryProvider(self, rename_type, | 424 def _GenerateFactoryOptParamsWithoutFactoryProvider(self, rename_type, |
| 425 emitter, factory_name, factory_constructor_name, factory_parameters): | 425 emitter, factory_name, factory_constructor_name, factory_parameters): |
| 426 """Helper method for creating a factory constructor with optional | 426 """Helper method for creating a factory constructor with optional |
| 427 parameters that does not call a factory provider, it simply creates the | 427 parameters that does not call a factory provider, it simply creates the |
| 428 object itself. This is currently used for SVGElements and HTMLElements.""" | 428 object itself. This is currently used for SVGElements and HTMLElements.""" |
| 429 inits = emitter.Emit( | 429 inits = emitter.Emit( |
| 430 '\n' | 430 '\n' |
| 431 ' factory $CONSTRUCTOR($PARAMS) {\n'» | 431 ' factory $CONSTRUCTOR($PARAMS) {\n' |
| 432 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' | 432 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| 433 '$!INITS' | 433 '$!INITS' |
| 434 ' return e;\n' | 434 ' return e;\n' |
| 435 ' }\n', | 435 ' }\n', |
| 436 CONSTRUCTOR=self._ConstructorFullName(rename_type), | 436 CONSTRUCTOR=self._ConstructorFullName(rename_type), |
| 437 FACTORY=factory_name, | 437 FACTORY=factory_name, |
| 438 CTOR_FACTORY_NAME=factory_constructor_name, | 438 CTOR_FACTORY_NAME=factory_constructor_name, |
| 439 PARAMS=self.ParametersDeclaration(rename_type), | 439 PARAMS=self.ParametersDeclaration(rename_type), |
| 440 FACTORY_PARAMS=factory_parameters) | 440 FACTORY_PARAMS=factory_parameters) |
| 441 for index, param_info in enumerate(self.param_infos): | 441 for index, param_info in enumerate(self.param_infos): |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 # Specific member of interface | 493 # Specific member of interface |
| 494 # "TYPE DIRECTION INTERFACE.*" -> conversion | 494 # "TYPE DIRECTION INTERFACE.*" -> conversion |
| 495 # All members of interface getting (setting) with type. | 495 # All members of interface getting (setting) with type. |
| 496 # "TYPE DIRECTION" -> conversion | 496 # "TYPE DIRECTION" -> conversion |
| 497 # All getters (setters) of type. | 497 # All getters (setters) of type. |
| 498 # | 498 # |
| 499 # where DIRECTION is 'get' for getters and operation return values, 'set' for | 499 # where DIRECTION is 'get' for getters and operation return values, 'set' for |
| 500 # setters and operation arguments. INTERFACE and MEMBER are the idl names. | 500 # setters and operation arguments. INTERFACE and MEMBER are the idl names. |
| 501 # | 501 # |
| 502 | 502 |
| 503 _serialize_SSV = Conversion('_convertDartToNative_SerializedScriptValue', | 503 _serialize_SSV = Conversion('convertDartToNative_SerializedScriptValue', |
| 504 'dynamic', 'dynamic') | 504 'dynamic', 'dynamic') |
| 505 | 505 |
| 506 dart2js_conversions = { | 506 dart2js_conversions = { |
| 507 # Wrap non-local Windows. We need to check EventTarget (the base type) | 507 # Wrap non-local Windows. We need to check EventTarget (the base type) |
| 508 # as well. Note, there are no functions that take a non-local Window | 508 # as well. Note, there are no functions that take a non-local Window |
| 509 # as a parameter / setter. | 509 # as a parameter / setter. |
| 510 'DOMWindow get': | 510 'DOMWindow get': |
| 511 Conversion('_convertNativeToDart_Window', 'dynamic', 'Window'), | 511 Conversion('_convertNativeToDart_Window', 'dynamic', 'Window'), |
| 512 'EventTarget get': | 512 'EventTarget get': |
| 513 Conversion('_convertNativeToDart_EventTarget', 'dynamic', | 513 Conversion('_convertNativeToDart_EventTarget', 'dynamic', |
| 514 'EventTarget'), | 514 'EventTarget'), |
| 515 'EventTarget set': | 515 'EventTarget set': |
| 516 Conversion('_convertDartToNative_EventTarget', 'EventTarget', | 516 Conversion('_convertDartToNative_EventTarget', 'EventTarget', |
| 517 'dynamic'), | 517 'dynamic'), |
| 518 | 518 |
| 519 'IDBKey get': | 519 'IDBKey get': |
| 520 Conversion('_convertNativeToDart_IDBKey', 'dynamic', 'dynamic'), | 520 Conversion('_convertNativeToDart_IDBKey', 'dynamic', 'dynamic'), |
| 521 'IDBKey set': | 521 'IDBKey set': |
| 522 Conversion('_convertDartToNative_IDBKey', 'dynamic', 'dynamic'), | 522 Conversion('_convertDartToNative_IDBKey', 'dynamic', 'dynamic'), |
| 523 | 523 |
| 524 'ImageData get': | 524 'ImageData get': |
| 525 Conversion('_convertNativeToDart_ImageData', 'dynamic', 'ImageData'), | 525 Conversion('_convertNativeToDart_ImageData', 'dynamic', 'ImageData'), |
| 526 'ImageData set': | 526 'ImageData set': |
| 527 Conversion('_convertDartToNative_ImageData', 'ImageData', 'dynamic'), | 527 Conversion('_convertDartToNative_ImageData', 'ImageData', 'dynamic'), |
| 528 | 528 |
| 529 'Dictionary get': | 529 'Dictionary get': |
| 530 Conversion('_convertNativeToDart_Dictionary', 'dynamic', 'Map'), | 530 Conversion('convertNativeToDart_Dictionary', 'dynamic', 'Map'), |
| 531 'Dictionary set': | 531 'Dictionary set': |
| 532 Conversion('_convertDartToNative_Dictionary', 'Map', 'dynamic'), | 532 Conversion('convertDartToNative_Dictionary', 'Map', 'dynamic'), |
| 533 | 533 |
| 534 'DOMString[] set': | 534 'DOMString[] set': |
| 535 Conversion('_convertDartToNative_StringArray', 'List<String>', 'List'), | 535 Conversion('convertDartToNative_StringArray', 'List<String>', 'List'), |
| 536 | 536 |
| 537 'any set IDBObjectStore.add': _serialize_SSV, | 537 'any set IDBObjectStore.add': _serialize_SSV, |
| 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 '* get MessageEvent.data': |
| 549 Conversion('_convertNativeToDart_SerializedScriptValue', | 549 Conversion('convertNativeToDart_SerializedScriptValue', |
| 550 'dynamic', 'dynamic'), | 550 'dynamic', 'dynamic'), |
| 551 | 551 |
| 552 '* get History.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': | 556 '* get PopStateEvent.state': |
| 557 Conversion('_convertNativeToDart_SerializedScriptValue', | 557 Conversion('convertNativeToDart_SerializedScriptValue', |
| 558 'dynamic', 'dynamic'), | 558 'dynamic', 'dynamic'), |
| 559 | 559 |
| 560 # 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, |
| 561 # which need no conversion.. Others include data values which require | 561 # which need no conversion.. Others include data values which require |
| 562 # serialized script value processing. | 562 # serialized script value processing. |
| 563 'IDBAny get IDBCursorWithValue.value': | 563 'IDBAny get IDBCursorWithValue.value': |
| 564 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), | 564 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), |
| 565 | 565 |
| 566 # This is problematic. The result property of IDBRequest is used for | 566 # This is problematic. The result property of IDBRequest is used for |
| 567 # all requests. Read requests like IDBDataStore.getObject need | 567 # all requests. Read requests like IDBDataStore.getObject need |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 'IDBRequest.result': "@Creates('Null')", | 628 'IDBRequest.result': "@Creates('Null')", |
| 629 | 629 |
| 630 # 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 |
| 631 # IDBRequest. | 631 # IDBRequest. |
| 632 'IDBRequest.source': "@Creates('Null')", | 632 'IDBRequest.source': "@Creates('Null')", |
| 633 | 633 |
| 634 'IDBFactory.open': "@Creates('IDBDatabase')", | 634 'IDBFactory.open': "@Creates('IDBDatabase')", |
| 635 | 635 |
| 636 'IDBObjectStore.put': "@_annotation_Creates_IDBKey", | 636 'IDBObjectStore.put': "@_annotation_Creates_IDBKey", |
| 637 'IDBObjectStore.add': "@_annotation_Creates_IDBKey", | 637 'IDBObjectStore.add': "@_annotation_Creates_IDBKey", |
| 638 'IDBObjectStore.get': "@_annotation_Creates_SerializedScriptValue", | 638 'IDBObjectStore.get': "@annotation_Creates_SerializedScriptValue", |
| 639 'IDBObjectStore.openCursor': "@Creates('IDBCursor')", | 639 'IDBObjectStore.openCursor': "@Creates('IDBCursor')", |
| 640 | 640 |
| 641 'IDBIndex.get': "@_annotation_Creates_SerializedScriptValue", | 641 'IDBIndex.get': "@annotation_Creates_SerializedScriptValue", |
| 642 'IDBIndex.getKey': | 642 'IDBIndex.getKey': |
| 643 "@_annotation_Creates_SerializedScriptValue " | 643 "@annotation_Creates_SerializedScriptValue " |
| 644 # The source is the object store behind the index. | 644 # The source is the object store behind the index. |
| 645 "@Creates('IDBObjectStore')", | 645 "@Creates('IDBObjectStore')", |
| 646 'IDBIndex.openCursor': "@Creates('IDBCursor')", | 646 'IDBIndex.openCursor': "@Creates('IDBCursor')", |
| 647 'IDBIndex.openKeyCursor': "@Creates('IDBCursor')", | 647 'IDBIndex.openKeyCursor': "@Creates('IDBCursor')", |
| 648 | 648 |
| 649 'IDBCursorWithValue.value': | 649 'IDBCursorWithValue.value': |
| 650 '@_annotation_Creates_SerializedScriptValue ' | 650 '@annotation_Creates_SerializedScriptValue ' |
| 651 '@_annotation_Returns_SerializedScriptValue', | 651 '@annotation_Returns_SerializedScriptValue', |
| 652 | 652 |
| 653 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", | 653 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", |
| 654 | 654 |
| 655 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 655 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 656 | 656 |
| 657 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 657 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 658 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 658 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
| 659 | 659 |
| 660 | 660 |
| 661 'MessageEvent.ports': "@Creates('=List')", | 661 'MessageEvent.ports': "@Creates('=List')", |
| 662 | 662 |
| 663 'MessageEvent.data': | 663 'MessageEvent.data': |
| 664 "@_annotation_Creates_SerializedScriptValue " | 664 "@annotation_Creates_SerializedScriptValue " |
| 665 "@_annotation_Returns_SerializedScriptValue", | 665 "@annotation_Returns_SerializedScriptValue", |
| 666 'PopStateEvent.state': | 666 'PopStateEvent.state': |
| 667 "@_annotation_Creates_SerializedScriptValue " | 667 "@annotation_Creates_SerializedScriptValue " |
| 668 "@_annotation_Returns_SerializedScriptValue", | 668 "@annotation_Returns_SerializedScriptValue", |
| 669 'SerializedScriptValue': | 669 'SerializedScriptValue': |
| 670 "@_annotation_Creates_SerializedScriptValue " | 670 "@annotation_Creates_SerializedScriptValue " |
| 671 "@_annotation_Returns_SerializedScriptValue", | 671 "@annotation_Returns_SerializedScriptValue", |
| 672 | 672 |
| 673 'SQLResultSetRowList.item': "@Creates('=Object')", | 673 'SQLResultSetRowList.item': "@Creates('=Object')", |
| 674 | 674 |
| 675 'XMLHttpRequest.response': | 675 'XMLHttpRequest.response': |
| 676 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", | 676 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", |
| 677 } | 677 } |
| 678 | 678 |
| 679 def FindAnnotations(idl_type, interface_name, member_name): | 679 def FindAnnotations(idl_type, interface_name, member_name): |
| 680 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | 680 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) |
| 681 if ann1: | 681 if ann1: |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 'CSSValueList': TypeData(clazz='Interface', | 1104 'CSSValueList': TypeData(clazz='Interface', |
| 1105 item_type='CSSValue', suppress_interface=True), | 1105 item_type='CSSValue', suppress_interface=True), |
| 1106 'DOMMimeTypeArray': TypeData(clazz='Interface', item_type='DOMMimeType'), | 1106 'DOMMimeTypeArray': TypeData(clazz='Interface', item_type='DOMMimeType'), |
| 1107 'DOMPluginArray': TypeData(clazz='Interface', item_type='DOMPlugin'), | 1107 'DOMPluginArray': TypeData(clazz='Interface', item_type='DOMPlugin'), |
| 1108 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString', | 1108 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString', |
| 1109 suppress_interface=True, custom_to_native=True), | 1109 suppress_interface=True, custom_to_native=True), |
| 1110 'EntryArray': TypeData(clazz='Interface', item_type='Entry', | 1110 'EntryArray': TypeData(clazz='Interface', item_type='Entry', |
| 1111 suppress_interface=True), | 1111 suppress_interface=True), |
| 1112 'EntryArraySync': TypeData(clazz='Interface', item_type='EntrySync', | 1112 'EntryArraySync': TypeData(clazz='Interface', item_type='EntrySync', |
| 1113 suppress_interface=True), | 1113 suppress_interface=True), |
| 1114 'FileList': TypeData(clazz='Interface', item_type='File', | 1114 'FileList': TypeData(clazz='Interface', item_type='File'), |
| 1115 suppress_interface=True), | |
| 1116 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', | 1115 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', |
| 1117 suppress_interface=True), | 1116 suppress_interface=True), |
| 1118 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'), | 1117 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'), |
| 1119 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'), | 1118 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'), |
| 1120 'MediaStreamList': TypeData(clazz='Interface', | 1119 'MediaStreamList': TypeData(clazz='Interface', |
| 1121 item_type='MediaStream', suppress_interface=True), | 1120 item_type='MediaStream', suppress_interface=True), |
| 1122 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'), | 1121 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'), |
| 1123 'NodeList': TypeData(clazz='Interface', item_type='Node', | 1122 'NodeList': TypeData(clazz='Interface', item_type='Node', |
| 1124 suppress_interface=False, dart_type='List<Node>'), | 1123 suppress_interface=False, dart_type='List<Node>'), |
| 1125 'SVGAnimatedLengthList': TypeData(clazz='Interface', | 1124 'SVGAnimatedLengthList': TypeData(clazz='Interface', |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 self) | 1225 self) |
| 1227 | 1226 |
| 1228 if type_data.clazz == 'SVGTearOff': | 1227 if type_data.clazz == 'SVGTearOff': |
| 1229 dart_interface_name = self._renamer.RenameInterface( | 1228 dart_interface_name = self._renamer.RenameInterface( |
| 1230 self._database.GetInterface(type_name)) | 1229 self._database.GetInterface(type_name)) |
| 1231 return SVGTearOffIDLTypeInfo( | 1230 return SVGTearOffIDLTypeInfo( |
| 1232 type_name, type_data, dart_interface_name, self) | 1231 type_name, type_data, dart_interface_name, self) |
| 1233 | 1232 |
| 1234 class_name = '%sIDLTypeInfo' % type_data.clazz | 1233 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1235 return globals()[class_name](type_name, type_data) | 1234 return globals()[class_name](type_name, type_data) |
| OLD | NEW |