| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 # [PrimaryGlobal] and [Global] | 207 # [PrimaryGlobal] and [Global] |
| 208 is_global = ('PrimaryGlobal' in extended_attributes or | 208 is_global = ('PrimaryGlobal' in extended_attributes or |
| 209 'Global' in extended_attributes) | 209 'Global' in extended_attributes) |
| 210 | 210 |
| 211 # [ImmutablePrototype] | 211 # [ImmutablePrototype] |
| 212 # TODO(littledan): Is it possible to deduce this based on inheritance, | 212 # TODO(littledan): Is it possible to deduce this based on inheritance, |
| 213 # as in the WebIDL spec? | 213 # as in the WebIDL spec? |
| 214 is_immutable_prototype = is_global or 'ImmutablePrototype' in extended_attri
butes | 214 is_immutable_prototype = is_global or 'ImmutablePrototype' in extended_attri
butes |
| 215 | 215 |
| 216 wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Nod
e') else 'ObjectClassId') | 216 wrapper_class_id = ('kNodeClassId' if inherits_interface(interface.name, 'No
de') else 'kObjectClassId') |
| 217 | 217 |
| 218 # [ActiveScriptWrappable] must be accompanied with [DependentLifetime]. | 218 # [ActiveScriptWrappable] must be accompanied with [DependentLifetime]. |
| 219 if active_scriptwrappable and not is_dependent_lifetime: | 219 if active_scriptwrappable and not is_dependent_lifetime: |
| 220 raise Exception('[ActiveScriptWrappable] interface must also specify ' | 220 raise Exception('[ActiveScriptWrappable] interface must also specify ' |
| 221 '[DependentLifetime]: %s' % interface.name) | 221 '[DependentLifetime]: %s' % interface.name) |
| 222 | 222 |
| 223 v8_class_name = v8_utilities.v8_class_name(interface) | 223 v8_class_name = v8_utilities.v8_class_name(interface) |
| 224 cpp_class_name = cpp_name(interface) | 224 cpp_class_name = cpp_name(interface) |
| 225 cpp_class_name_or_partial = cpp_name_or_partial(interface) | 225 cpp_class_name_or_partial = cpp_name_or_partial(interface) |
| 226 v8_class_name_or_partial = v8_utilities.v8_class_name_or_partial(interface) | 226 v8_class_name_or_partial = v8_utilities.v8_class_name_or_partial(interface) |
| 227 | 227 |
| 228 # TODO(peria): Generate the target list from 'Window' and 'HTMLDocument'. | 228 # TODO(peria): Generate the target list from 'Window' and 'HTMLDocument'. |
| 229 needs_runtime_enabled_installer = v8_class_name in [ | 229 needs_runtime_enabled_installer = v8_class_name in [ |
| 230 'V8Window', 'V8HTMLDocument', 'V8Document', 'V8Node', 'V8EventTarget'] | 230 'V8Window', 'V8HTMLDocument', 'V8Document', 'V8Node', 'V8EventTarget'] |
| 231 | 231 |
| 232 context = { | 232 context = { |
| 233 'cpp_class': cpp_class_name, | 233 'cpp_class': cpp_class_name, |
| 234 'cpp_class_or_partial': cpp_class_name_or_partial, | 234 'cpp_class_or_partial': cpp_class_name_or_partial, |
| 235 'event_target_inheritance': 'InheritFromEventTarget' if is_event_target
else 'NotInheritFromEventTarget', | 235 'event_target_inheritance': 'kInheritFromEventTarget' if is_event_target
else 'kNotInheritFromEventTarget', |
| 236 'is_gc_type': True, | 236 'is_gc_type': True, |
| 237 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 | 237 # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 |
| 238 'has_access_check_callbacks': (is_check_security and | 238 'has_access_check_callbacks': (is_check_security and |
| 239 interface.name != 'EventTarget'), | 239 interface.name != 'EventTarget'), |
| 240 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] | 240 'has_custom_legacy_call_as_function': has_extended_attribute_value(inter
face, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] |
| 241 'has_partial_interface': len(interface.partial_interfaces) > 0, | 241 'has_partial_interface': len(interface.partial_interfaces) > 0, |
| 242 'header_includes': header_includes, | 242 'header_includes': header_includes, |
| 243 'interface_name': interface.name, | 243 'interface_name': interface.name, |
| 244 'is_array_buffer_or_view': is_array_buffer_or_view, | 244 'is_array_buffer_or_view': is_array_buffer_or_view, |
| 245 'is_check_security': is_check_security, | 245 'is_check_security': is_check_security, |
| 246 'is_event_target': is_event_target, | 246 'is_event_target': is_event_target, |
| 247 'is_exception': interface.is_exception, | 247 'is_exception': interface.is_exception, |
| 248 'is_global': is_global, | 248 'is_global': is_global, |
| 249 'is_immutable_prototype': is_immutable_prototype, | 249 'is_immutable_prototype': is_immutable_prototype, |
| 250 'is_node': inherits_interface(interface.name, 'Node'), | 250 'is_node': inherits_interface(interface.name, 'Node'), |
| 251 'is_partial': interface.is_partial, | 251 'is_partial': interface.is_partial, |
| 252 'is_typed_array_type': is_typed_array_type, | 252 'is_typed_array_type': is_typed_array_type, |
| 253 'lifetime': 'Dependent' if is_dependent_lifetime else 'Independent', | 253 'lifetime': 'kDependent' if is_dependent_lifetime else 'kIndependent', |
| 254 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] | 254 'measure_as': v8_utilities.measure_as(interface, None), # [MeasureAs] |
| 255 'needs_runtime_enabled_installer': needs_runtime_enabled_installer, | 255 'needs_runtime_enabled_installer': needs_runtime_enabled_installer, |
| 256 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct
ion_name(interface), | 256 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_funct
ion_name(interface), |
| 257 'parent_interface': parent_interface, | 257 'parent_interface': parent_interface, |
| 258 'pass_cpp_type': cpp_name(interface) + '*', | 258 'pass_cpp_type': cpp_name(interface) + '*', |
| 259 'active_scriptwrappable': active_scriptwrappable, | 259 'active_scriptwrappable': active_scriptwrappable, |
| 260 'runtime_enabled_feature_name': runtime_enabled_feature_name(interface),
# [RuntimeEnabled] | 260 'runtime_enabled_feature_name': runtime_enabled_feature_name(interface),
# [RuntimeEnabled] |
| 261 'v8_class': v8_class_name, | 261 'v8_class': v8_class_name, |
| 262 'v8_class_or_partial': v8_class_name_or_partial, | 262 'v8_class_or_partial': v8_class_name_or_partial, |
| 263 'wrapper_class_id': wrapper_class_id, | 263 'wrapper_class_id': wrapper_class_id, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 }) | 532 }) |
| 533 | 533 |
| 534 def generated_iterator_method(name, implemented_as=None): | 534 def generated_iterator_method(name, implemented_as=None): |
| 535 return generated_method( | 535 return generated_method( |
| 536 return_type=IdlType('Iterator'), | 536 return_type=IdlType('Iterator'), |
| 537 name=name, | 537 name=name, |
| 538 extended_attributes=used_extended_attributes, | 538 extended_attributes=used_extended_attributes, |
| 539 implemented_as=implemented_as) | 539 implemented_as=implemented_as) |
| 540 | 540 |
| 541 if not interface.has_indexed_elements: | 541 if not interface.has_indexed_elements: |
| 542 iterator_method = generated_iterator_method('iterator', implemented_
as='iterator') | 542 iterator_method = generated_iterator_method('iterator', implemented_
as='GetIterator') |
| 543 | 543 |
| 544 if interface.iterable or interface.maplike or interface.setlike: | 544 if interface.iterable or interface.maplike or interface.setlike: |
| 545 non_overridable_methods = [] | 545 non_overridable_methods = [] |
| 546 overridable_methods = [] | 546 overridable_methods = [] |
| 547 | 547 |
| 548 non_overridable_methods.extend([ | 548 non_overridable_methods.extend([ |
| 549 generated_iterator_method('keys'), | 549 generated_iterator_method('Keys'), |
| 550 generated_iterator_method('values'), | 550 generated_iterator_method('Values'), |
| 551 generated_iterator_method('entries'), | 551 generated_iterator_method('Entries'), |
| 552 | 552 |
| 553 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) | 553 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) |
| 554 generated_method(IdlType('void'), 'forEach', | 554 generated_method(IdlType('void'), 'ForEach', |
| 555 arguments=[generated_argument(IdlType('Function
'), 'callback'), | 555 arguments=[generated_argument(IdlType('Function
'), 'callback'), |
| 556 generated_argument(IdlType('any'), '
thisArg', | 556 generated_argument(IdlType('any'), '
thisArg', |
| 557 is_optional=True, | 557 is_optional=True, |
| 558 extended_attribut
es={'Default': 'Undefined'})], | 558 extended_attribut
es={'Default': 'Undefined'})], |
| 559 extended_attributes=forEach_extended_attributes
), | 559 extended_attributes=forEach_extended_attributes
), |
| 560 ]) | 560 ]) |
| 561 | 561 |
| 562 if interface.maplike: | 562 if interface.maplike: |
| 563 key_argument = generated_argument(interface.maplike.key_type, 'k
ey') | 563 key_argument = generated_argument(interface.maplike.key_type, 'k
ey') |
| 564 value_argument = generated_argument(interface.maplike.value_type
, 'value') | 564 value_argument = generated_argument(interface.maplike.value_type
, 'value') |
| 565 | 565 |
| 566 non_overridable_methods.extend([ | 566 non_overridable_methods.extend([ |
| 567 generated_method(IdlType('boolean'), 'has', | 567 generated_method(IdlType('boolean'), 'Has', |
| 568 arguments=[key_argument], | 568 arguments=[key_argument], |
| 569 extended_attributes=used_extended_attribute
s), | 569 extended_attributes=used_extended_attribute
s), |
| 570 generated_method(IdlType('any'), 'get', | 570 generated_method(IdlType('any'), 'Get', |
| 571 arguments=[key_argument], | 571 arguments=[key_argument], |
| 572 extended_attributes=used_extended_attribute
s), | 572 extended_attributes=used_extended_attribute
s), |
| 573 ]) | 573 ]) |
| 574 | 574 |
| 575 if not interface.maplike.is_read_only: | 575 if not interface.maplike.is_read_only: |
| 576 overridable_methods.extend([ | 576 overridable_methods.extend([ |
| 577 generated_method(IdlType('void'), 'clear', | 577 generated_method(IdlType('void'), 'Clear', |
| 578 extended_attributes=used_extended_attri
butes), | 578 extended_attributes=used_extended_attri
butes), |
| 579 generated_method(IdlType('boolean'), 'delete', | 579 generated_method(IdlType('boolean'), 'Delete', |
| 580 arguments=[key_argument], | 580 arguments=[key_argument], |
| 581 extended_attributes=used_extended_attri
butes), | 581 extended_attributes=used_extended_attri
butes), |
| 582 generated_method(IdlType(interface.name), 'set', | 582 generated_method(IdlType(interface.name), 'Set', |
| 583 arguments=[key_argument, value_argument
], | 583 arguments=[key_argument, value_argument
], |
| 584 extended_attributes=used_extended_attri
butes), | 584 extended_attributes=used_extended_attri
butes), |
| 585 ]) | 585 ]) |
| 586 | 586 |
| 587 if interface.setlike: | 587 if interface.setlike: |
| 588 value_argument = generated_argument(interface.setlike.value_type
, 'value') | 588 value_argument = generated_argument(interface.setlike.value_type
, 'value') |
| 589 | 589 |
| 590 non_overridable_methods.extend([ | 590 non_overridable_methods.extend([ |
| 591 generated_method(IdlType('boolean'), 'has', | 591 generated_method(IdlType('boolean'), 'Has', |
| 592 arguments=[value_argument], | 592 arguments=[value_argument], |
| 593 extended_attributes=used_extended_attribute
s), | 593 extended_attributes=used_extended_attribute
s), |
| 594 ]) | 594 ]) |
| 595 | 595 |
| 596 if not interface.setlike.is_read_only: | 596 if not interface.setlike.is_read_only: |
| 597 overridable_methods.extend([ | 597 overridable_methods.extend([ |
| 598 generated_method(IdlType(interface.name), 'add', | 598 generated_method(IdlType(interface.name), 'Add', |
| 599 arguments=[value_argument], | 599 arguments=[value_argument], |
| 600 extended_attributes=used_extended_attri
butes), | 600 extended_attributes=used_extended_attri
butes), |
| 601 generated_method(IdlType('void'), 'clear', | 601 generated_method(IdlType('void'), 'Clear', |
| 602 extended_attributes=used_extended_attri
butes), | 602 extended_attributes=used_extended_attri
butes), |
| 603 generated_method(IdlType('boolean'), 'delete', | 603 generated_method(IdlType('boolean'), 'Delete', |
| 604 arguments=[value_argument], | 604 arguments=[value_argument], |
| 605 extended_attributes=used_extended_attri
butes), | 605 extended_attributes=used_extended_attri
butes), |
| 606 ]) | 606 ]) |
| 607 | 607 |
| 608 methods_by_name = {} | 608 methods_by_name = {} |
| 609 for method in methods: | 609 for method in methods: |
| 610 methods_by_name.setdefault(method['name'], []).append(method) | 610 methods_by_name.setdefault(method['name'], []).append(method) |
| 611 | 611 |
| 612 for non_overridable_method in non_overridable_methods: | 612 for non_overridable_method in non_overridable_methods: |
| 613 if non_overridable_method['name'] in methods_by_name: | 613 if non_overridable_method['name'] in methods_by_name: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 633 if serializer.operation: | 633 if serializer.operation: |
| 634 return_type = serializer.operation.idl_type | 634 return_type = serializer.operation.idl_type |
| 635 implemented_as = serializer.operation.name | 635 implemented_as = serializer.operation.name |
| 636 else: | 636 else: |
| 637 return_type = IdlType('any') | 637 return_type = IdlType('any') |
| 638 implemented_as = None | 638 implemented_as = None |
| 639 if 'CallWith' not in serializer_ext_attrs: | 639 if 'CallWith' not in serializer_ext_attrs: |
| 640 serializer_ext_attrs['CallWith'] = 'ScriptState' | 640 serializer_ext_attrs['CallWith'] = 'ScriptState' |
| 641 methods.append(generated_method( | 641 methods.append(generated_method( |
| 642 return_type=return_type, | 642 return_type=return_type, |
| 643 name='toJSON', | 643 name='ToJSON', |
| 644 extended_attributes=serializer_ext_attrs, | 644 extended_attributes=serializer_ext_attrs, |
| 645 implemented_as=implemented_as)) | 645 implemented_as=implemented_as)) |
| 646 | 646 |
| 647 # Stringifier | 647 # Stringifier |
| 648 if interface.stringifier: | 648 if interface.stringifier: |
| 649 stringifier = interface.stringifier | 649 stringifier = interface.stringifier |
| 650 stringifier_ext_attrs = stringifier.extended_attributes.copy() | 650 stringifier_ext_attrs = stringifier.extended_attributes.copy() |
| 651 if stringifier.attribute: | 651 if stringifier.attribute: |
| 652 implemented_as = stringifier.attribute.name | 652 implemented_as = stringifier.attribute.name |
| 653 elif stringifier.operation: | 653 elif stringifier.operation: |
| 654 implemented_as = stringifier.operation.name | 654 implemented_as = stringifier.operation.name |
| 655 else: | 655 else: |
| 656 implemented_as = 'toString' | 656 implemented_as = 'ToString' |
| 657 methods.append(generated_method( | 657 methods.append(generated_method( |
| 658 return_type=IdlType('DOMString'), | 658 return_type=IdlType('DOMString'), |
| 659 name='toString', | 659 name='ToString', |
| 660 extended_attributes=stringifier_ext_attrs, | 660 extended_attributes=stringifier_ext_attrs, |
| 661 implemented_as=implemented_as)) | 661 implemented_as=implemented_as)) |
| 662 | 662 |
| 663 for method in methods: | 663 for method in methods: |
| 664 # The value of the Function object’s “length” property is a Number | 664 # The value of the Function object’s “length” property is a Number |
| 665 # determined as follows: | 665 # determined as follows: |
| 666 # 1. Let S be the effective overload set for regular operations (if the | 666 # 1. Let S be the effective overload set for regular operations (if the |
| 667 # operation is a regular operation) or for static operations (if the | 667 # operation is a regular operation) or for static operations (if the |
| 668 # operation is a static operation) with identifier id on interface I and | 668 # operation is a static operation) with identifier id on interface I and |
| 669 # with argument count 0. | 669 # with argument count 0. |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 yield test, method | 1123 yield test, method |
| 1124 except StopIteration: | 1124 except StopIteration: |
| 1125 pass | 1125 pass |
| 1126 | 1126 |
| 1127 # 3. Otherwise: if V is null or undefined, and there is an entry in S that | 1127 # 3. Otherwise: if V is null or undefined, and there is an entry in S that |
| 1128 # has one of the following types at position i of its type list, | 1128 # has one of the following types at position i of its type list, |
| 1129 # • a nullable type | 1129 # • a nullable type |
| 1130 try: | 1130 try: |
| 1131 method = next(method for idl_type, method in idl_types_methods | 1131 method = next(method for idl_type, method in idl_types_methods |
| 1132 if idl_type.is_nullable) | 1132 if idl_type.is_nullable) |
| 1133 test = 'isUndefinedOrNull(%s)' % cpp_value | 1133 test = 'IsUndefinedOrNull(%s)' % cpp_value |
| 1134 yield test, method | 1134 yield test, method |
| 1135 except StopIteration: | 1135 except StopIteration: |
| 1136 pass | 1136 pass |
| 1137 | 1137 |
| 1138 # 4. Otherwise: if V is a platform object – but not a platform array | 1138 # 4. Otherwise: if V is a platform object – but not a platform array |
| 1139 # object – and there is an entry in S that has one of the following | 1139 # object – and there is an entry in S that has one of the following |
| 1140 # types at position i of its type list, | 1140 # types at position i of its type list, |
| 1141 # • an interface type that V implements | 1141 # • an interface type that V implements |
| 1142 # (Unlike most of these tests, this can return multiple methods, since we | 1142 # (Unlike most of these tests, this can return multiple methods, since we |
| 1143 # test if it implements an interface. Thus we need a for loop, not a next.) | 1143 # test if it implements an interface. Thus we need a for loop, not a next.) |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 return v8_methods.method_context(interface, caller) | 1385 return v8_methods.method_context(interface, caller) |
| 1386 | 1386 |
| 1387 def property_getter(getter, cpp_arguments): | 1387 def property_getter(getter, cpp_arguments): |
| 1388 if not getter: | 1388 if not getter: |
| 1389 return None | 1389 return None |
| 1390 | 1390 |
| 1391 def is_null_expression(idl_type): | 1391 def is_null_expression(idl_type): |
| 1392 if idl_type.use_output_parameter_for_result: | 1392 if idl_type.use_output_parameter_for_result: |
| 1393 return 'result.isNull()' | 1393 return 'result.isNull()' |
| 1394 if idl_type.is_string_type: | 1394 if idl_type.is_string_type: |
| 1395 return 'result.isNull()' | 1395 return 'result.IsNull()' |
| 1396 if idl_type.is_interface_type: | 1396 if idl_type.is_interface_type: |
| 1397 return '!result' | 1397 return '!result' |
| 1398 if idl_type.base_type in ('any', 'object'): | 1398 if idl_type.base_type in ('any', 'object'): |
| 1399 return 'result.isEmpty()' | 1399 return 'result.IsEmpty()' |
| 1400 return '' | 1400 return '' |
| 1401 | 1401 |
| 1402 extended_attributes = getter.extended_attributes | 1402 extended_attributes = getter.extended_attributes |
| 1403 idl_type = getter.idl_type | 1403 idl_type = getter.idl_type |
| 1404 idl_type.add_includes_for_type(extended_attributes) | 1404 idl_type.add_includes_for_type(extended_attributes) |
| 1405 is_call_with_script_state = v8_utilities.has_extended_attribute_value(getter
, 'CallWith', 'ScriptState') | 1405 is_call_with_script_state = v8_utilities.has_extended_attribute_value(getter
, 'CallWith', 'ScriptState') |
| 1406 is_raises_exception = 'RaisesException' in extended_attributes | 1406 is_raises_exception = 'RaisesException' in extended_attributes |
| 1407 use_output_parameter_for_result = idl_type.use_output_parameter_for_result | 1407 use_output_parameter_for_result = idl_type.use_output_parameter_for_result |
| 1408 | 1408 |
| 1409 # FIXME: make more generic, so can use v8_methods.cpp_value | 1409 # FIXME: make more generic, so can use v8_methods.cpp_value |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 extended_attributes = deleter.extended_attributes | 1479 extended_attributes = deleter.extended_attributes |
| 1480 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') | 1480 is_call_with_script_state = v8_utilities.has_extended_attribute_value(delete
r, 'CallWith', 'ScriptState') |
| 1481 is_ce_reactions = 'CEReactions' in extended_attributes | 1481 is_ce_reactions = 'CEReactions' in extended_attributes |
| 1482 return { | 1482 return { |
| 1483 'is_call_with_script_state': is_call_with_script_state, | 1483 'is_call_with_script_state': is_call_with_script_state, |
| 1484 'is_ce_reactions': is_ce_reactions, | 1484 'is_ce_reactions': is_ce_reactions, |
| 1485 'is_custom': 'Custom' in extended_attributes, | 1485 'is_custom': 'Custom' in extended_attributes, |
| 1486 'is_raises_exception': 'RaisesException' in extended_attributes, | 1486 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 1487 'name': cpp_name(deleter), | 1487 'name': cpp_name(deleter), |
| 1488 } | 1488 } |
| OLD | NEW |