OLD | NEW |
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 26 matching lines...) Expand all Loading... |
37 from idl_types import inherits_interface | 37 from idl_types import inherits_interface |
38 from dart_interface import suppress_getter, suppress_setter | 38 from dart_interface import suppress_getter, suppress_setter |
39 import dart_types | 39 import dart_types |
40 from dart_utilities import DartUtilities | 40 from dart_utilities import DartUtilities |
41 from v8_globals import includes, interfaces | 41 from v8_globals import includes, interfaces |
42 | 42 |
43 | 43 |
44 def generate_attribute(interface, attribute): | 44 def generate_attribute(interface, attribute): |
45 idl_type = attribute.idl_type | 45 idl_type = attribute.idl_type |
46 base_idl_type = idl_type.base_type | 46 base_idl_type = idl_type.base_type |
| 47 # TODO(terry): Work around for DOMString[] base should be IDLTypeArray |
| 48 if base_idl_type == None: |
| 49 # Returns Array or Sequence. |
| 50 base_idl_type = idl_type.inner_name |
47 extended_attributes = attribute.extended_attributes | 51 extended_attributes = attribute.extended_attributes |
48 | 52 |
49 idl_type.add_includes_for_type() | 53 idl_type.add_includes_for_type() |
50 | 54 |
51 # [CheckSecurity] | 55 # [CheckSecurity] |
52 is_check_security_for_node = 'CheckSecurity' in extended_attributes | 56 is_check_security_for_node = 'CheckSecurity' in extended_attributes |
53 if is_check_security_for_node: | 57 if is_check_security_for_node: |
54 includes.add('bindings/common/BindingSecurity.h') | 58 includes.add('bindings/common/BindingSecurity.h') |
55 # [Custom] | 59 # [Custom] |
56 has_custom_getter = (('Custom' in extended_attributes and | 60 has_custom_getter = (('Custom' in extended_attributes and |
(...skipping 19 matching lines...) Expand all Loading... |
76 extended_attributes['RaisesException'] in [None, 'Setter']) | 80 extended_attributes['RaisesException'] in [None, 'Setter']) |
77 # [DartStrictTypeChecking] | 81 # [DartStrictTypeChecking] |
78 has_strict_type_checking = ( | 82 has_strict_type_checking = ( |
79 ('DartStrictTypeChecking' in extended_attributes or | 83 ('DartStrictTypeChecking' in extended_attributes or |
80 'DartStrictTypeChecking' in interface.extended_attributes) and | 84 'DartStrictTypeChecking' in interface.extended_attributes) and |
81 idl_type.is_wrapper_type) | 85 idl_type.is_wrapper_type) |
82 | 86 |
83 if (base_idl_type == 'EventHandler' and | 87 if (base_idl_type == 'EventHandler' and |
84 interface.name in ['Window', 'WorkerGlobalScope'] and | 88 interface.name in ['Window', 'WorkerGlobalScope'] and |
85 attribute.name == 'onerror'): | 89 attribute.name == 'onerror'): |
86 includes.add('bindings/v8/V8ErrorHandler.h') | 90 includes.add('bindings/core/v8/V8ErrorHandler.h') |
87 | 91 |
88 is_auto_scope = not 'DartNoAutoScope' in extended_attributes | 92 is_auto_scope = not 'DartNoAutoScope' in extended_attributes |
89 contents = { | 93 contents = { |
90 'access_control_list': access_control_list(attribute), | 94 'access_control_list': access_control_list(attribute), |
91 'activity_logging_world_list_for_getter': DartUtilities.activity_logging
_world_list(attribute, 'Getter'), # [ActivityLogging] | 95 '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] | 96 'activity_logging_world_list_for_setter': DartUtilities.activity_logging
_world_list(attribute, 'Setter'), # [ActivityLogging] |
93 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), | 97 'cached_attribute_validation_method': extended_attributes.get('CachedAtt
ribute'), |
94 'conditional_string': DartUtilities.conditional_string(attribute), | 98 'conditional_string': DartUtilities.conditional_string(attribute), |
95 'constructor_type': idl_type.constructor_type_name | 99 'constructor_type': idl_type.constructor_type_name |
96 if is_constructor_attribute(attribute) else None, | 100 if is_constructor_attribute(attribute) else None, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 not attribute.is_static): | 240 not attribute.is_static): |
237 # Pass by reference. | 241 # Pass by reference. |
238 arguments.append('*receiver') | 242 arguments.append('*receiver') |
239 | 243 |
240 # TODO(jacobr): refactor has_type_checking_nullable to better match v8. | 244 # TODO(jacobr): refactor has_type_checking_nullable to better match v8. |
241 has_type_checking_nullable = ( | 245 has_type_checking_nullable = ( |
242 (DartUtilities.has_extended_attribute_value(interface, 'TypeChecking', '
Nullable') or | 246 (DartUtilities.has_extended_attribute_value(interface, 'TypeChecking', '
Nullable') or |
243 DartUtilities.has_extended_attribute_value(attribute, 'TypeChecking', '
Nullable')) and | 247 DartUtilities.has_extended_attribute_value(attribute, 'TypeChecking', '
Nullable')) and |
244 idl_type.is_wrapper_type) | 248 idl_type.is_wrapper_type) |
245 | 249 |
246 if attribute.idl_type.is_nullable and not has_type_checking_nullable: | 250 if attribute.idl_type.is_explicit_nullable: |
247 arguments.append('isNull') | 251 arguments.append('isNull') |
248 if contents['is_getter_raises_exception']: | 252 if contents['is_getter_raises_exception']: |
249 arguments.append('es') | 253 arguments.append('es') |
250 return '%s(%s)' % (getter_name, ', '.join(arguments)) | 254 return '%s(%s)' % (getter_name, ', '.join(arguments)) |
251 | 255 |
252 | 256 |
253 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 257 CONTENT_ATTRIBUTE_GETTER_NAMES = { |
254 'boolean': 'hasAttribute', | 258 'boolean': 'hasAttribute', |
255 'long': 'getIntegralAttribute', | 259 'long': 'getIntegralAttribute', |
256 'unsigned long': 'getUnsignedIntegralAttribute', | 260 'unsigned long': 'getUnsignedIntegralAttribute', |
(...skipping 10 matching lines...) Expand all Loading... |
267 # Special-case for performance optimization. | 271 # Special-case for performance optimization. |
268 return 'get%sAttribute' % content_attribute_name.capitalize() | 272 return 'get%sAttribute' % content_attribute_name.capitalize() |
269 | 273 |
270 arguments.append(scoped_content_attribute_name(interface, attribute)) | 274 arguments.append(scoped_content_attribute_name(interface, attribute)) |
271 | 275 |
272 base_idl_type = attribute.idl_type.base_type | 276 base_idl_type = attribute.idl_type.base_type |
273 if base_idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: | 277 if base_idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: |
274 return CONTENT_ATTRIBUTE_GETTER_NAMES[base_idl_type] | 278 return CONTENT_ATTRIBUTE_GETTER_NAMES[base_idl_type] |
275 if 'URL' in attribute.extended_attributes: | 279 if 'URL' in attribute.extended_attributes: |
276 return 'getURLAttribute' | 280 return 'getURLAttribute' |
277 return 'getAttribute' | 281 return 'fastGetAttribute' |
278 | 282 |
279 | 283 |
280 def is_keep_alive_for_gc(interface, attribute): | 284 def is_keep_alive_for_gc(interface, attribute): |
281 idl_type = attribute.idl_type | 285 idl_type = attribute.idl_type |
282 base_idl_type = idl_type.base_type | 286 base_idl_type = idl_type.base_type |
283 extended_attributes = attribute.extended_attributes | 287 extended_attributes = attribute.extended_attributes |
284 return ( | 288 return ( |
285 # For readonly attributes, for performance reasons we keep the attribute | 289 # For readonly attributes, for performance reasons we keep the attribute |
286 # wrapper alive while the owner wrapper is alive, because the attribute | 290 # wrapper alive while the owner wrapper is alive, because the attribute |
287 # never changes. | 291 # never changes. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 idl_type = attribute.idl_type | 334 idl_type = attribute.idl_type |
331 | 335 |
332 # TODO(terry): Should be able to eliminate suppress_setter as we move from | 336 # TODO(terry): Should be able to eliminate suppress_setter as we move from |
333 # IGNORE_MEMBERS to DartSuppress in the IDL. | 337 # IGNORE_MEMBERS to DartSuppress in the IDL. |
334 suppress = (suppress_setter(interface.name, attribute.name) or | 338 suppress = (suppress_setter(interface.name, attribute.name) or |
335 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr
ess', 'Setter')) | 339 DartUtilities.has_extended_attribute_value(attribute, 'DartSuppr
ess', 'Setter')) |
336 contents.update({ | 340 contents.update({ |
337 'is_setter_suppressed': suppress, | 341 'is_setter_suppressed': suppress, |
338 'setter_lvalue': dart_types.check_reserved_name(attribute.name), | 342 'setter_lvalue': dart_types.check_reserved_name(attribute.name), |
339 'cpp_type': this_cpp_type, | 343 'cpp_type': this_cpp_type, |
340 'local_cpp_type': idl_type.cpp_type_args(attribute.extended_attributes,
used_as_argument=True), | 344 'local_cpp_type': idl_type.cpp_type_args(attribute.extended_attributes,
raw_type=True), |
341 'cpp_setter': setter_expression(interface, attribute, contents), | 345 'cpp_setter': setter_expression(interface, attribute, contents), |
342 'dart_value_to_local_cpp_value': | 346 'dart_value_to_local_cpp_value': |
343 attribute.idl_type.dart_value_to_local_cpp_value( | 347 attribute.idl_type.dart_value_to_local_cpp_value( |
344 interface_extended_attributes, extended_attributes, attribute.na
me, False, 1, | 348 interface_extended_attributes, extended_attributes, attribute.na
me, False, 1, |
345 contents['is_auto_scope']), | 349 contents['is_auto_scope']), |
346 }) | 350 }) |
347 | 351 |
348 | 352 |
349 def setter_expression(interface, attribute, contents): | 353 def setter_expression(interface, attribute, contents): |
350 extended_attributes = attribute.extended_attributes | 354 extended_attributes = attribute.extended_attributes |
351 arguments = DartUtilities.call_with_arguments(attribute, extended_attributes
.get('SetterCallWith')) | 355 arguments = DartUtilities.call_with_arguments(attribute, extended_attributes
.get('SetterCallWith')) |
352 | 356 |
353 this_setter_base_name = setter_base_name(interface, attribute, arguments) | 357 this_setter_base_name = setter_base_name(interface, attribute, arguments) |
354 setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_ba
se_name) | 358 setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_ba
se_name) |
355 | 359 |
356 if ('PartialInterfaceImplementedAs' in extended_attributes and | 360 if ('PartialInterfaceImplementedAs' in extended_attributes and |
357 not attribute.is_static): | 361 not attribute.is_static): |
358 arguments.append('*receiver') | 362 arguments.append('*receiver') |
359 idl_type = attribute.idl_type | 363 idl_type = attribute.idl_type |
360 if idl_type.base_type == 'EventHandler': | 364 if idl_type.base_type == 'EventHandler': |
361 getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilit
ies.cpp_name(attribute)) | 365 getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilit
ies.cpp_name(attribute)) |
362 contents['event_handler_getter_expression'] = '%s(%s)' % ( | 366 contents['event_handler_getter_expression'] = '%s(%s)' % ( |
363 getter_name, ', '.join(arguments)) | 367 getter_name, ', '.join(arguments)) |
364 # FIXME(vsm): Do we need to support this? If so, what's our analogue of | 368 # FIXME(vsm): Do we need to support this? If so, what's our analogue of |
365 # V8EventListenerList? | 369 # V8EventListenerList? |
366 arguments.append('nullptr') | 370 arguments.append('nullptr') |
367 # if (interface.name in ['Window', 'WorkerGlobalScope'] and | 371 # if (interface.name in ['Window', 'WorkerGlobalScope'] and |
368 # attribute.name == 'onerror'): | 372 # attribute.name == 'onerror'): |
369 # includes.add('bindings/v8/V8ErrorHandler.h') | 373 # includes.add('bindings/core/v8/V8ErrorHandler.h') |
370 # arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorH
andler>(jsValue, true, info.GetIsolate())') | 374 # arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorH
andler>(jsValue, true, info.GetIsolate())') |
371 # else: | 375 # else: |
372 # arguments.append('V8EventListenerList::getEventListener(jsValue, tr
ue, ListenerFindOrCreate)') | 376 # arguments.append('V8EventListenerList::getEventListener(jsValue, tr
ue, ListenerFindOrCreate)') |
373 else: | 377 else: |
374 attribute_name = dart_types.check_reserved_name(attribute.name) | 378 attribute_name = dart_types.check_reserved_name(attribute.name) |
375 arguments.append(attribute_name) | 379 arguments.append(attribute_name) |
376 if contents['is_setter_raises_exception']: | 380 if contents['is_setter_raises_exception']: |
377 arguments.append('es') | 381 arguments.append('es') |
378 | 382 |
379 return '%s(%s)' % (setter_name, ', '.join(arguments)) | 383 return '%s(%s)' % (setter_name, ', '.join(arguments)) |
(...skipping 12 matching lines...) Expand all Loading... |
392 arguments.append(scoped_content_attribute_name(interface, attribute)) | 396 arguments.append(scoped_content_attribute_name(interface, attribute)) |
393 | 397 |
394 base_idl_type = attribute.idl_type.base_type | 398 base_idl_type = attribute.idl_type.base_type |
395 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: | 399 if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: |
396 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] | 400 return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] |
397 return 'setAttribute' | 401 return 'setAttribute' |
398 | 402 |
399 | 403 |
400 def scoped_content_attribute_name(interface, attribute): | 404 def scoped_content_attribute_name(interface, attribute): |
401 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() | 405 content_attribute_name = attribute.extended_attributes['Reflect'] or attribu
te.name.lower() |
402 namespace = 'SVGNames' if interface.name.startswith('SVG') else 'HTMLNames' | 406 if interface.name.startswith('SVG'): |
403 includes.add('%s.h' % namespace) | 407 # SVG's xmlbase/xmlspace/xmllang need special behavior, i.e. |
404 return 'WebCore::%s::%sAttr' % (namespace, content_attribute_name) | 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) |
405 | 418 |
406 | 419 |
407 ################################################################################ | 420 ################################################################################ |
408 # Attribute configuration | 421 # Attribute configuration |
409 ################################################################################ | 422 ################################################################################ |
410 | 423 |
411 # [Replaceable] | 424 # [Replaceable] |
412 def setter_callback_name(interface, attribute): | 425 def setter_callback_name(interface, attribute): |
413 cpp_class_name = DartUtilities.cpp_name(interface) | 426 cpp_class_name = DartUtilities.cpp_name(interface) |
414 extended_attributes = attribute.extended_attributes | 427 extended_attributes = attribute.extended_attributes |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 # Constructors | 471 # Constructors |
459 ################################################################################ | 472 ################################################################################ |
460 | 473 |
461 idl_types.IdlType.constructor_type_name = property( | 474 idl_types.IdlType.constructor_type_name = property( |
462 # FIXME: replace this with a [ConstructorAttribute] extended attribute | 475 # FIXME: replace this with a [ConstructorAttribute] extended attribute |
463 lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor')) | 476 lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor')) |
464 | 477 |
465 | 478 |
466 def is_constructor_attribute(attribute): | 479 def is_constructor_attribute(attribute): |
467 # FIXME: replace this with [ConstructorAttribute] extended attribute | 480 # FIXME: replace this with [ConstructorAttribute] extended attribute |
468 return attribute.idl_type.base_type.endswith('Constructor') | 481 return attribute.idl_type.name.endswith('Constructor') |
469 | 482 |
470 | 483 |
471 def generate_constructor_getter(interface, attribute, contents): | 484 def generate_constructor_getter(interface, attribute, contents): |
472 contents['needs_constructor_getter_callback'] = contents['measure_as'] or co
ntents['deprecate_as'] | 485 contents['needs_constructor_getter_callback'] = contents['measure_as'] or co
ntents['deprecate_as'] |
OLD | NEW |