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

Side by Side Diff: tools/dom/scripts/systemnative.py

Issue 22357003: MERGE: 152953-155080 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « tools/dom/scripts/idlparser.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from htmldartgenerator import * 12 from htmldartgenerator import *
13 from idlnode import IDLArgument, IDLAttribute 13 from idlnode import IDLArgument, IDLAttribute
14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES 14 from systemhtml import js_support_checks, GetCallbackInfo, HTML_LIBRARY_NAMES
15 15
16 _cpp_type_map = { 16 # TODO(vsm): This logic needs to pulled from the source IDL. These tables are
17 # an ugly workaround.
18 _cpp_callback_map = {
17 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem', 19 ('DataTransferItem', 'webkitGetAsEntry'): 'DataTransferItemFileSystem',
18 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen', 20 ('Document', 'webkitIsFullScreen'): 'DocumentFullscreen',
19 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen', 21 ('Document', 'webkitFullScreenKeyboardInputAllowed'): 'DocumentFullscreen',
20 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen', 22 ('Document', 'webkitCurrentFullScreenElement'): 'DocumentFullscreen',
21 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen', 23 ('Document', 'webkitCancelFullScreen'): 'DocumentFullscreen',
22 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen', 24 ('Document', 'webkitFullscreenEnabled'): 'DocumentFullscreen',
23 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen', 25 ('Document', 'webkitFullscreenElement'): 'DocumentFullscreen',
24 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen', 26 ('Document', 'webkitExitFullscreen'): 'DocumentFullscreen',
25 ('Window', 'crypto'): 'DOMWindowCrypto', 27 ('DOMWindow', 'crypto'): 'DOMWindowCrypto',
26 ('Window', 'indexedDB'): 'DOMWindowIndexedDatabase', 28 ('DOMWindow', 'indexedDB'): 'DOMWindowIndexedDatabase',
27 ('Window', 'speechSynthesis'): 'DOMWindowSpeechSynthesis', 29 ('DOMWindow', 'speechSynthesis'): 'DOMWindowSpeechSynthesis',
28 ('Window', 'webkitNotifications'): 'DOMWindowNotifications', 30 ('DOMWindow', 'webkitNotifications'): 'DOMWindowNotifications',
29 ('Window', 'storage'): 'DOMWindowQuota', 31 ('DOMWindow', 'storage'): 'DOMWindowQuota',
30 ('Window', 'webkitStorageInfo'): 'DOMWindowQuota', 32 ('DOMWindow', 'webkitStorageInfo'): 'DOMWindowQuota',
31 ('Window', 'openDatabase'): 'DOMWindowWebDatabase', 33 ('DOMWindow', 'openDatabase'): 'DOMWindowWebDatabase',
32 ('Window', 'webkitRequestFileSystem'): 'DOMWindowFileSystem', 34 ('DOMWindow', 'webkitRequestFileSystem'): 'DOMWindowFileSystem',
33 ('Window', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem', 35 ('DOMWindow', 'webkitResolveLocalFileSystemURL'): 'DOMWindowFileSystem',
36 ('DOMWindow', 'atob'): 'DOMWindowBase64',
37 ('DOMWindow', 'btoa'): 'DOMWindowBase64',
38 ('DOMWindow', 'clearTimeout'): 'DOMWindowTimers',
39 ('DOMWindow', 'clearInterval'): 'DOMWindowTimers',
34 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem', 40 ('HTMLInputElement', 'webkitEntries'): 'HTMLInputElementFileSystem',
35 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack', 41 ('Navigator', 'doNotTrack'): 'NavigatorDoNotTrack',
36 ('Navigator', 'geolocation'): 'NavigatorGeolocation', 42 ('Navigator', 'geolocation'): 'NavigatorGeolocation',
37 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota', 43 ('Navigator', 'webkitPersistentStorage'): 'NavigatorStorageQuota',
38 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota', 44 ('Navigator', 'webkitTemporaryStorage'): 'NavigatorStorageQuota',
39 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils', 45 ('Navigator', 'registerProtocolHandler'): 'NavigatorContentUtils',
40 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils', 46 ('Navigator', 'unregisterProtocolHandler'): 'NavigatorContentUtils',
41 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream', 47 ('Navigator', 'webkitGetUserMedia'): 'NavigatorMediaStream',
42 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad', 48 ('Navigator', 'webkitGetGamepads'): 'NavigatorGamepad',
43 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI', 49 ('Navigator', 'requestMIDIAccess'): 'NavigatorWebMIDI',
44 ('Navigator', 'vibrate'): 'NavigatorVibration', 50 ('Navigator', 'vibrate'): 'NavigatorVibration',
51 ('WorkerGlobalScope', 'crypto'): 'WorkerGlobalScopeCrypto',
52 ('WorkerGlobalScope', 'indexedDB'): 'WorkerGlobalScopeIndexedDatabase',
53 ('WorkerGlobalScope', 'webkitNotifications'): 'WorkerGlobalScopeNotifications' ,
54 ('WorkerGlobalScope', 'openDatabase'): 'WorkerGlobalScopeWebDatabase',
55 ('WorkerGlobalScope', 'openDatabaseSync'): 'WorkerGlobalScopeWebDatabase',
56 ('WorkerGlobalScope', 'performance'): 'WorkerGlobalScopePerformance',
57 ('WorkerGlobalScope', 'webkitRequestFileSystem'): 'WorkerGlobalScopeFileSystem ',
58 ('WorkerGlobalScope', 'webkitRequestFileSystemSync'): 'WorkerGlobalScopeFileSy stem',
59 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemURL'): 'WorkerGlobalScopeFi leSystem',
60 ('WorkerGlobalScope', 'webkitResolveLocalFileSystemSyncURL'): 'WorkerGlobalSco peFileSystem',
61 ('WorkerGlobalScope', 'atob'): 'DOMWindowBase64',
62 ('WorkerGlobalScope', 'btoa'): 'DOMWindowBase64',
63 ('WorkerGlobalScope', 'clearTimeout'): 'DOMWindowTimers',
64 ('WorkerGlobalScope', 'clearInterval'): 'DOMWindowTimers',
45 } 65 }
46 66
67 _cpp_overloaded_callback_map = {
68 ('DOMURL', 'createObjectUrlFromSourceCallback'): 'URLMediaSource',
69 ('DOMURL', 'createObjectUrlFromStreamCallback'): 'URLMediaStream',
70 ('DOMURL', '_createObjectUrlFromWebKitSourceCallback'): 'URLMediaSource',
71 ('DOMURL', '_createObjectURL_2Callback'): 'URLMediaSource',
72 ('DOMURL', '_createObjectURL_3Callback'): 'URLMediaSource',
73 ('DOMURL', '_createObjectURL_4Callback'): 'URLMediaStream',
74 }
75
47 _cpp_partial_map = {} 76 _cpp_partial_map = {}
48 77
49 def _GetCPPPartialNames(interface_name): 78 def _GetCPPPartialNames(interface):
79 interface_name = interface.ext_attrs.get('ImplementedAs', interface.id)
50 if not _cpp_partial_map: 80 if not _cpp_partial_map:
51 for (type, member) in _cpp_type_map.keys(): 81 for (type, member) in _cpp_callback_map.keys():
52 if type not in _cpp_partial_map: 82 if type not in _cpp_partial_map:
53 _cpp_partial_map[type] = set([]) 83 _cpp_partial_map[type] = set([])
54 _cpp_partial_map[type].add(_cpp_type_map[(type, member)]) 84 _cpp_partial_map[type].add(_cpp_callback_map[(type, member)])
85
86 for (type, member) in _cpp_overloaded_callback_map.keys():
87 if type not in _cpp_partial_map:
88 _cpp_partial_map[type] = set([])
89 _cpp_partial_map[type].add(_cpp_overloaded_callback_map[(type, member)])
55 90
56 if interface_name in _cpp_partial_map: 91 if interface_name in _cpp_partial_map:
57 return _cpp_partial_map[interface_name] 92 return _cpp_partial_map[interface_name]
58 else: 93 else:
59 return set([]) 94 return set([])
60 95
61 def _GetCPPTypeName(interface_name, callback_name): 96 def _GetCPPTypeName(interface_name, callback_name, cpp_name):
62 # TODO(vsm): We need to track the original IDL file name in order to recover 97 # TODO(vsm): We need to track the original IDL file name in order to recover
63 # the proper CPP name. 98 # the proper CPP name.
64 99
65 cpp_tuple = (interface_name, callback_name) 100 cpp_tuple = (interface_name, callback_name)
66 if cpp_tuple in _cpp_type_map: 101 if cpp_tuple in _cpp_callback_map:
67 cpp_type_name = _cpp_type_map[cpp_tuple] 102 cpp_type_name = _cpp_callback_map[cpp_tuple]
103 elif (interface_name, cpp_name) in _cpp_overloaded_callback_map:
104 cpp_type_name = _cpp_overloaded_callback_map[(interface_name, cpp_name)]
68 else: 105 else:
69 cpp_type_name = interface_name 106 cpp_type_name = interface_name
70 return cpp_type_name 107 return cpp_type_name
71 108
72 class DartiumBackend(HtmlDartGenerator): 109 class DartiumBackend(HtmlDartGenerator):
73 """Generates Dart implementation for one DOM IDL interface.""" 110 """Generates Dart implementation for one DOM IDL interface."""
74 111
75 def __init__(self, interface, cpp_library_emitter, options): 112 def __init__(self, interface, cpp_library_emitter, options):
76 super(DartiumBackend, self).__init__(interface, options) 113 super(DartiumBackend, self).__init__(interface, options)
77 114
(...skipping 12 matching lines...) Expand all
90 return False 127 return False
91 128
92 def CustomJSMembers(self): 129 def CustomJSMembers(self):
93 return {} 130 return {}
94 131
95 def GenerateCallback(self, info): 132 def GenerateCallback(self, info):
96 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id): 133 if IsPureInterface(self._interface.id) or IsCustomType(self._interface.id):
97 return 134 return
98 135
99 cpp_impl_includes = set(['"' + partial + '.h"' 136 cpp_impl_includes = set(['"' + partial + '.h"'
100 for partial in _GetCPPPartialNames(self._interface. id)]) 137 for partial in _GetCPPPartialNames(self._interface) ])
101 cpp_header_handlers_emitter = emitter.Emitter() 138 cpp_header_handlers_emitter = emitter.Emitter()
102 cpp_impl_handlers_emitter = emitter.Emitter() 139 cpp_impl_handlers_emitter = emitter.Emitter()
103 class_name = 'Dart%s' % self._interface.id 140 class_name = 'Dart%s' % self._interface.id
104 for operation in self._interface.operations: 141 for operation in self._interface.operations:
105 parameters = [] 142 parameters = []
106 arguments = [] 143 arguments = []
107 conversion_includes = [] 144 conversion_includes = []
108 for argument in operation.arguments: 145 for argument in operation.arguments:
109 argument_type_info = self._TypeInfo(argument.type.id) 146 argument_type_info = self._TypeInfo(argument.type.id)
110 parameters.append('%s %s' % (argument_type_info.parameter_type(), 147 parameters.append('%s %s' % (argument_type_info.parameter_type(),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 self._renamer.GetLibraryName(self._interface)) 217 self._renamer.GetLibraryName(self._interface))
181 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel f._interface.id) 218 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel f._interface.id)
182 else: 219 else:
183 self._cpp_header_emitter = emitter.Emitter() 220 self._cpp_header_emitter = emitter.Emitter()
184 self._cpp_impl_emitter = emitter.Emitter() 221 self._cpp_impl_emitter = emitter.Emitter()
185 222
186 self._interface_type_info = self._TypeInfo(self._interface.id) 223 self._interface_type_info = self._TypeInfo(self._interface.id)
187 self._members_emitter = members_emitter 224 self._members_emitter = members_emitter
188 self._cpp_declarations_emitter = emitter.Emitter() 225 self._cpp_declarations_emitter = emitter.Emitter()
189 self._cpp_impl_includes = set(['"' + partial + '.h"' 226 self._cpp_impl_includes = set(['"' + partial + '.h"'
190 for partial in _GetCPPPartialNames(self._inte rface.id)]) 227 for partial in _GetCPPPartialNames(self._inte rface)])
191 self._cpp_definitions_emitter = emitter.Emitter() 228 self._cpp_definitions_emitter = emitter.Emitter()
192 self._cpp_resolver_emitter = emitter.Emitter() 229 self._cpp_resolver_emitter = emitter.Emitter()
193 230
194 # We need to revisit our treatment of typed arrays, right now 231 # We need to revisit our treatment of typed arrays, right now
195 # it is full of hacks. 232 # it is full of hacks.
196 if self._interface.ext_attrs.get('ConstructorTemplate') == 'TypedArray': 233 if self._interface.ext_attrs.get('ConstructorTemplate') == 'TypedArray':
197 self._cpp_resolver_emitter.Emit( 234 self._cpp_resolver_emitter.Emit(
198 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 235 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
199 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n' , 236 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n' ,
200 INTERFACE_NAME=self._interface.id) 237 INTERFACE_NAME=self._interface.id)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 webcore_function_name = attr.ext_attrs['ImplementedAs'] 442 webcore_function_name = attr.ext_attrs['ImplementedAs']
406 else: 443 else:
407 if attr.id == 'operator': 444 if attr.id == 'operator':
408 webcore_function_name = '_operator' 445 webcore_function_name = '_operator'
409 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 446 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
410 webcore_function_name = 'svgTarget' 447 webcore_function_name = 'svgTarget'
411 elif attr.id == 'CSS': 448 elif attr.id == 'CSS':
412 webcore_function_name = 'css' 449 webcore_function_name = 'css'
413 else: 450 else:
414 webcore_function_name = self._ToWebKitName(attr.id) 451 webcore_function_name = self._ToWebKitName(attr.id)
415 if attr.type.id.startswith('SVGAnimated'):
416 webcore_function_name += 'Animated'
417 452
418 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 453 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
419 self._GenerateNativeCallback( 454 self._GenerateNativeCallback(
420 cpp_callback_name, 455 cpp_callback_name,
421 True, 456 True,
422 function_expression, 457 function_expression,
423 attr, 458 attr,
424 [], 459 [],
425 attr.type.id, 460 attr.type.id,
426 attr.type.nullable, 461 attr.type.nullable,
427 'GetterRaisesException' in attr.ext_attrs or 'RaisesException' in attr.e xt_attrs) 462 'GetterRaisesException' in attr.ext_attrs or 'RaisesException' in attr.e xt_attrs)
428 463
429 def _AddSetter(self, attr, html_name): 464 def _AddSetter(self, attr, html_name):
430 type_info = self._TypeInfo(attr.type.id) 465 type_info = self._TypeInfo(attr.type.id)
431 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id)) 466 dart_declaration = 'void set %s(%s value)' % (html_name, self._DartType(attr .type.id))
432 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 467 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
433 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 468 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
434 dart_declaration, 'Setter', is_custom) 469 dart_declaration, 'Setter', is_custom)
435 if is_custom: 470 if is_custom:
436 return 471 return
437 472
438 if 'Reflect' in attr.ext_attrs: 473 if 'Reflect' in attr.ext_attrs:
439 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name() 474 webcore_function_name = self._TypeInfo(attr.type.id).webcore_setter_name()
440 else: 475 else:
441 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 476 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
442 lambda s: s.group(1).upper(), 477 lambda s: s.group(1).upper(),
443 attr.id) 478 attr.id)
444 webcore_function_name = 'set%s' % webcore_function_name 479 webcore_function_name = 'set%s' % webcore_function_name
445 if attr.type.id.startswith('SVGAnimated'):
446 webcore_function_name += 'Animated'
447 480
448 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 481 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
449 self._GenerateNativeCallback( 482 self._GenerateNativeCallback(
450 cpp_callback_name, 483 cpp_callback_name,
451 True, 484 True,
452 function_expression, 485 function_expression,
453 attr, 486 attr,
454 [attr], 487 [attr],
455 'void', 488 'void',
456 False, 489 False,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 operations, 640 operations,
608 dart_declaration, 641 dart_declaration,
609 GenerateCall, 642 GenerateCall,
610 self._IsArgumentOptionalInWebCore) 643 self._IsArgumentOptionalInWebCore)
611 644
612 def SecondaryContext(self, interface): 645 def SecondaryContext(self, interface):
613 pass 646 pass
614 647
615 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name): 648 def _GenerateOperationNativeCallback(self, operation, arguments, cpp_callback_ name):
616 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d) 649 webcore_function_name = operation.ext_attrs.get('ImplementedAs', operation.i d)
617 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 650 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation, cpp_callback_name)
618 self._GenerateNativeCallback( 651 self._GenerateNativeCallback(
619 cpp_callback_name, 652 cpp_callback_name,
620 not operation.is_static, 653 not operation.is_static,
621 function_expression, 654 function_expression,
622 operation, 655 operation,
623 arguments, 656 arguments,
624 operation.type.id, 657 operation.type.id,
625 operation.type.nullable, 658 operation.type.nullable,
626 'RaisesException' in operation.ext_attrs) 659 'RaisesException' in operation.ext_attrs)
627 660
628 def _GenerateNativeCallback(self, 661 def _GenerateNativeCallback(self,
629 callback_name, 662 callback_name,
630 needs_receiver, 663 needs_receiver,
631 function_expression, 664 function_expression,
632 node, 665 node,
633 arguments, 666 arguments,
634 return_type, 667 return_type,
635 return_type_is_nullable, 668 return_type_is_nullable,
636 raises_dom_exception): 669 raises_dom_exception):
670
637 ext_attrs = node.ext_attrs 671 ext_attrs = node.ext_attrs
638 672
639 cpp_arguments = [] 673 cpp_arguments = []
640 runtime_check = None 674 runtime_check = None
641 raises_exceptions = raises_dom_exception or arguments 675 raises_exceptions = raises_dom_exception or arguments
642 676
643 # TODO(antonm): unify with ScriptState below. 677 # TODO(antonm): unify with ScriptState below.
644 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS tate' or 678 requires_stack_info = (ext_attrs.get('CallWith') == 'ScriptArguments|ScriptS tate' or
645 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts|ScriptState') 679 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts|ScriptState' or
680 ext_attrs.get('CallWith') == 'ScriptArguments&ScriptS tate' or
681 ext_attrs.get('ConstructorCallWith') == 'ScriptArgume nts&ScriptState')
646 if requires_stack_info: 682 if requires_stack_info:
647 raises_exceptions = True 683 raises_exceptions = True
648 cpp_arguments = ['&state', 'scriptArguments.release()'] 684 cpp_arguments = ['&state', 'scriptArguments.release()']
649 # WebKit uses scriptArguments to reconstruct last argument, so 685 # WebKit uses scriptArguments to reconstruct last argument, so
650 # it's not needed and should be just removed. 686 # it's not needed and should be just removed.
651 arguments = arguments[:-1] 687 arguments = arguments[:-1]
652 688
653 # TODO(antonm): unify with ScriptState below. 689 # TODO(antonm): unify with ScriptState below.
654 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments' or 690 requires_script_arguments = (ext_attrs.get('CallWith') == 'ScriptArguments' or
655 ext_attrs.get('ConstructorCallWith') == 'Script Arguments') 691 ext_attrs.get('ConstructorCallWith') == 'Script Arguments')
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 846
811 # Emit arguments. 847 # Emit arguments.
812 start_index = 1 if needs_receiver else 0 848 start_index = 1 if needs_receiver else 0
813 for i, argument in enumerate(arguments): 849 for i, argument in enumerate(arguments):
814 type_info = self._TypeInfo(argument.type.id) 850 type_info = self._TypeInfo(argument.type.id)
815 self._cpp_impl_includes |= set(type_info.conversion_includes()) 851 self._cpp_impl_includes |= set(type_info.conversion_includes())
816 argument_expression_template, type, cls, function = \ 852 argument_expression_template, type, cls, function = \
817 type_info.to_native_info(argument, self._interface.id) 853 type_info.to_native_info(argument, self._interface.id)
818 854
819 def AllowsNull(): 855 def AllowsNull():
820 assert argument.ext_attrs.get('TreatNullAs', 'NullString') == 'NullStrin g' 856 # TODO(vsm): HTMLSelectElement's indexed setter treats a null as a remov e.
857 # We need to handle that.
858 # assert argument.ext_attrs.get('TreatNullAs', 'NullString') == 'NullStr ing'
821 if argument.ext_attrs.get('TreatNullAs') == 'NullString': 859 if argument.ext_attrs.get('TreatNullAs') == 'NullString':
822 return True 860 return True
823 861
824 if argument.type.nullable: 862 if argument.type.nullable:
825 return True 863 return True
826 864
827 if isinstance(argument, IDLAttribute): 865 if isinstance(argument, IDLAttribute):
828 return (argument.type.id == 'DOMString') and \ 866 return (argument.type.id == 'DOMString') and \
829 ('Reflect' in argument.ext_attrs) 867 ('Reflect' in argument.ext_attrs)
830 868
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 self._cpp_impl_includes.add('"%s.h"' % cls) 900 self._cpp_impl_includes.add('"%s.h"' % cls)
863 cpp_arguments.append(argument_expression_template % argument_name) 901 cpp_arguments.append(argument_expression_template % argument_name)
864 902
865 body_emitter.Emit('\n') 903 body_emitter.Emit('\n')
866 904
867 if 'NeedsUserGestureCheck' in ext_attrs: 905 if 'NeedsUserGestureCheck' in ext_attrs:
868 cpp_arguments.append('DartUtilities::processingUserGesture') 906 cpp_arguments.append('DartUtilities::processingUserGesture')
869 907
870 invocation_emitter = body_emitter 908 invocation_emitter = body_emitter
871 if raises_dom_exception: 909 if raises_dom_exception:
872 cpp_arguments.append('ec') 910 cpp_arguments.append('es')
873 invocation_emitter = body_emitter.Emit( 911 invocation_emitter = body_emitter.Emit(
874 ' ExceptionCode ec = 0;\n' 912 # TODO(vsm): The move from ExceptionCode to ExceptionState adds
913 # a V8 dependency. Constructing with a NULL V8 isolate....
914 ' ExceptionState es(0);\n'
875 '$!INVOCATION' 915 '$!INVOCATION'
876 ' if (UNLIKELY(ec)) {\n' 916 ' if (es.hadException()) {\n'
877 ' exception = DartDOMWrapper::exceptionCodeToDartException(ec );\n' 917 ' exception = DartDOMWrapper::exceptionCodeToDartException(es );\n'
878 ' goto fail;\n' 918 ' goto fail;\n'
879 ' }\n') 919 ' }\n')
880 920
881 921
882 if needs_receiver: 922 if needs_receiver:
883 interface_name = self._interface_type_info.native_type() 923 interface_name = self._interface_type_info.native_type()
884 cpp_type_name = _GetCPPTypeName(interface_name, 924 # Hack to determine if this came from the _cpp_callback_map.
885 node.id)
886 # Hack to determine if this came from the _cpp_type_map.
887 # In this case, the getter is mapped to a static method. 925 # In this case, the getter is mapped to a static method.
888 if (not function_expression.startswith('receiver->') and 926 if (not function_expression.startswith('receiver->') and
889 not function_expression.startswith(interface_name + '::')): 927 not function_expression.startswith(interface_name + '::')):
890 if 'childNodes' in callback_name: 928 if interface_name == 'DOMWindow' or interface_name == 'Navigator' or int erface_name == 'WorkerGlobalScope':
891 print function_expression
892 print interface_name
893 raise 'hell'
894 if interface_name == 'DOMWindow' or interface_name == 'Navigator':
895 cpp_arguments.insert(0, 'receiver') 929 cpp_arguments.insert(0, 'receiver')
896 else: 930 else:
897 cpp_arguments.append('receiver') 931 cpp_arguments.append('receiver')
898 932
899 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments)) 933 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
900 if return_type == 'void': 934 if return_type == 'void':
901 invocation_emitter.Emit( 935 invocation_emitter.Emit(
902 ' $FUNCTION_CALL;\n', 936 ' $FUNCTION_CALL;\n',
903 FUNCTION_CALL=function_call) 937 FUNCTION_CALL=function_call)
904 else: 938 else:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload', 1005 svg_exceptions = ['class', 'id', 'onabort', 'onclick', 'onerror', 'onload',
972 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 1006 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
973 'onmouseup', 'onresize', 'onscroll', 'onunload'] 1007 'onmouseup', 'onresize', 'onscroll', 'onunload']
974 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions: 1008 if self._interface.id.startswith('SVG') and not attr.id in svg_exceptions:
975 namespace = 'SVGNames' 1009 namespace = 'SVGNames'
976 self._cpp_impl_includes.add('"%s.h"' % namespace) 1010 self._cpp_impl_includes.add('"%s.h"' % namespace)
977 1011
978 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 1012 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
979 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 1013 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
980 1014
981 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): 1015 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node, cpp_call back_name=None):
982 if 'ImplementedBy' in idl_node.ext_attrs: 1016 if 'ImplementedBy' in idl_node.ext_attrs:
983 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) 1017 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
1018 cpp_type_name = self._interface_type_info.native_type()
1019 impl_type_name = _GetCPPTypeName(cpp_type_name, function_name, cpp_callback_ name)
984 if idl_node.is_static: 1020 if idl_node.is_static:
985 return '%s::%s' % (self._interface_type_info.native_type(), function_name) 1021 return '%s::%s' % (impl_type_name, function_name)
986 interface_name = self._interface_type_info.idl_type() 1022 if cpp_type_name == impl_type_name:
987 cpp_type_name = _GetCPPTypeName(interface_name, function_name)
988 if cpp_type_name == interface_name:
989 return '%s%s' % (self._interface_type_info.receiver(), function_name) 1023 return '%s%s' % (self._interface_type_info.receiver(), function_name)
990 else: 1024 else:
991 return '%s::%s' % (cpp_type_name, function_name) 1025 return '%s::%s' % (impl_type_name, function_name)
992 1026
993 def _IsArgumentOptionalInWebCore(self, operation, argument): 1027 def _IsArgumentOptionalInWebCore(self, operation, argument):
994 if not IsOptional(argument): 1028 if not IsOptional(argument):
995 return False 1029 return False
996 if 'Callback' in argument.ext_attrs: 1030 if 'Callback' in argument.ext_attrs:
997 return False 1031 return False
998 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture': 1032 if operation.id in ['addEventListener', 'removeEventListener'] and argument. id == 'useCapture':
999 return False 1033 return False
1000 if 'ForceOptional' in argument.ext_attrs: 1034 if 'ForceOptional' in argument.ext_attrs:
1001 return False 1035 return False
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 1098 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
1065 ' return func;\n', 1099 ' return func;\n',
1066 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 1100 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
1067 1101
1068 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument): 1102 def _IsOptionalStringArgumentInInitEventMethod(interface, operation, argument):
1069 return ( 1103 return (
1070 interface.id.endswith('Event') and 1104 interface.id.endswith('Event') and
1071 operation.id.startswith('init') and 1105 operation.id.startswith('init') and
1072 argument.ext_attrs.get('Default') == 'Undefined' and 1106 argument.ext_attrs.get('Default') == 'Undefined' and
1073 argument.type.id == 'DOMString') 1107 argument.type.id == 'DOMString')
OLDNEW
« no previous file with comments | « tools/dom/scripts/idlparser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698