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

Side by Side Diff: bindings/dart/scripts/dart_attributes.py

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 5 years, 10 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 | « bindings/dart/scripts/compiler.py ('k') | bindings/dart/scripts/dart_callback_interface.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 16 matching lines...) Expand all
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """Generate template values for attributes. 29 """Generate template values for attributes.
30 30
31 Extends IdlType with property |constructor_type_name|. 31 Extends IdlType with property |constructor_type_name|.
32 32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """ 34 """
35 35
36 import idl_types 36 import idl_types
37 from idl_types import inherits_interface
38 from dart_interface import suppress_getter, suppress_setter 37 from dart_interface import suppress_getter, suppress_setter
39 import dart_types 38 import dart_types
40 from dart_utilities import DartUtilities 39 from dart_utilities import DartUtilities
41 from v8_globals import includes, interfaces 40 from v8_globals import interfaces
41
42 import v8_attributes
42 43
43 44
44 def generate_attribute(interface, attribute): 45 def attribute_context(interface, attribute):
46 # Call v8's implementation.
47 context = v8_attributes.attribute_context(interface, attribute)
48
49 extended_attributes = attribute.extended_attributes
50
51 # Augment's Dart's information to context.
45 idl_type = attribute.idl_type 52 idl_type = attribute.idl_type
46 base_idl_type = idl_type.base_type 53 base_idl_type = idl_type.base_type
47 # TODO(terry): Work around for DOMString[] base should be IDLTypeArray 54 # TODO(terry): Work around for DOMString[] base should be IDLTypeArray
48 if base_idl_type == None: 55 if base_idl_type == None:
49 # Returns Array or Sequence. 56 # Returns Array or Sequence.
50 base_idl_type = idl_type.inner_name 57 base_idl_type = idl_type.name
51 extended_attributes = attribute.extended_attributes
52 58
53 idl_type.add_includes_for_type()
54
55 # [CheckSecurity]
56 is_check_security_for_node = 'CheckSecurity' in extended_attributes
57 if is_check_security_for_node:
58 includes.add('bindings/common/BindingSecurity.h')
59 # [Custom] 59 # [Custom]
60 has_custom_getter = (('Custom' in extended_attributes and 60 has_custom_getter = (('Custom' in extended_attributes and
61 extended_attributes['Custom'] in [None, 'Getter']) or 61 extended_attributes['Custom'] in [None, 'Getter']) or
62 ('DartCustom' in extended_attributes and 62 ('DartCustom' in extended_attributes and
63 extended_attributes['DartCustom'] in [None, 'Getter', 'New'])) 63 extended_attributes['DartCustom'] in [None, 'Getter', 'New']))
64 has_custom_setter = (not attribute.is_read_only and 64 has_custom_setter = (not attribute.is_read_only and
65 (('Custom' in extended_attributes and 65 (('Custom' in extended_attributes and
66 extended_attributes['Custom'] in [None, 'Setter']) or 66 extended_attributes['Custom'] in [None, 'Setter']) or
67 ('DartCustom' in extended_attributes and 67 ('DartCustom' in extended_attributes and
68 extended_attributes['DartCustom'] in [None, 'Setter', 'New']))) 68 extended_attributes['DartCustom'] in [None, 'Setter', 'New'])))
69 69
70 is_call_with_script_state = DartUtilities.has_extended_attribute_value(attri bute, 'CallWith', 'ScriptState') 70 is_call_with_script_state = DartUtilities.has_extended_attribute_value(attri bute, 'CallWith', 'ScriptState')
71 71
72 # [CustomElementCallbacks], [Reflect] 72 is_auto_scope = not 'DartNoAutoScope' in extended_attributes
73 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
74 is_reflect = 'Reflect' in extended_attributes
75 if is_custom_element_callbacks or is_reflect:
76 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
77 # [RaisesException], [RaisesException=Setter]
78 is_setter_raises_exception = (
79 'RaisesException' in extended_attributes and
80 extended_attributes['RaisesException'] in [None, 'Setter'])
81 # [DartStrictTypeChecking]
82 has_strict_type_checking = (
83 ('DartStrictTypeChecking' in extended_attributes or
84 'DartStrictTypeChecking' in interface.extended_attributes) and
85 idl_type.is_wrapper_type)
86 73
87 if (base_idl_type == 'EventHandler' and 74 context.update({
88 interface.name in ['Window', 'WorkerGlobalScope'] and 75 'activity_logging_world_list_for_getter': DartUtilities.activity_logging_w orld_list(attribute, 'Getter'), # [ActivityLogging]
89 attribute.name == 'onerror'): 76 'activity_logging_world_list_for_setter': DartUtilities.activity_logging_w orld_list(attribute, 'Setter'), # [ActivityLogging]
90 includes.add('bindings/core/v8/V8ErrorHandler.h') 77 'deprecate_as': DartUtilities.deprecate_as(attribute), # [DeprecateAs]
78 'has_custom_getter': has_custom_getter,
79 'has_custom_setter': has_custom_setter,
80 'is_auto_scope': is_auto_scope, # Used internally (outside of templates) .
81 'is_call_with_script_state': is_call_with_script_state,
82 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
83 'measure_as': DartUtilities.measure_as(attribute), # [MeasureAs]
84 'v8_type': dart_types.v8_type(base_idl_type),
85 })
91 86
92 is_auto_scope = not 'DartNoAutoScope' in extended_attributes 87 if v8_attributes.is_constructor_attribute(attribute):
93 contents = { 88 v8_attributes.constructor_getter_context(interface, attribute, context)
94 'access_control_list': access_control_list(attribute), 89 return context
95 'activity_logging_world_list_for_getter': DartUtilities.activity_logging _world_list(attribute, 'Getter'), # [ActivityLogging] 90 if not v8_attributes.has_custom_getter(attribute):
96 'activity_logging_world_list_for_setter': DartUtilities.activity_logging _world_list(attribute, 'Setter'), # [ActivityLogging] 91 getter_context(interface, attribute, context)
97 'cached_attribute_validation_method': extended_attributes.get('CachedAtt ribute'),
98 'conditional_string': DartUtilities.conditional_string(attribute),
99 'constructor_type': idl_type.constructor_type_name
100 if is_constructor_attribute(attribute) else None,
101 'cpp_name': DartUtilities.cpp_name(attribute),
102 'cpp_type': idl_type.cpp_type,
103 'deprecate_as': DartUtilities.deprecate_as(attribute), # [DeprecateAs]
104 'enum_validation_expression': idl_type.enum_validation_expression,
105 'has_custom_getter': has_custom_getter,
106 'has_custom_setter': has_custom_setter,
107 'has_strict_type_checking': has_strict_type_checking,
108 'idl_type': str(idl_type), # need trailing [] on array for Dictionary:: ConversionContext::setConversionType
109 'is_auto_scope': is_auto_scope,
110 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
111 'is_call_with_execution_context': DartUtilities.has_extended_attribute_v alue(attribute, 'CallWith', 'ExecutionContext'),
112 'is_call_with_script_state': is_call_with_script_state,
113 'is_check_security_for_node': is_check_security_for_node,
114 'is_custom_element_callbacks': is_custom_element_callbacks,
115 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes,
116 'is_getter_raises_exception': ( # [RaisesException]
117 'RaisesException' in extended_attributes and
118 extended_attributes['RaisesException'] in [None, 'Getter']),
119 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in exten ded_attributes,
120 'is_initialized_by_event_constructor':
121 'InitializedByEventConstructor' in extended_attributes,
122 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute),
123 'is_nullable': attribute.idl_type.is_nullable,
124 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
125 'is_read_only': attribute.is_read_only,
126 'is_reflect': is_reflect,
127 'is_replaceable': 'Replaceable' in attribute.extended_attributes,
128 'is_setter_call_with_execution_context': DartUtilities.has_extended_attr ibute_value(attribute, 'SetterCallWith', 'ExecutionContext'),
129 'is_setter_raises_exception': is_setter_raises_exception,
130 'has_setter_exception_state': (
131 is_setter_raises_exception or has_strict_type_checking or
132 idl_type.is_integer_type),
133 'is_static': attribute.is_static,
134 'is_url': 'URL' in extended_attributes,
135 'is_unforgeable': 'Unforgeable' in extended_attributes,
136 'measure_as': DartUtilities.measure_as(attribute), # [MeasureAs]
137 'name': attribute.name,
138 'per_context_enabled_function': DartUtilities.per_context_enabled_functi on_name(attribute), # [PerContextEnabled]
139 'property_attributes': property_attributes(attribute),
140 'put_forwards': 'PutForwards' in extended_attributes,
141 'ref_ptr': 'RefPtrWillBeRawPtr' if idl_type.is_will_be_garbage_collected else 'RefPtr',
142 'reflect_empty': extended_attributes.get('ReflectEmpty'),
143 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''),
144 'reflect_missing': extended_attributes.get('ReflectMissing'),
145 'reflect_only': extended_attributes['ReflectOnly'].split('|')
146 if 'ReflectOnly' in extended_attributes else None,
147 'setter_callback': setter_callback_name(interface, attribute),
148 'v8_type': dart_types.v8_type(base_idl_type),
149 'runtime_enabled_function': DartUtilities.runtime_enabled_function_name( attribute), # [RuntimeEnabled]
150 'world_suffixes': ['', 'ForMainWorld']
151 if 'PerWorldBindings' in extended_attributes
152 else [''], # [PerWorldBindings]
153 }
154
155 if is_constructor_attribute(attribute):
156 generate_constructor_getter(interface, attribute, contents)
157 return contents
158 if not has_custom_getter:
159 generate_getter(interface, attribute, contents)
160 # FIXME: We did not previously support the PutForwards attribute, so I am
161 # disabling it here for now to get things compiling.
162 # We may wish to revisit this.
163 # if ((not attribute.is_read_only or 'PutForwards' in extended_attributes)):
164 if (not attribute.is_read_only): 92 if (not attribute.is_read_only):
165 generate_setter(interface, attribute, contents) 93 # FIXME: We did not previously support the PutForwards attribute, so I a m
94 # disabling it here for now to get things compiling.
95 # We may wish to revisit this.
96 # if (not has_custom_setter(attribute) and
97 # (not attribute.is_read_only or 'PutForwards' in extended_attributes)):
98 setter_context(interface, attribute, context)
166 99
167 native_entry_getter = \ 100 native_entry_getter = \
168 DartUtilities.generate_native_entry(interface.name, contents, 101 DartUtilities.generate_native_entry(
169 attribute.name, 'Getter', 102 interface.name, attribute.name, 'Getter', attribute.is_static, 0)
170 None, [], None)
171 native_entry_setter = \ 103 native_entry_setter = \
172 DartUtilities.generate_native_entry(interface.name, contents, 104 DartUtilities.generate_native_entry(
173 attribute.name, 'Setter', 105 interface.name, attribute.name, 'Setter', attribute.is_static, 1)
174 None, ["value"], None) 106 context.update({
175 contents.update({
176 'native_entry_getter': native_entry_getter, 107 'native_entry_getter': native_entry_getter,
177 'native_entry_setter': native_entry_setter, 108 'native_entry_setter': native_entry_setter,
178 }) 109 })
179 110
180 return contents 111 return context
181 112
182 113
183 ################################################################################ 114 ################################################################################
184 # Getter 115 # Getter
185 ################################################################################ 116 ################################################################################
186 117
187 def generate_getter(interface, attribute, contents): 118 def getter_context(interface, attribute, context):
119 v8_attributes.getter_context(interface, attribute, context)
120
188 idl_type = attribute.idl_type 121 idl_type = attribute.idl_type
189 base_idl_type = idl_type.base_type 122 base_idl_type = idl_type.base_type
190 extended_attributes = attribute.extended_attributes 123 extended_attributes = attribute.extended_attributes
191 name = attribute.name
192 124
193 cpp_value = getter_expression(interface, attribute, contents) 125 cpp_value = getter_expression(interface, attribute, context)
194 # Normally we can inline the function call into the return statement to 126 # Normally we can inline the function call into the return statement to
195 # avoid the overhead of using a Ref<> temporary, but for some cases 127 # avoid the overhead of using a Ref<> temporary, but for some cases
196 # (nullable types, EventHandler, [CachedAttribute], or if there are 128 # (nullable types, EventHandler, [CachedAttribute], or if there are
197 # exceptions), we need to use a local variable. 129 # exceptions), we need to use a local variable.
198 # FIXME: check if compilers are smart enough to inline this, and if so, 130 # FIXME: check if compilers are smart enough to inline this, and if so,
199 # always use a local variable (for readability and CG simplicity). 131 # always use a local variable (for readability and CG simplicity).
200 release = False 132 release = False
201 if (idl_type.is_nullable or 133 if (idl_type.is_nullable or
202 base_idl_type == 'EventHandler' or 134 base_idl_type == 'EventHandler' or
203 'CachedAttribute' in extended_attributes or 135 'CachedAttribute' in extended_attributes or
204 'ReflectOnly' in extended_attributes or 136 'ReflectOnly' in extended_attributes or
205 contents['is_getter_raises_exception']): 137 context['is_getter_raises_exception']):
206 contents['cpp_value_original'] = cpp_value 138 context['cpp_value_original'] = cpp_value
207 cpp_value = 'result' 139 cpp_value = 'result'
208 # EventHandler has special handling 140 # EventHandler has special handling
209 if base_idl_type != 'EventHandler' and idl_type.is_interface_type: 141 if base_idl_type != 'EventHandler' and idl_type.is_interface_type:
210 release = True 142 release = True
211 143
212 dart_set_return_value = \ 144 dart_set_return_value = \
213 idl_type.dart_set_return_value(cpp_value, 145 idl_type.dart_set_return_value(cpp_value,
214 extended_attributes=extended_attributes, 146 extended_attributes=extended_attributes,
215 script_wrappable='impl', 147 script_wrappable='impl',
216 release=release, 148 release=release,
217 for_main_world=False, 149 for_main_world=False,
218 auto_scope=contents['is_auto_scope']) 150 auto_scope=context['is_auto_scope'])
219 151
220 # TODO(terry): Should be able to eliminate suppress_getter as we move from 152 # TODO(terry): Should be able to eliminate suppress_getter as we move from
221 # IGNORE_MEMBERS to DartSuppress in the IDL. 153 # IGNORE_MEMBERS to DartSuppress in the IDL.
222 suppress = (suppress_getter(interface.name, attribute.name) or 154 suppress = (suppress_getter(interface.name, attribute.name) or
223 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr ess', 'Getter')) 155 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr ess', 'Getter'))
224 156
225 contents.update({ 157 context.update({
226 'cpp_value': cpp_value, 158 'cpp_value': cpp_value,
227 'dart_set_return_value': dart_set_return_value, 159 'dart_set_return_value': dart_set_return_value,
228 'is_getter_suppressed': suppress, 160 'is_getter_suppressed': suppress,
229 }) 161 })
230 162
231 163
232 def getter_expression(interface, attribute, contents): 164 def getter_expression(interface, attribute, context):
165 v8_attributes.getter_expression(interface, attribute, context)
166
233 arguments = [] 167 arguments = []
234 idl_type = attribute.idl_type 168 this_getter_base_name = v8_attributes.getter_base_name(interface, attribute, arguments)
235 this_getter_base_name = getter_base_name(interface, attribute, arguments)
236 getter_name = DartUtilities.scoped_name(interface, attribute, this_getter_ba se_name) 169 getter_name = DartUtilities.scoped_name(interface, attribute, this_getter_ba se_name)
237 170
238 arguments.extend(DartUtilities.call_with_arguments(attribute)) 171 arguments.extend(DartUtilities.call_with_arguments(
172 attribute.extended_attributes.get('CallWith')))
239 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and 173 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and
240 not attribute.is_static): 174 not attribute.is_static):
241 # Pass by reference. 175 # Pass by reference.
242 arguments.append('*receiver') 176 arguments.append('*receiver')
243 177
244 # TODO(jacobr): refactor has_type_checking_nullable to better match v8.
245 has_type_checking_nullable = (
246 (DartUtilities.has_extended_attribute_value(interface, 'TypeChecking', ' Nullable') or
247 DartUtilities.has_extended_attribute_value(attribute, 'TypeChecking', ' Nullable')) and
248 idl_type.is_wrapper_type)
249
250 if attribute.idl_type.is_explicit_nullable: 178 if attribute.idl_type.is_explicit_nullable:
251 arguments.append('isNull') 179 arguments.append('isNull')
252 if contents['is_getter_raises_exception']: 180 if context['is_getter_raises_exception']:
253 arguments.append('es') 181 arguments.append('es')
254 return '%s(%s)' % (getter_name, ', '.join(arguments)) 182 return '%s(%s)' % (getter_name, ', '.join(arguments))
255 183
256 184
257 CONTENT_ATTRIBUTE_GETTER_NAMES = {
258 'boolean': 'hasAttribute',
259 'long': 'getIntegralAttribute',
260 'unsigned long': 'getUnsignedIntegralAttribute',
261 }
262
263
264 def getter_base_name(interface, attribute, arguments):
265 extended_attributes = attribute.extended_attributes
266 if 'Reflect' not in extended_attributes:
267 return DartUtilities.uncapitalize(DartUtilities.cpp_name(attribute))
268
269 content_attribute_name = extended_attributes['Reflect'] or attribute.name.lo wer()
270 if content_attribute_name in ['class', 'id', 'name']:
271 # Special-case for performance optimization.
272 return 'get%sAttribute' % content_attribute_name.capitalize()
273
274 arguments.append(scoped_content_attribute_name(interface, attribute))
275
276 base_idl_type = attribute.idl_type.base_type
277 if base_idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES:
278 return CONTENT_ATTRIBUTE_GETTER_NAMES[base_idl_type]
279 if 'URL' in attribute.extended_attributes:
280 return 'getURLAttribute'
281 return 'fastGetAttribute'
282
283
284 def is_keep_alive_for_gc(interface, attribute):
285 idl_type = attribute.idl_type
286 base_idl_type = idl_type.base_type
287 extended_attributes = attribute.extended_attributes
288 return (
289 # For readonly attributes, for performance reasons we keep the attribute
290 # wrapper alive while the owner wrapper is alive, because the attribute
291 # never changes.
292 (attribute.is_read_only and
293 idl_type.is_wrapper_type and
294 # There are some exceptions, however:
295 not(
296 # Node lifetime is managed by object grouping.
297 inherits_interface(interface.name, 'Node') or
298 inherits_interface(base_idl_type, 'Node') or
299 # A self-reference is unnecessary.
300 attribute.name == 'self' or
301 # FIXME: Remove these hard-coded hacks.
302 base_idl_type in ['EventTarget', 'Window'] or
303 base_idl_type.startswith(('HTML', 'SVG')))))
304
305
306 ################################################################################ 185 ################################################################################
307 # Setter 186 # Setter
308 ################################################################################ 187 ################################################################################
309 188
310 def generate_setter(interface, attribute, contents): 189 def setter_context(interface, attribute, context):
190 v8_attributes.setter_context(interface, attribute, context)
191
311 def target_attribute(): 192 def target_attribute():
312 target_interface_name = attribute.idl_type.base_type 193 target_interface_name = attribute.idl_type.base_type
313 target_attribute_name = extended_attributes['PutForwards'] 194 target_attribute_name = extended_attributes['PutForwards']
314 target_interface = interfaces[target_interface_name] 195 target_interface = interfaces[target_interface_name]
315 try: 196 try:
316 return next(attribute 197 return next(attribute
317 for attribute in target_interface.attributes 198 for attribute in target_interface.attributes
318 if attribute.name == target_attribute_name) 199 if attribute.name == target_attribute_name)
319 except StopIteration: 200 except StopIteration:
320 raise Exception('[PutForward] target not found:\n' 201 raise Exception('[PutForward] target not found:\n'
321 'Attribute "%s" is not present in interface "%s"' % 202 'Attribute "%s" is not present in interface "%s"' %
322 (target_attribute_name, target_interface_name)) 203 (target_attribute_name, target_interface_name))
323 204
324 extended_attributes = attribute.extended_attributes 205 extended_attributes = attribute.extended_attributes
325 interface_extended_attributes = interface.extended_attributes
326 206
327 if 'PutForwards' in extended_attributes: 207 if 'PutForwards' in extended_attributes:
328 # Use target attribute in place of original attribute 208 # Use target attribute in place of original attribute
329 attribute = target_attribute() 209 attribute = target_attribute()
330 this_cpp_type = 'DartStringAdapter' 210 this_cpp_type = 'DartStringAdapter'
331 else: 211 else:
332 this_cpp_type = contents['cpp_type'] 212 this_cpp_type = context['cpp_type']
333 213
334 idl_type = attribute.idl_type 214 idl_type = attribute.idl_type
335 215
336 # TODO(terry): Should be able to eliminate suppress_setter as we move from 216 # TODO(terry): Should be able to eliminate suppress_setter as we move from
337 # IGNORE_MEMBERS to DartSuppress in the IDL. 217 # IGNORE_MEMBERS to DartSuppress in the IDL.
338 suppress = (suppress_setter(interface.name, attribute.name) or 218 suppress = (suppress_setter(interface.name, attribute.name) or
339 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr ess', 'Setter')) 219 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr ess', 'Setter'))
340 contents.update({ 220 context.update({
221 'has_setter_exception_state': (
222 context['is_setter_raises_exception'] or context['has_type_checking_ interface'] or
223 idl_type.is_integer_type),
341 'is_setter_suppressed': suppress, 224 'is_setter_suppressed': suppress,
342 'setter_lvalue': dart_types.check_reserved_name(attribute.name), 225 'setter_lvalue': dart_types.check_reserved_name(attribute.name),
343 'cpp_type': this_cpp_type, 226 'cpp_type': this_cpp_type,
344 'local_cpp_type': idl_type.cpp_type_args(attribute.extended_attributes, raw_type=True), 227 'local_cpp_type': idl_type.cpp_type_args(attribute.extended_attributes, raw_type=True),
345 'cpp_setter': setter_expression(interface, attribute, contents),
346 'dart_value_to_local_cpp_value': 228 'dart_value_to_local_cpp_value':
347 attribute.idl_type.dart_value_to_local_cpp_value( 229 attribute.idl_type.dart_value_to_local_cpp_value(
348 interface_extended_attributes, extended_attributes, attribute.na me, False, 1, 230 extended_attributes, attribute.name, False,
349 contents['is_auto_scope']), 231 context['has_type_checking_interface'], 1,
232 context['is_auto_scope']),
350 }) 233 })
351 234
235 # setter_expression() depends on context values we set above.
236 context['cpp_setter'] = setter_expression(interface, attribute, context)
352 237
353 def setter_expression(interface, attribute, contents): 238
239 def setter_expression(interface, attribute, context):
354 extended_attributes = attribute.extended_attributes 240 extended_attributes = attribute.extended_attributes
355 arguments = DartUtilities.call_with_arguments(attribute, extended_attributes .get('SetterCallWith')) 241 arguments = DartUtilities.call_with_arguments(
242 extended_attributes.get('SetterCallWith') or
243 extended_attributes.get('CallWith'))
356 244
357 this_setter_base_name = setter_base_name(interface, attribute, arguments) 245 this_setter_base_name = v8_attributes.setter_base_name(interface, attribute, arguments)
358 setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_ba se_name) 246 setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_ba se_name)
359 247
360 if ('PartialInterfaceImplementedAs' in extended_attributes and 248 if ('PartialInterfaceImplementedAs' in extended_attributes and
361 not attribute.is_static): 249 not attribute.is_static):
362 arguments.append('*receiver') 250 arguments.append('*receiver')
363 idl_type = attribute.idl_type 251 idl_type = attribute.idl_type
364 if idl_type.base_type == 'EventHandler': 252 if idl_type.base_type == 'EventHandler':
365 getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilit ies.cpp_name(attribute)) 253 getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilit ies.cpp_name(attribute))
366 contents['event_handler_getter_expression'] = '%s(%s)' % ( 254 context['event_handler_getter_expression'] = '%s(%s)' % (
367 getter_name, ', '.join(arguments)) 255 getter_name, ', '.join(arguments))
368 # FIXME(vsm): Do we need to support this? If so, what's our analogue of 256 # FIXME(vsm): Do we need to support this? If so, what's our analogue of
369 # V8EventListenerList? 257 # V8EventListenerList?
370 arguments.append('nullptr') 258 arguments.append('nullptr')
371 # if (interface.name in ['Window', 'WorkerGlobalScope'] and 259 # if (interface.name in ['Window', 'WorkerGlobalScope'] and
372 # attribute.name == 'onerror'): 260 # attribute.name == 'onerror'):
373 # includes.add('bindings/core/v8/V8ErrorHandler.h') 261 # includes.add('bindings/core/v8/V8ErrorHandler.h')
374 # arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorH andler>(jsValue, true, info.GetIsolate())') 262 # arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorH andler>(jsValue, true, info.GetIsolate())')
375 # else: 263 # else:
376 # arguments.append('V8EventListenerList::getEventListener(jsValue, tr ue, ListenerFindOrCreate)') 264 # arguments.append('V8EventListenerList::getEventListener(jsValue, tr ue, ListenerFindOrCreate)')
377 else: 265 else:
378 attribute_name = dart_types.check_reserved_name(attribute.name) 266 attribute_name = dart_types.check_reserved_name(attribute.name)
379 arguments.append(attribute_name) 267 arguments.append(attribute_name)
380 if contents['is_setter_raises_exception']: 268 if context['is_setter_raises_exception']:
381 arguments.append('es') 269 arguments.append('es')
382 270
383 return '%s(%s)' % (setter_name, ', '.join(arguments)) 271 return '%s(%s)' % (setter_name, ', '.join(arguments))
384 272
385 273
386 CONTENT_ATTRIBUTE_SETTER_NAMES = {
387 'boolean': 'setBooleanAttribute',
388 'long': 'setIntegralAttribute',
389 'unsigned long': 'setUnsignedIntegralAttribute',
390 }
391
392
393 def setter_base_name(interface, attribute, arguments):
394 if 'Reflect' not in attribute.extended_attributes:
395 return 'set%s' % DartUtilities.capitalize(DartUtilities.cpp_name(attribu te))
396 arguments.append(scoped_content_attribute_name(interface, attribute))
397
398 base_idl_type = attribute.idl_type.base_type
399 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES:
400 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type]
401 return 'setAttribute'
402
403
404 def scoped_content_attribute_name(interface, attribute):
405 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu te.name.lower()
406 if interface.name.startswith('SVG'):
407 # SVG's xmlbase/xmlspace/xmllang need special behavior, i.e.
408 # it is in XMLNames namespace and the generated attribute has no xml pre fix.
409 if attribute.name.startswith('xml'):
410 namespace = 'XMLNames'
411 content_attribute_name = content_attribute_name[3:]
412 else:
413 namespace = 'SVGNames'
414 else:
415 namespace = 'HTMLNames'
416 includes.add('core/%s.h' % namespace)
417 return '%s::%sAttr' % (namespace, content_attribute_name)
418
419
420 ################################################################################ 274 ################################################################################
421 # Attribute configuration 275 # Attribute configuration
422 ################################################################################ 276 ################################################################################
423 277
424 # [Replaceable] 278 # [Replaceable]
425 def setter_callback_name(interface, attribute): 279 def setter_callback_name(interface, attribute):
426 cpp_class_name = DartUtilities.cpp_name(interface) 280 cpp_class_name = DartUtilities.cpp_name(interface)
427 extended_attributes = attribute.extended_attributes 281 extended_attributes = attribute.extended_attributes
428 if (('Replaceable' in extended_attributes and 282 if (('Replaceable' in extended_attributes and
429 'PutForwards' not in extended_attributes) or 283 'PutForwards' not in extended_attributes) or
430 is_constructor_attribute(attribute)): 284 v8_attributes.is_constructor_attribute(attribute)):
431 # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors 285 # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
432 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name) 286 return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp _class_name)
433 # FIXME:disabling PutForwards for now since we didn't support it before 287 # FIXME:disabling PutForwards for now since we didn't support it before
434 # if attribute.is_read_only and 'PutForwards' not in extended_attributes: 288 # if attribute.is_read_only and 'PutForwards' not in extended_attributes:
435 if attribute.is_read_only: 289 if attribute.is_read_only:
436 return '0' 290 return '0'
437 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name) 291 return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribut e.name)
438 292
439 293
440 # [DoNotCheckSecurity], [Unforgeable]
441 def access_control_list(attribute):
442 extended_attributes = attribute.extended_attributes
443 access_control = []
444 if 'DoNotCheckSecurity' in extended_attributes:
445 do_not_check_security = extended_attributes['DoNotCheckSecurity']
446 if do_not_check_security == 'Setter':
447 access_control.append('v8::ALL_CAN_WRITE')
448 else:
449 access_control.append('v8::ALL_CAN_READ')
450 if (not attribute.is_read_only or
451 'Replaceable' in extended_attributes):
452 access_control.append('v8::ALL_CAN_WRITE')
453 if 'Unforgeable' in extended_attributes:
454 access_control.append('v8::PROHIBITS_OVERWRITING')
455 return access_control or ['v8::DEFAULT']
456
457
458 # [NotEnumerable], [Unforgeable]
459 def property_attributes(attribute):
460 extended_attributes = attribute.extended_attributes
461 property_attributes_list = []
462 if ('NotEnumerable' in extended_attributes or
463 is_constructor_attribute(attribute)):
464 property_attributes_list.append('v8::DontEnum')
465 if 'Unforgeable' in extended_attributes:
466 property_attributes_list.append('v8::DontDelete')
467 return property_attributes_list or ['v8::None']
468
469
470 ################################################################################ 294 ################################################################################
471 # Constructors 295 # Constructors
472 ################################################################################ 296 ################################################################################
473 297
474 idl_types.IdlType.constructor_type_name = property( 298 idl_types.IdlType.constructor_type_name = property(
475 # FIXME: replace this with a [ConstructorAttribute] extended attribute 299 # FIXME: replace this with a [ConstructorAttribute] extended attribute
476 lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor')) 300 lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor'))
477
478
479 def is_constructor_attribute(attribute):
480 # FIXME: replace this with [ConstructorAttribute] extended attribute
481 return attribute.idl_type.name.endswith('Constructor')
482
483
484 def generate_constructor_getter(interface, attribute, contents):
485 contents['needs_constructor_getter_callback'] = contents['measure_as'] or co ntents['deprecate_as']
OLDNEW
« no previous file with comments | « bindings/dart/scripts/compiler.py ('k') | bindings/dart/scripts/dart_callback_interface.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698