Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Generate template contexts of dictionaries for both v8 bindings and | |
| 6 implementation classes that are used by blink's core/modules. | |
| 7 """ | |
| 8 | |
| 9 from v8_globals import includes | |
| 10 import v8_types | |
| 11 import v8_utilities | |
| 12 | |
| 13 | |
| 14 DICTIONARY_H_INCLUDES_V8 = frozenset([ | |
| 15 'bindings/core/v8/V8Binding.h', | |
| 16 'platform/heap/Handle.h', | |
| 17 ]) | |
| 18 | |
| 19 DICTIONARY_CPP_INCLUDES_V8 = frozenset([ | |
| 20 # FIXME: Remove this | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Bug number?
http://crbug.com/321462
bashi
2014/07/22 02:33:57
Done.
| |
| 21 'bindings/core/v8/Dictionary.h', | |
| 22 ]) | |
| 23 | |
| 24 | |
| 25 def setter_name_for_dictionary_member(member): | |
| 26 return 'set%s' % v8_utilities.capitalize(member.name) | |
| 27 | |
| 28 | |
| 29 def has_name_for_dictionary_member(member): | |
| 30 return 'has%s' % v8_utilities.capitalize(member.name) | |
| 31 | |
| 32 | |
| 33 # Context for v8 bindings | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Caps: V8
bashi
2014/07/22 02:33:57
Done.
| |
| 34 | |
| 35 | |
| 36 def dictionary_context_v8(dictionary): | |
| 37 includes.clear() | |
| 38 includes.update(DICTIONARY_CPP_INCLUDES_V8) | |
| 39 header_includes = set(DICTIONARY_H_INCLUDES_V8) | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
inline?
bashi
2014/07/22 02:33:57
Done.
| |
| 40 sorted_members = sorted(dictionary.members, | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
inline?
bashi
2014/07/22 02:33:57
Done.
| |
| 41 key=lambda member: member.name) | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
An alternative is:
key=operator.attrgetter('name')
bashi
2014/07/22 02:33:57
Done.
| |
| 42 return { | |
| 43 'header_includes': header_includes, | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Alpha
bashi
2014/07/22 02:33:58
Done.
| |
| 44 'cpp_class': v8_utilities.cpp_name(dictionary), | |
| 45 'members': [member_context_v8(member) for member in sorted_members], | |
| 46 'v8_class': v8_utilities.v8_class_name(dictionary), | |
| 47 } | |
| 48 | |
| 49 | |
| 50 def member_context_v8(member): | |
| 51 member.idl_type.add_includes_for_type() | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Move below idl_type = ...
bashi
2014/07/22 02:33:58
Done.
| |
| 52 idl_type = member.idl_type | |
| 53 base_idl_type = idl_type.base_type | |
| 54 cpp_value = 'impl->%s()' % member.name | |
| 55 cpp_value_to_v8_value = idl_type.cpp_value_to_v8_value( | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Inline?
bashi
2014/07/22 02:33:57
Done.
| |
| 56 cpp_value=cpp_value, isolate='isolate', | |
| 57 creation_context='creationContext', | |
| 58 extended_attributes=member.extended_attributes) | |
| 59 default_value = None | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
How about just
default_value = str(member.default_
bashi
2014/07/22 02:33:57
str(None) results in 'None' and |default_value| is
| |
| 60 v8_default_value = None | |
| 61 if member.default_value: | |
| 62 default_value = str(member.default_value) | |
| 63 v8_default_value = idl_type.cpp_value_to_v8_value( | |
| 64 cpp_value=default_value, isolate='isolate', | |
| 65 creation_context='creationContext', | |
| 66 extended_attributes=member.extended_attributes) | |
| 67 | |
| 68 return { | |
| 69 'cpp_type': idl_type.cpp_type, | |
| 70 'cpp_value_to_v8_value': cpp_value_to_v8_value, | |
| 71 'default_value': default_value, | |
| 72 'has_name': has_name_for_dictionary_member(member), | |
| 73 'name': member.name, | |
| 74 'setter_name': setter_name_for_dictionary_member(member), | |
| 75 'v8_default_value': v8_default_value, | |
| 76 'v8_type': v8_types.v8_type(base_idl_type), | |
| 77 } | |
| 78 | |
| 79 | |
| 80 # Context for implementation classes | |
| 81 | |
| 82 | |
| 83 def dictionary_context_impl(dictionary, interfaces_info): | |
| 84 includes.clear() | |
| 85 header_includes = set(['platform/heap/Handle.h']) | |
| 86 members = [member_context_impl(member, interfaces_info, | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
Inline this?
bashi
2014/07/22 02:33:57
Done.
| |
| 87 header_includes) | |
| 88 for member in dictionary.members] | |
| 89 return { | |
| 90 'header_includes': header_includes, | |
| 91 'cpp_name': v8_utilities.cpp_name(dictionary), | |
| 92 'members': members, | |
| 93 } | |
| 94 | |
| 95 | |
| 96 # FIXME: We may want to put this in v8_types.py | |
| 97 def impl_includes_for_type(idl_type, interfaces_info): | |
| 98 idl_type = idl_type.preprocessed_type | |
| 99 | |
| 100 native_array_element_type = idl_type.native_array_element_type | |
| 101 if native_array_element_type: | |
| 102 includes_for_type = impl_includes_for_type( | |
| 103 native_array_element_type, interfaces_info) | |
| 104 includes_for_type.update(set(['wtf/Vector.h'])) | |
| 105 return includes_for_type | |
| 106 | |
| 107 if idl_type.is_string_type: | |
| 108 return set(['wtf/text/WTFString.h']) | |
| 109 if idl_type.name in interfaces_info: | |
| 110 interface_info = interfaces_info[idl_type.name] | |
| 111 return set([interface_info['include_path']]) | |
| 112 return set() | |
| 113 | |
| 114 | |
| 115 def member_context_impl(member, interfaces_info, header_includes): | |
| 116 idl_type = member.idl_type | |
| 117 includes_for_member = impl_includes_for_type(idl_type, interfaces_info) | |
| 118 header_includes.update(includes_for_member) | |
| 119 argument_cpp_type = idl_type.cpp_type_args(used_as_argument=True) | |
|
Nils Barth (inactive)
2014/07/18 21:52:34
You can inline these into the dictionary display;
bashi
2014/07/22 02:33:57
Done.
| |
| 120 getter_cpp_type = idl_type.cpp_type_args(used_as_return_type=True) | |
| 121 member_cpp_type = idl_type.cpp_type_args(used_as_member=True) | |
| 122 is_traceable = (idl_type.is_garbage_collected or | |
| 123 idl_type.is_will_be_garbage_collected) | |
| 124 return { | |
| 125 'argument_cpp_type': argument_cpp_type, | |
| 126 'cpp_type': idl_type.cpp_type, | |
| 127 'getter_cpp_type': getter_cpp_type, | |
| 128 'has_name': has_name_for_dictionary_member(member), | |
| 129 'is_traceable': is_traceable, | |
| 130 'member_cpp_type': member_cpp_type, | |
| 131 'name': member.name, | |
| 132 'setter_name': setter_name_for_dictionary_member(member), | |
| 133 } | |
| OLD | NEW |