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 idl_types import IdlType | 10 from idl_types import IdlType |
11 from v8_globals import includes | 11 from v8_globals import includes |
12 import v8_types | 12 import v8_types |
13 import v8_utilities | 13 import v8_utilities |
| 14 from v8_utilities import has_extended_attribute_value |
14 | 15 |
15 | 16 |
16 DICTIONARY_H_INCLUDES = frozenset([ | 17 DICTIONARY_H_INCLUDES = frozenset([ |
17 'bindings/core/v8/ToV8.h', | 18 'bindings/core/v8/ToV8.h', |
18 'bindings/core/v8/V8Binding.h', | 19 'bindings/core/v8/V8Binding.h', |
19 'platform/heap/Handle.h', | 20 'platform/heap/Handle.h', |
20 ]) | 21 ]) |
21 | 22 |
22 DICTIONARY_CPP_INCLUDES = frozenset([ | 23 DICTIONARY_CPP_INCLUDES = frozenset([ |
23 'bindings/core/v8/ExceptionState.h', | 24 'bindings/core/v8/ExceptionState.h', |
(...skipping 25 matching lines...) Expand all Loading... |
49 | 50 |
50 # Context for V8 bindings | 51 # Context for V8 bindings |
51 | 52 |
52 def dictionary_context(dictionary, interfaces_info): | 53 def dictionary_context(dictionary, interfaces_info): |
53 includes.clear() | 54 includes.clear() |
54 includes.update(DICTIONARY_CPP_INCLUDES) | 55 includes.update(DICTIONARY_CPP_INCLUDES) |
55 cpp_class = v8_utilities.cpp_name(dictionary) | 56 cpp_class = v8_utilities.cpp_name(dictionary) |
56 context = { | 57 context = { |
57 'cpp_class': cpp_class, | 58 'cpp_class': cpp_class, |
58 'header_includes': set(DICTIONARY_H_INCLUDES), | 59 'header_includes': set(DICTIONARY_H_INCLUDES), |
59 'members': [member_context(member) | 60 'members': [member_context(dictionary, member) |
60 for member in sorted(dictionary.members, | 61 for member in sorted(dictionary.members, |
61 key=operator.attrgetter('name'))], | 62 key=operator.attrgetter('name'))], |
62 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in dictionary.extended_attributes, | 63 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in dictionary.extended_attributes, |
63 'v8_class': v8_types.v8_type(cpp_class), | 64 'v8_class': v8_types.v8_type(cpp_class), |
64 'v8_original_class': v8_types.v8_type(dictionary.name), | 65 'v8_original_class': v8_types.v8_type(dictionary.name), |
65 } | 66 } |
66 if dictionary.parent: | 67 if dictionary.parent: |
67 IdlType(dictionary.parent).add_includes_for_type() | 68 IdlType(dictionary.parent).add_includes_for_type() |
68 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( | 69 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( |
69 dictionary.parent, interfaces_info) | 70 dictionary.parent, interfaces_info) |
70 context.update({ | 71 context.update({ |
71 'parent_cpp_class': parent_cpp_class, | 72 'parent_cpp_class': parent_cpp_class, |
72 'parent_v8_class': v8_types.v8_type(parent_cpp_class), | 73 'parent_v8_class': v8_types.v8_type(parent_cpp_class), |
73 }) | 74 }) |
74 return context | 75 return context |
75 | 76 |
76 | 77 |
77 def member_context(member): | 78 def member_context(dictionary, member): |
78 idl_type = member.idl_type | 79 idl_type = member.idl_type |
79 idl_type.add_includes_for_type() | 80 idl_type.add_includes_for_type() |
80 unwrapped_idl_type = unwrap_nullable_if_needed(idl_type) | 81 unwrapped_idl_type = unwrap_nullable_if_needed(idl_type) |
81 | 82 |
| 83 restricted_float = ( |
| 84 has_extended_attribute_value(dictionary, 'TypeChecking', 'Unrestricted')
or |
| 85 has_extended_attribute_value(member, 'TypeChecking', 'Unrestricted')) |
| 86 |
82 def default_values(): | 87 def default_values(): |
83 if not member.default_value: | 88 if not member.default_value: |
84 return None, None | 89 return None, None |
85 if member.default_value.is_null: | 90 if member.default_value.is_null: |
86 return None, 'v8::Null(isolate)' | 91 return None, 'v8::Null(isolate)' |
87 cpp_default_value = str(member.default_value) | 92 cpp_default_value = str(member.default_value) |
88 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( | 93 v8_default_value = unwrapped_idl_type.cpp_value_to_v8_value( |
89 cpp_value=cpp_default_value, isolate='isolate', | 94 cpp_value=cpp_default_value, isolate='isolate', |
90 creation_context='creationContext') | 95 creation_context='creationContext') |
91 return cpp_default_value, v8_default_value | 96 return cpp_default_value, v8_default_value |
(...skipping 16 matching lines...) Expand all Loading... |
108 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, | 113 'is_interface_type': idl_type.is_interface_type and not idl_type.is_dict
ionary, |
109 'is_nullable': idl_type.is_nullable, | 114 'is_nullable': idl_type.is_nullable, |
110 'is_object': unwrapped_idl_type.name == 'Object', | 115 'is_object': unwrapped_idl_type.name == 'Object', |
111 'name': member.name, | 116 'name': member.name, |
112 'setter_name': setter_name_for_dictionary_member(member), | 117 'setter_name': setter_name_for_dictionary_member(member), |
113 'null_setter_name': null_setter_name_for_dictionary_member(member), | 118 'null_setter_name': null_setter_name_for_dictionary_member(member), |
114 'use_output_parameter_for_result': unwrapped_idl_type.use_output_paramet
er_for_result, | 119 'use_output_parameter_for_result': unwrapped_idl_type.use_output_paramet
er_for_result, |
115 'v8_default_value': v8_default_value, | 120 'v8_default_value': v8_default_value, |
116 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( | 121 'v8_value_to_local_cpp_value': unwrapped_idl_type.v8_value_to_local_cpp_
value( |
117 member.extended_attributes, member.name + 'Value', | 122 member.extended_attributes, member.name + 'Value', |
118 member.name, isolate='isolate'), | 123 member.name, isolate='isolate', restricted_float=restricted_float), |
119 } | 124 } |
120 | 125 |
121 | 126 |
122 # Context for implementation classes | 127 # Context for implementation classes |
123 | 128 |
124 def dictionary_impl_context(dictionary, interfaces_info): | 129 def dictionary_impl_context(dictionary, interfaces_info): |
125 def remove_duplicate_members(members): | 130 def remove_duplicate_members(members): |
126 # When [ImplementedAs] is used, cpp_name can conflict. For example, | 131 # When [ImplementedAs] is used, cpp_name can conflict. For example, |
127 # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long old
Foo; }; | 132 # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long old
Foo; }; |
128 # This function removes such duplications, checking they have the same t
ype. | 133 # This function removes such duplications, checking they have the same t
ype. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 'getter_expression': getter_expression(), | 195 'getter_expression': getter_expression(), |
191 'has_method_expression': has_method_expression(), | 196 'has_method_expression': has_method_expression(), |
192 'has_method_name': has_method_name_for_dictionary_member(member), | 197 'has_method_name': has_method_name_for_dictionary_member(member), |
193 'is_object': is_object, | 198 'is_object': is_object, |
194 'is_traceable': idl_type.is_traceable, | 199 'is_traceable': idl_type.is_traceable, |
195 'member_cpp_type': member_cpp_type(), | 200 'member_cpp_type': member_cpp_type(), |
196 'null_setter_name': null_setter_name_for_dictionary_member(member), | 201 'null_setter_name': null_setter_name_for_dictionary_member(member), |
197 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 202 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
198 'setter_name': setter_name_for_dictionary_member(member), | 203 'setter_name': setter_name_for_dictionary_member(member), |
199 } | 204 } |
OLD | NEW |