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

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

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