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 copy | 9 import copy |
10 import operator | 10 import operator |
(...skipping 10 matching lines...) Expand all Loading... |
21 DICTIONARY_CPP_INCLUDES = frozenset([ | 21 DICTIONARY_CPP_INCLUDES = frozenset([ |
22 # FIXME: Remove this, http://crbug.com/321462 | 22 # FIXME: Remove this, http://crbug.com/321462 |
23 'bindings/core/v8/Dictionary.h', | 23 'bindings/core/v8/Dictionary.h', |
24 ]) | 24 ]) |
25 | 25 |
26 | 26 |
27 def setter_name_for_dictionary_member(member): | 27 def setter_name_for_dictionary_member(member): |
28 return 'set%s' % v8_utilities.capitalize(member.name) | 28 return 'set%s' % v8_utilities.capitalize(member.name) |
29 | 29 |
30 | 30 |
31 def has_name_for_dictionary_member(member): | 31 def has_method_name_for_dictionary_member(member): |
32 return 'has%s' % v8_utilities.capitalize(member.name) | 32 return 'has%s' % v8_utilities.capitalize(member.name) |
33 | 33 |
34 | 34 |
35 # Context for V8 bindings | 35 # Context for V8 bindings |
36 | 36 |
37 def dictionary_context(dictionary): | 37 def dictionary_context(dictionary): |
38 includes.clear() | 38 includes.clear() |
39 includes.update(DICTIONARY_CPP_INCLUDES) | 39 includes.update(DICTIONARY_CPP_INCLUDES) |
40 return { | 40 return { |
41 'cpp_class': v8_utilities.cpp_name(dictionary), | 41 'cpp_class': v8_utilities.cpp_name(dictionary), |
(...skipping 30 matching lines...) Expand all Loading... |
72 | 72 |
73 cpp_default_value, v8_default_value = default_values() | 73 cpp_default_value, v8_default_value = default_values() |
74 | 74 |
75 return { | 75 return { |
76 'cpp_default_value': cpp_default_value, | 76 'cpp_default_value': cpp_default_value, |
77 'cpp_type': idl_type.cpp_type, | 77 'cpp_type': idl_type.cpp_type, |
78 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 78 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
79 cpp_value='impl->%s()' % member.name, isolate='isolate', | 79 cpp_value='impl->%s()' % member.name, isolate='isolate', |
80 creation_context='creationContext', | 80 creation_context='creationContext', |
81 extended_attributes=member.extended_attributes), | 81 extended_attributes=member.extended_attributes), |
82 'has_name': has_name_for_dictionary_member(member), | 82 'has_method_name': has_method_name_for_dictionary_member(member), |
83 'name': member.name, | 83 'name': member.name, |
84 'setter_name': setter_name_for_dictionary_member(member), | 84 'setter_name': setter_name_for_dictionary_member(member), |
85 'v8_default_value': v8_default_value, | 85 'v8_default_value': v8_default_value, |
86 'v8_type': v8_types.v8_type(idl_type.base_type), | 86 'v8_type': v8_types.v8_type(idl_type.base_type), |
87 } | 87 } |
88 | 88 |
89 # FIXME: Implement context for impl class. | 89 |
| 90 # Context for implementation classes |
| 91 |
| 92 def dictionary_impl_context(dictionary, interfaces_info): |
| 93 includes.clear() |
| 94 header_includes = set(['platform/heap/Handle.h']) |
| 95 return { |
| 96 'header_includes': header_includes, |
| 97 'cpp_class': v8_utilities.cpp_name(dictionary), |
| 98 'members': [member_impl_context(member, interfaces_info, |
| 99 header_includes) |
| 100 for member in dictionary.members], |
| 101 } |
| 102 |
| 103 |
| 104 def member_impl_context(member, interfaces_info, header_includes): |
| 105 idl_type = member.idl_type |
| 106 |
| 107 def getter_expression(): |
| 108 if idl_type.impl_should_use_nullable_container: |
| 109 return 'm_%s.get()' % member.name |
| 110 return 'm_%s' % member.name |
| 111 |
| 112 def has_method_expression(): |
| 113 if (idl_type.impl_should_use_nullable_container or |
| 114 idl_type.is_string_type): |
| 115 return '!m_%s.isNull()' % member.name |
| 116 else: |
| 117 return 'm_%s' % member.name |
| 118 |
| 119 def member_cpp_type(): |
| 120 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
| 121 if idl_type.impl_should_use_nullable_container: |
| 122 return v8_types.cpp_template_type('Nullable', member_cpp_type) |
| 123 return member_cpp_type |
| 124 |
| 125 header_includes.update(idl_type.impl_includes_for_type(interfaces_info)) |
| 126 return { |
| 127 'getter_expression': getter_expression(), |
| 128 'has_method_expression': has_method_expression(), |
| 129 'has_method_name': has_method_name_for_dictionary_member(member), |
| 130 'is_traceable': (idl_type.is_garbage_collected or |
| 131 idl_type.is_will_be_garbage_collected), |
| 132 'member_cpp_type': member_cpp_type(), |
| 133 'name': member.name, |
| 134 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 135 'setter_name': setter_name_for_dictionary_member(member), |
| 136 } |
OLD | NEW |