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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 """Represents a way of converting between types.""" | 515 """Represents a way of converting between types.""" |
516 def __init__(self, name, input_type, output_type): | 516 def __init__(self, name, input_type, output_type): |
517 # input_type is the type of the API input (and the argument type of the | 517 # input_type is the type of the API input (and the argument type of the |
518 # conversion function) | 518 # conversion function) |
519 # output_type is the type of the API output (and the result type of the | 519 # output_type is the type of the API output (and the result type of the |
520 # conversion function) | 520 # conversion function) |
521 self.function_name = name | 521 self.function_name = name |
522 self.input_type = input_type | 522 self.input_type = input_type |
523 self.output_type = output_type | 523 self.output_type = output_type |
524 | 524 |
525 # TYPE -> "DIRECTION INTERFACE.MEMBER" -> conversion | 525 # "TYPE DIRECTION INTERFACE.MEMBER" -> conversion |
526 # TYPE -> "DIRECTION INTERFACE.*" -> conversion | 526 # Specific member of interface |
527 # TYPE -> "DIRECTION" -> conversion | 527 # "TYPE DIRECTION INTERFACE.*" -> conversion |
| 528 # All members of interface getting (setting) with type. |
| 529 # "TYPE DIRECTION" -> conversion |
| 530 # All getters (setters) of type. |
528 # | 531 # |
529 # where DIRECTION is 'get' for getters and operation return values, 'set' for | 532 # where DIRECTION is 'get' for getters and operation return values, 'set' for |
530 # setters and operation arguments. INTERFACE and MEMBER are the idl names. | 533 # setters and operation arguments. INTERFACE and MEMBER are the idl names. |
531 # | 534 # |
| 535 |
| 536 _serialize_SSV = Conversion('_convertDartToNative_SerializedScriptValue', |
| 537 'Dynamic', 'Dynamic') |
| 538 |
532 dart2js_conversions = { | 539 dart2js_conversions = { |
533 'IDBKey': { | 540 'IDBKey get': |
534 'get': | 541 Conversion('_convertNativeToDart_IDBKey', 'Dynamic', 'Dynamic'), |
535 Conversion('_convertNativeToDart_IDBKey', 'Dynamic', 'Dynamic'), | 542 'IDBKey set': |
536 'set': | 543 Conversion('_convertDartToNative_IDBKey', 'Dynamic', 'Dynamic'), |
537 Conversion('_convertDartToNative_IDBKey', 'Dynamic', 'Dynamic'), | |
538 }, | |
539 'ImageData': { | |
540 'get': | |
541 Conversion('_convertNativeToDart_ImageData', 'Dynamic', 'ImageData'), | |
542 'set': | |
543 Conversion('_convertDartToNative_ImageData', 'ImageData', 'Dynamic') | |
544 }, | |
545 'Dictionary': { | |
546 'get': | |
547 Conversion('_convertNativeToDart_Dictionary', 'Dynamic', 'Map'), | |
548 'set': | |
549 Conversion('_convertDartToNative_Dictionary', 'Map', 'Dynamic'), | |
550 }, | |
551 | 544 |
552 'DOMString[]': { | 545 'ImageData get': |
553 'set': | 546 Conversion('_convertNativeToDart_ImageData', 'Dynamic', 'ImageData'), |
554 Conversion( | 547 'ImageData set': |
555 '_convertDartToNative_StringArray', 'List<String>', 'List'), | 548 Conversion('_convertDartToNative_ImageData', 'ImageData', 'Dynamic'), |
556 }, | |
557 | 549 |
558 'any': { | 550 'Dictionary get': |
559 'set IDBObjectStore.add': | 551 Conversion('_convertNativeToDart_Dictionary', 'Dynamic', 'Map'), |
560 Conversion('_convertDartToNative_SerializedScriptValue', | 552 'Dictionary set': |
561 'Dynamic', 'Dynamic'), | 553 Conversion('_convertDartToNative_Dictionary', 'Map', 'Dynamic'), |
562 'set IDBObjectStore.put': | 554 |
563 Conversion('_convertDartToNative_SerializedScriptValue', | 555 'DOMString[] set': |
564 'Dynamic', 'Dynamic'), | 556 Conversion('_convertDartToNative_StringArray', 'List<String>', 'List'), |
565 'set IDBCursor.update': | 557 |
566 Conversion('_convertDartToNative_SerializedScriptValue', | 558 'any set IDBObjectStore.add': _serialize_SSV, |
567 'Dynamic', 'Dynamic'), | 559 'any set IDBObjectStore.put': _serialize_SSV, |
568 }, | 560 'any set IDBCursor.update': _serialize_SSV, |
| 561 |
| 562 # postMessage |
| 563 'any set DedicatedWorkerContext.postMessage': _serialize_SSV, |
| 564 'any set MessagePort.postMessage': _serialize_SSV, |
| 565 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV, |
| 566 'SerializedScriptValue set Worker.postMessage': _serialize_SSV, |
| 567 |
| 568 # receiving message via MessageEvent |
| 569 'DOMObject get MessageEvent.data': |
| 570 Conversion('_convertNativeToDart_SerializedScriptValue', |
| 571 'Dynamic', 'Dynamic'), |
569 | 572 |
570 | 573 |
571 # IDBAny is problematic. Some uses are just a union of other IDB types, | 574 # IDBAny is problematic. Some uses are just a union of other IDB types, |
572 # which need no conversion.. Others include data values which require | 575 # which need no conversion.. Others include data values which require |
573 # serialized script value processing. | 576 # serialized script value processing. |
574 'IDBAny': { | 577 'IDBAny get IDBCursorWithValue.value': |
575 'get IDBCursorWithValue.value': | 578 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'), |
576 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'), | |
577 | 579 |
578 # This is problematic. The result property of IDBRequest is used for | 580 # This is problematic. The result property of IDBRequest is used for |
579 # all requests. Read requests like IDBDataStore.getObject need | 581 # all requests. Read requests like IDBDataStore.getObject need |
580 # conversion, but other requests like opening a database return | 582 # conversion, but other requests like opening a database return |
581 # something that does not need conversion. | 583 # something that does not need conversion. |
582 'get IDBRequest.result': | 584 'IDBAny get IDBRequest.result': |
583 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'), | 585 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'), |
584 | 586 |
585 # "source: On getting, returns the IDBObjectStore or IDBIndex that the | 587 # "source: On getting, returns the IDBObjectStore or IDBIndex that the |
586 # cursor is iterating. ...". So we should not try to convert it. | 588 # cursor is iterating. ...". So we should not try to convert it. |
587 'get IDBCursor.source': None, | 589 'IDBAny get IDBCursor.source': None, |
588 | 590 |
589 # Should be either a DOMString, an Array of DOMStrings or null. | 591 # Should be either a DOMString, an Array of DOMStrings or null. |
590 'get IDBObjectStore.keyPath': None | 592 'IDBAny get IDBObjectStore.keyPath': None, |
591 }, | |
592 } | 593 } |
593 | 594 |
594 def FindConversion(idl_type, direction, interface, member): | 595 def FindConversion(idl_type, direction, interface, member): |
595 table = dart2js_conversions.get(idl_type) | 596 table = dart2js_conversions |
596 if table: | 597 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or |
597 return (table.get('%s %s.%s' % (direction, interface, member)) or | 598 table.get('%s %s %s.*' % (idl_type, direction, interface)) or |
598 table.get('%s %s.*' % (direction, interface)) or | 599 table.get('%s %s' % (idl_type, direction))) |
599 table.get(direction)) | |
600 return None | 600 return None |
601 | 601 |
602 # ------------------------------------------------------------------------------ | 602 # ------------------------------------------------------------------------------ |
603 | 603 |
604 class IDLTypeInfo(object): | 604 class IDLTypeInfo(object): |
605 def __init__(self, idl_type, data): | 605 def __init__(self, idl_type, data): |
606 self._idl_type = idl_type | 606 self._idl_type = idl_type |
607 self._data = data | 607 self._data = data |
608 | 608 |
609 def idl_type(self): | 609 def idl_type(self): |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 if type_data.clazz == 'Interface': | 1029 if type_data.clazz == 'Interface': |
1030 if self._database.HasInterface(type_name): | 1030 if self._database.HasInterface(type_name): |
1031 dart_interface_name = self._renamer.RenameInterface( | 1031 dart_interface_name = self._renamer.RenameInterface( |
1032 self._database.GetInterface(type_name)) | 1032 self._database.GetInterface(type_name)) |
1033 else: | 1033 else: |
1034 dart_interface_name = type_name | 1034 dart_interface_name = type_name |
1035 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) | 1035 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name) |
1036 | 1036 |
1037 class_name = '%sIDLTypeInfo' % type_data.clazz | 1037 class_name = '%sIDLTypeInfo' % type_data.clazz |
1038 return globals()[class_name](type_name, type_data) | 1038 return globals()[class_name](type_name, type_data) |
OLD | NEW |