| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generate template contexts of dictionaries for both v8 bindings and | 5 """Generate template contexts of dictionaries for both v8 bindings and |
| 6 implementation classes that are used by blink's core/modules. | 6 implementation classes that are used by blink's core/modules. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import operator | 9 import operator |
| 10 from v8_globals import includes | 10 from v8_globals import includes |
| 11 import v8_types | 11 import v8_types |
| 12 import v8_utilities | 12 import v8_utilities |
| 13 | 13 |
| 14 | 14 |
| 15 DICTIONARY_H_INCLUDES = frozenset([ | 15 DICTIONARY_H_INCLUDES = frozenset([ |
| 16 'bindings/core/v8/V8Binding.h', | 16 'bindings/core/v8/V8Binding.h', |
| 17 'platform/heap/Handle.h', | 17 'platform/heap/Handle.h', |
| 18 ]) | 18 ]) |
| 19 | 19 |
| 20 DICTIONARY_CPP_INCLUDES = frozenset([ | 20 DICTIONARY_CPP_INCLUDES = frozenset([ |
| 21 'bindings/core/v8/ExceptionState.h', |
| 21 # FIXME: Remove this, http://crbug.com/321462 | 22 # FIXME: Remove this, http://crbug.com/321462 |
| 22 'bindings/core/v8/Dictionary.h', | 23 'bindings/core/v8/Dictionary.h', |
| 23 ]) | 24 ]) |
| 24 | 25 |
| 25 | 26 |
| 26 def setter_name_for_dictionary_member(member): | 27 def setter_name_for_dictionary_member(member): |
| 27 return 'set%s' % v8_utilities.capitalize(member.name) | 28 return 'set%s' % v8_utilities.capitalize(member.name) |
| 28 | 29 |
| 29 | 30 |
| 30 def has_method_name_for_dictionary_member(member): | 31 def has_method_name_for_dictionary_member(member): |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 69 |
| 69 cpp_default_value, v8_default_value = default_values() | 70 cpp_default_value, v8_default_value = default_values() |
| 70 | 71 |
| 71 return { | 72 return { |
| 72 'cpp_default_value': cpp_default_value, | 73 'cpp_default_value': cpp_default_value, |
| 73 'cpp_type': idl_type.cpp_type, | 74 'cpp_type': idl_type.cpp_type, |
| 74 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 75 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 75 cpp_value='impl->%s()' % member.name, isolate='isolate', | 76 cpp_value='impl->%s()' % member.name, isolate='isolate', |
| 76 creation_context='creationContext', | 77 creation_context='creationContext', |
| 77 extended_attributes=member.extended_attributes), | 78 extended_attributes=member.extended_attributes), |
| 79 'enum_validation_expression': idl_type.enum_validation_expression, |
| 78 'has_method_name': has_method_name_for_dictionary_member(member), | 80 'has_method_name': has_method_name_for_dictionary_member(member), |
| 79 'name': member.name, | 81 'name': member.name, |
| 80 'setter_name': setter_name_for_dictionary_member(member), | 82 'setter_name': setter_name_for_dictionary_member(member), |
| 81 'v8_default_value': v8_default_value, | 83 'v8_default_value': v8_default_value, |
| 82 } | 84 } |
| 83 | 85 |
| 84 | 86 |
| 85 # Context for implementation classes | 87 # Context for implementation classes |
| 86 | 88 |
| 87 def dictionary_impl_context(dictionary, interfaces_info): | 89 def dictionary_impl_context(dictionary, interfaces_info): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 | 100 |
| 99 def member_impl_context(member, interfaces_info, header_includes): | 101 def member_impl_context(member, interfaces_info, header_includes): |
| 100 idl_type = member.idl_type | 102 idl_type = member.idl_type |
| 101 | 103 |
| 102 def getter_expression(): | 104 def getter_expression(): |
| 103 if idl_type.impl_should_use_nullable_container: | 105 if idl_type.impl_should_use_nullable_container: |
| 104 return 'm_%s.get()' % member.name | 106 return 'm_%s.get()' % member.name |
| 105 return 'm_%s' % member.name | 107 return 'm_%s' % member.name |
| 106 | 108 |
| 107 def has_method_expression(): | 109 def has_method_expression(): |
| 108 if (idl_type.impl_should_use_nullable_container or | 110 if idl_type.impl_should_use_nullable_container or idl_type.is_enum or id
l_type.is_string_type: |
| 109 idl_type.is_string_type): | |
| 110 return '!m_%s.isNull()' % member.name | 111 return '!m_%s.isNull()' % member.name |
| 111 else: | 112 else: |
| 112 return 'm_%s' % member.name | 113 return 'm_%s' % member.name |
| 113 | 114 |
| 114 def member_cpp_type(): | 115 def member_cpp_type(): |
| 115 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | 116 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
| 116 if idl_type.impl_should_use_nullable_container: | 117 if idl_type.impl_should_use_nullable_container: |
| 117 return v8_types.cpp_template_type('Nullable', member_cpp_type) | 118 return v8_types.cpp_template_type('Nullable', member_cpp_type) |
| 118 return member_cpp_type | 119 return member_cpp_type |
| 119 | 120 |
| 120 cpp_default_value = None | 121 cpp_default_value = None |
| 121 if member.default_value and not member.default_value.is_null: | 122 if member.default_value and not member.default_value.is_null: |
| 122 cpp_default_value = str(member.default_value) | 123 cpp_default_value = str(member.default_value) |
| 123 | 124 |
| 124 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) | 125 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 125 return { | 126 return { |
| 126 'cpp_default_value': cpp_default_value, | 127 'cpp_default_value': cpp_default_value, |
| 127 'getter_expression': getter_expression(), | 128 'getter_expression': getter_expression(), |
| 128 'has_method_expression': has_method_expression(), | 129 'has_method_expression': has_method_expression(), |
| 129 'has_method_name': has_method_name_for_dictionary_member(member), | 130 'has_method_name': has_method_name_for_dictionary_member(member), |
| 130 'is_traceable': (idl_type.is_garbage_collected or | 131 'is_traceable': (idl_type.is_garbage_collected or |
| 131 idl_type.is_will_be_garbage_collected), | 132 idl_type.is_will_be_garbage_collected), |
| 132 'member_cpp_type': member_cpp_type(), | 133 'member_cpp_type': member_cpp_type(), |
| 133 'name': member.name, | 134 'name': member.name, |
| 134 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 135 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 135 'setter_name': setter_name_for_dictionary_member(member), | 136 'setter_name': setter_name_for_dictionary_member(member), |
| 136 } | 137 } |
| OLD | NEW |