Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: Source/bindings/scripts/v8_dictionary.py

Issue 420763002: IDL: DOM impl class code generation for IDL dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 rvalue_cpp_type():
108 cpp_rvalue_type = idl_type.cpp_type_args(used_as_rvalue_type=True)
109 if (idl_type.native_array_element_type or idl_type.is_string_type):
110 return 'const %s&' % cpp_rvalue_type
haraken 2014/07/29 11:09:19 I'm not quite sure why we need this special-casing
bashi 2014/07/29 11:51:21 Sorry, this should be in cpp_type(); This is a kin
bashi 2014/07/29 23:59:49 Done. As a side effect, setter functions in impl c
haraken 2014/07/30 00:00:56 This would be fine.
111 return cpp_rvalue_type
112
113 def getter_expression():
114 if idl_type.impl_should_use_nullable_container:
115 return 'm_%s.get()' % member.name
116 return 'm_%s' % member.name
117
118 def has_method_expression():
119 if (idl_type.impl_should_use_nullable_container or
120 idl_type.is_string_type):
121 return '!m_%s.isNull()' % member.name
122 else:
123 return 'm_%s' % member.name
124
125 def member_cpp_type():
126 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True)
127 if idl_type.impl_should_use_nullable_container:
128 return v8_types.cpp_template_type('Nullable', member_cpp_type)
129 return member_cpp_type
130
131 header_includes.update(idl_type.impl_includes_for_type(interfaces_info))
132 return {
133 'getter_expression': getter_expression(),
134 'has_method_expression': has_method_expression(),
135 'has_method_name': has_method_name_for_dictionary_member(member),
136 'is_traceable': (idl_type.is_garbage_collected or
137 idl_type.is_will_be_garbage_collected),
138 'member_cpp_type': member_cpp_type(),
139 'name': member.name,
140 'rvalue_cpp_type': rvalue_cpp_type(),
141 'setter_name': setter_name_for_dictionary_member(member),
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698