Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: lib/html/scripts/generator.py

Issue 11065003: Convert between Dart and JavaScript SerializedScriptValues on postMessage. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 """Represents a way of converting between types.""" 505 """Represents a way of converting between types."""
506 def __init__(self, name, input_type, output_type): 506 def __init__(self, name, input_type, output_type):
507 # input_type is the type of the API input (and the argument type of the 507 # input_type is the type of the API input (and the argument type of the
508 # conversion function) 508 # conversion function)
509 # output_type is the type of the API output (and the result type of the 509 # output_type is the type of the API output (and the result type of the
510 # conversion function) 510 # conversion function)
511 self.function_name = name 511 self.function_name = name
512 self.input_type = input_type 512 self.input_type = input_type
513 self.output_type = output_type 513 self.output_type = output_type
514 514
515 # TYPE -> "DIRECTION INTERFACE.MEMBER" -> conversion 515 # "TYPE DIRECTION INTERFACE.MEMBER" -> conversion
516 # TYPE -> "DIRECTION INTERFACE.*" -> conversion 516 # "TYPE DIRECTION INTERFACE.*" -> conversion
517 # TYPE -> "DIRECTION" -> conversion 517 # "TYPE DIRECTION" -> conversion
vsm 2012/10/04 16:03:35 This is for the static type only, right? Can you
sra1 2012/10/05 02:15:29 Done.
518 # 518 #
519 # where DIRECTION is 'get' for getters and operation return values, 'set' for 519 # where DIRECTION is 'get' for getters and operation return values, 'set' for
520 # setters and operation arguments. INTERFACE and MEMBER are the idl names. 520 # setters and operation arguments. INTERFACE and MEMBER are the idl names.
521 # 521 #
522
523 _serialize_SSV = Conversion('_convertDartToNative_SerializedScriptValue',
524 'Dynamic', 'Dynamic')
525
522 dart2js_conversions = { 526 dart2js_conversions = {
523 'IDBKey': { 527 'IDBKey get':
524 'get': 528 Conversion('_convertNativeToDart_IDBKey', 'Dynamic', 'Dynamic'),
525 Conversion('_convertNativeToDart_IDBKey', 'Dynamic', 'Dynamic'), 529 'IDBKey set':
526 'set': 530 Conversion('_convertDartToNative_IDBKey', 'Dynamic', 'Dynamic'),
527 Conversion('_convertDartToNative_IDBKey', 'Dynamic', 'Dynamic'),
528 },
529 'ImageData': {
530 'get':
531 Conversion('_convertNativeToDart_ImageData', 'Dynamic', 'ImageData'),
532 'set':
533 Conversion('_convertDartToNative_ImageData', 'ImageData', 'Dynamic')
534 },
535 'Dictionary': {
536 'get':
537 Conversion('_convertNativeToDart_Dictionary', 'Dynamic', 'Map'),
538 'set':
539 Conversion('_convertDartToNative_Dictionary', 'Map', 'Dynamic'),
540 },
541 531
542 'DOMString[]': { 532 'ImageData get':
543 'set': 533 Conversion('_convertNativeToDart_ImageData', 'Dynamic', 'ImageData'),
544 Conversion( 534 'ImageData set':
545 '_convertDartToNative_StringArray', 'List<String>', 'List'), 535 Conversion('_convertDartToNative_ImageData', 'ImageData', 'Dynamic'),
546 },
547 536
548 'any': { 537 'Dictionary get':
549 'set IDBObjectStore.add': 538 Conversion('_convertNativeToDart_Dictionary', 'Dynamic', 'Map'),
550 Conversion('_convertDartToNative_SerializedScriptValue', 539 'Dictionary set':
551 'Dynamic', 'Dynamic'), 540 Conversion('_convertDartToNative_Dictionary', 'Map', 'Dynamic'),
552 'set IDBObjectStore.put': 541
553 Conversion('_convertDartToNative_SerializedScriptValue', 542 'DOMString[] set':
554 'Dynamic', 'Dynamic'), 543 Conversion('_convertDartToNative_StringArray', 'List<String>', 'List'),
555 'set IDBCursor.update': 544
556 Conversion('_convertDartToNative_SerializedScriptValue', 545 'any set IDBObjectStore.add': _serialize_SSV,
557 'Dynamic', 'Dynamic'), 546 'any set IDBObjectStore.put': _serialize_SSV,
558 }, 547 'any set IDBCursor.update': _serialize_SSV,
548
549 # postMessage
550 'any set DedicatedWorkerContext.postMessage': _serialize_SSV,
551 'any set MessagePort.postMessage': _serialize_SSV,
552 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV,
553 'SerializedScriptValue set Worker.postMessage': _serialize_SSV,
554
555 # receiving message via MessageEvent
556 'DOMObject get MessageEvent.data':
557 Conversion('_convertNativeToDart_SerializedScriptValue',
558 'Dynamic', 'Dynamic'),
559 559
560 560
561 # IDBAny is problematic. Some uses are just a union of other IDB types, 561 # IDBAny is problematic. Some uses are just a union of other IDB types,
562 # which need no conversion.. Others include data values which require 562 # which need no conversion.. Others include data values which require
563 # serialized script value processing. 563 # serialized script value processing.
564 'IDBAny': { 564 'IDBAny get IDBCursorWithValue.value':
565 'get IDBCursorWithValue.value': 565 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'),
566 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'),
567 566
568 # This is problematic. The result property of IDBRequest is used for 567 # This is problematic. The result property of IDBRequest is used for
569 # all requests. Read requests like IDBDataStore.getObject need 568 # all requests. Read requests like IDBDataStore.getObject need
570 # conversion, but other requests like opening a database return 569 # conversion, but other requests like opening a database return
571 # something that does not need conversion. 570 # something that does not need conversion.
572 'get IDBRequest.result': 571 'IDBAny get IDBRequest.result':
573 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'), 572 Conversion('_convertNativeToDart_IDBAny', 'Dynamic', 'Dynamic'),
574 573
575 # "source: On getting, returns the IDBObjectStore or IDBIndex that the 574 # "source: On getting, returns the IDBObjectStore or IDBIndex that the
576 # cursor is iterating. ...". So we should not try to convert it. 575 # cursor is iterating. ...". So we should not try to convert it.
577 'get IDBCursor.source': None, 576 'IDBAny get IDBCursor.source': None,
578 577
579 # Should be either a DOMString, an Array of DOMStrings or null. 578 # Should be either a DOMString, an Array of DOMStrings or null.
580 'get IDBObjectStore.keyPath': None 579 'IDBAny get IDBObjectStore.keyPath': None,
581 },
582 } 580 }
583 581
584 def FindConversion(idl_type, direction, interface, member): 582 def FindConversion(idl_type, direction, interface, member):
585 table = dart2js_conversions.get(idl_type) 583 table = dart2js_conversions
586 if table: 584 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or
587 return (table.get('%s %s.%s' % (direction, interface, member)) or 585 table.get('%s %s %s.*' % (idl_type, direction, interface)) or
588 table.get('%s %s.*' % (direction, interface)) or 586 table.get('%s %s' % (idl_type, direction)))
589 table.get(direction))
590 return None 587 return None
591 588
592 # ------------------------------------------------------------------------------ 589 # ------------------------------------------------------------------------------
593 590
594 class IDLTypeInfo(object): 591 class IDLTypeInfo(object):
595 def __init__(self, idl_type, data): 592 def __init__(self, idl_type, data):
596 self._idl_type = idl_type 593 self._idl_type = idl_type
597 self._data = data 594 self._data = data
598 595
599 def idl_type(self): 596 def idl_type(self):
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 if match: 981 if match:
985 if type_name == 'DOMString[]': 982 if type_name == 'DOMString[]':
986 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 983 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
987 item_info = self.TypeInfo(match.group(1) or match.group(2)) 984 item_info = self.TypeInfo(match.group(1) or match.group(2))
988 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 985 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
989 if not type_name in _idl_type_registry: 986 if not type_name in _idl_type_registry:
990 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 987 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
991 type_data = _idl_type_registry.get(type_name) 988 type_data = _idl_type_registry.get(type_name)
992 class_name = '%sIDLTypeInfo' % type_data.clazz 989 class_name = '%sIDLTypeInfo' % type_data.clazz
993 return globals()[class_name](type_name, type_data) 990 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698