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

Side by Side Diff: sky/engine/bindings2/scripts/v8_methods.py

Issue 914413004: Add a new bindings2/scripts directory for Dart bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove idlrenderer.py it's not used Created 5 years, 10 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
« no previous file with comments | « sky/engine/bindings2/scripts/v8_interface.py ('k') | sky/engine/bindings2/scripts/v8_types.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 27 matching lines...) Expand all
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface 38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface
39 from v8_globals import includes 39 from v8_globals import includes
40 import v8_types 40 import v8_types
41 import v8_utilities 41 import v8_utilities
42 from v8_utilities import has_extended_attribute_value 42 from v8_utilities import has_extended_attribute_value
43 43
44 44
45 # Methods with any of these require custom method registration code in the 45 # Methods with any of these require custom method registration code in the
46 # interface's configure*Template() function. 46 # interface's configure*Template() function.
47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ 47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
48 'DoNotCheckSecurity',
49 'DoNotCheckSignature',
50 'NotEnumerable', 48 'NotEnumerable',
51 'Unforgeable',
52 ]) 49 ])
53 50
54 51
55 def argument_needs_try_catch(method, argument): 52 def argument_needs_try_catch(method, argument):
56 return_promise = method.idl_type and method.idl_type.name == 'Promise' 53 return_promise = method.idl_type and method.idl_type.name == 'Promise'
57 idl_type = argument.idl_type 54 idl_type = argument.idl_type
58 base_type = idl_type.base_type 55 base_type = idl_type.base_type
59 56
60 return not( 57 return not(
61 # These cases are handled by separate code paths in the 58 # These cases are handled by separate code paths in the
62 # generate_argument() macro in engine/bindings/templates/methods.cpp. 59 # generate_argument() macro in engine/bindings/templates/methods.cpp.
63 idl_type.is_callback_interface or 60 idl_type.is_callback_interface or
64 base_type == 'SerializedScriptValue' or 61 base_type == 'SerializedScriptValue' or
65 (argument.is_variadic and idl_type.is_wrapper_type) or 62 (argument.is_variadic and idl_type.is_wrapper_type) or
66 # String and enumeration arguments converted using one of the 63 # String and enumeration arguments converted using one of the
67 # TOSTRING_* macros except for _PROMISE variants in 64 # TOSTRING_* macros except for _PROMISE variants in
68 # engine/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch. 65 # engine/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch.
69 ((base_type == 'DOMString' or idl_type.is_enum) and 66 ((base_type == 'DOMString' or idl_type.is_enum) and
70 not argument.is_variadic and 67 not argument.is_variadic and
71 not return_promise)) 68 not return_promise))
72 69
73 70
74 def use_local_result(method): 71 def use_local_result(method):
75 extended_attributes = method.extended_attributes 72 extended_attributes = method.extended_attributes
76 idl_type = method.idl_type 73 idl_type = method.idl_type
77 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 74 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
78 'ImplementedInPrivateScript' in extended_attributes or
79 'RaisesException' in extended_attributes or 75 'RaisesException' in extended_attributes or
80 idl_type.is_union_type or 76 idl_type.is_union_type or
81 idl_type.is_explicit_nullable) 77 idl_type.is_explicit_nullable)
82 78
83 79
84 def method_context(interface, method): 80 def method_context(interface, method):
85 arguments = method.arguments 81 arguments = method.arguments
86 extended_attributes = method.extended_attributes 82 extended_attributes = method.extended_attributes
87 idl_type = method.idl_type 83 idl_type = method.idl_type
88 is_static = method.is_static 84 is_static = method.is_static
89 name = method.name 85 name = method.name
90 86
91 idl_type.add_includes_for_type() 87 idl_type.add_includes_for_type()
92 this_cpp_value = cpp_value(interface, method, len(arguments)) 88 this_cpp_value = cpp_value(interface, method, len(arguments))
93 89
94 def function_template(): 90 def function_template():
95 if is_static: 91 if is_static:
96 return 'functionTemplate' 92 return 'functionTemplate'
97 if 'Unforgeable' in extended_attributes:
98 return 'instanceTemplate'
99 return 'prototypeTemplate' 93 return 'prototypeTemplate'
100 94
101 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes
102 if is_implemented_in_private_script:
103 includes.add('bindings/core/v8/PrivateScriptRunner.h')
104 includes.add('core/frame/LocalFrame.h')
105 includes.add('platform/ScriptForbiddenScope.h')
106
107 # [OnlyExposedToPrivateScript]
108 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended _attributes
109
110 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments') 95 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments')
111 if is_call_with_script_arguments: 96 if is_call_with_script_arguments:
112 includes.update(['bindings/core/v8/ScriptCallStackFactory.h', 97 includes.update(['bindings/core/v8/ScriptCallStackFactory.h',
113 'core/inspector/ScriptArguments.h']) 98 'core/inspector/ScriptArguments.h'])
114 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') 99 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
115 if is_call_with_script_state: 100 if is_call_with_script_state:
116 includes.add('bindings/core/v8/ScriptState.h') 101 includes.add('bindings/core/v8/ScriptState.h')
117 is_check_security_for_node = 'CheckSecurity' in extended_attributes
118 if is_check_security_for_node:
119 includes.add('bindings/core/v8/BindingSecurity.h')
120 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 102 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
121 if is_custom_element_callbacks: 103 if is_custom_element_callbacks:
122 includes.add('core/dom/custom/CustomElementProcessingStack.h') 104 includes.add('core/dom/custom/CustomElementProcessingStack.h')
123 105
124 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes
125
126 is_check_security_for_frame = (
127 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and
128 not is_do_not_check_security)
129
130 is_check_security_for_window = (
131 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and
132 not is_do_not_check_security)
133
134 is_raises_exception = 'RaisesException' in extended_attributes 106 is_raises_exception = 'RaisesException' in extended_attributes
135 107
136 arguments_need_try_catch = ( 108 arguments_need_try_catch = (
137 any(argument_needs_try_catch(method, argument) 109 any(argument_needs_try_catch(method, argument)
138 for argument in arguments)) 110 for argument in arguments))
139 111
140 return { 112 return {
141 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
142 'arguments': [argument_context(interface, method, argument, index) 113 'arguments': [argument_context(interface, method, argument, index)
143 for index, argument in enumerate(arguments)], 114 for index, argument in enumerate(arguments)],
144 'argument_declarations_for_private_script':
145 argument_declarations_for_private_script(interface, method),
146 'arguments_need_try_catch': arguments_need_try_catch, 115 'arguments_need_try_catch': arguments_need_try_catch,
147 'conditional_string': v8_utilities.conditional_string(method),
148 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 116 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
149 if idl_type.is_explicit_nullable else idl_type.cpp_type), 117 if idl_type.is_explicit_nullable else idl_type.cpp_type),
150 'cpp_value': this_cpp_value, 118 'cpp_value': this_cpp_value,
151 'cpp_type_initializer': idl_type.cpp_type_initializer, 119 'cpp_type_initializer': idl_type.cpp_type_initializer,
152 'custom_registration_extended_attributes': 120 'custom_registration_extended_attributes':
153 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 121 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
154 extended_attributes.iterkeys()), 122 extended_attributes.iterkeys()),
155 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
156 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 123 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
157 'function_template': function_template(), 124 'function_template': function_template(),
158 'has_custom_registration': is_static or 125 'has_custom_registration': is_static or
159 v8_utilities.has_extended_attribute( 126 v8_utilities.has_extended_attribute(
160 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 127 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
161 'has_exception_state': 128 'has_exception_state':
162 is_raises_exception or 129 is_raises_exception or
163 is_check_security_for_frame or
164 is_check_security_for_window or
165 any(argument for argument in arguments 130 any(argument for argument in arguments
166 if argument.idl_type.name == 'SerializedScriptValue' or 131 if argument.idl_type.name == 'SerializedScriptValue' or
167 argument.idl_type.may_raise_exception_on_conversion), 132 argument.idl_type.may_raise_exception_on_conversion),
168 'idl_type': idl_type.base_type, 133 'idl_type': idl_type.base_type,
169 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 134 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
170 'is_call_with_script_arguments': is_call_with_script_arguments, 135 'is_call_with_script_arguments': is_call_with_script_arguments,
171 'is_call_with_script_state': is_call_with_script_state, 136 'is_call_with_script_state': is_call_with_script_state,
172 'is_check_security_for_frame': is_check_security_for_frame,
173 'is_check_security_for_node': is_check_security_for_node,
174 'is_check_security_for_window': is_check_security_for_window,
175 'is_custom': 'Custom' in extended_attributes, 137 'is_custom': 'Custom' in extended_attributes,
176 'is_custom_element_callbacks': is_custom_element_callbacks, 138 'is_custom_element_callbacks': is_custom_element_callbacks,
177 'is_do_not_check_security': is_do_not_check_security,
178 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
179 'is_explicit_nullable': idl_type.is_explicit_nullable, 139 'is_explicit_nullable': idl_type.is_explicit_nullable,
180 'is_implemented_in_private_script': is_implemented_in_private_script,
181 'is_partial_interface_member': 140 'is_partial_interface_member':
182 'PartialInterfaceImplementedAs' in extended_attributes, 141 'PartialInterfaceImplementedAs' in extended_attributes,
183 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
184 'is_raises_exception': is_raises_exception, 142 'is_raises_exception': is_raises_exception,
185 'is_read_only': 'Unforgeable' in extended_attributes,
186 'is_static': is_static, 143 'is_static': is_static,
187 'is_variadic': arguments and arguments[-1].is_variadic, 144 'is_variadic': arguments and arguments[-1].is_variadic,
188 'measure_as': v8_utilities.measure_as(method), # [MeasureAs]
189 'name': name, 145 'name': name,
190 'number_of_arguments': len(arguments), 146 'number_of_arguments': len(arguments),
191 'number_of_required_arguments': len([ 147 'number_of_required_arguments': len([
192 argument for argument in arguments 148 argument for argument in arguments
193 if not (argument.is_optional or argument.is_variadic)]), 149 if not (argument.is_optional or argument.is_variadic)]),
194 'number_of_required_or_variadic_arguments': len([ 150 'number_of_required_or_variadic_arguments': len([
195 argument for argument in arguments 151 argument for argument in arguments
196 if not argument.is_optional]), 152 if not argument.is_optional]),
197 'only_exposed_to_private_script': is_only_exposed_to_private_script,
198 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value(
199 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True),
200 'property_attributes': property_attributes(method),
201 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
202 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script),
203 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
204 'union_arguments': idl_type.union_arguments, 153 'union_arguments': idl_type.union_arguments,
205 'use_local_result': use_local_result(method), 154 'use_local_result': use_local_result(method),
206 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
207 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
208 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
209 } 155 }
210 156
211 157
212 def argument_context(interface, method, argument, index): 158 def argument_context(interface, method, argument, index):
213 extended_attributes = argument.extended_attributes 159 extended_attributes = argument.extended_attributes
214 idl_type = argument.idl_type 160 idl_type = argument.idl_type
215 this_cpp_value = cpp_value(interface, method, index) 161 this_cpp_value = cpp_value(interface, method, index)
216 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
217 return_promise = (method.idl_type.name == 'Promise' if method.idl_type 162 return_promise = (method.idl_type.name == 'Promise' if method.idl_type
218 else False) 163 else False)
219 164
220 if ('ImplementedInPrivateScript' in extended_attributes and
221 not idl_type.is_wrapper_type and
222 not idl_type.is_basic_type):
223 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
224
225 default_cpp_value = argument.default_cpp_value 165 default_cpp_value = argument.default_cpp_value
226 return { 166 return {
227 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, 167 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
228 raw_type=True, 168 raw_type=True,
229 used_as_variadic_argument=argument.is _variadic), 169 used_as_variadic_argument=argument.is _variadic),
230 'cpp_value': this_cpp_value, 170 'cpp_value': this_cpp_value,
231 # FIXME: check that the default value's type is compatible with the argu ment's 171 # FIXME: check that the default value's type is compatible with the argu ment's
232 'default_value': default_cpp_value, 172 'default_value': default_cpp_value,
233 'enum_validation_expression': idl_type.enum_validation_expression, 173 'enum_validation_expression': idl_type.enum_validation_expression,
234 'handle': '%sHandle' % argument.name, 174 'handle': '%sHandle' % argument.name,
235 # FIXME: remove once [Default] removed and just use argument.default_val ue 175 # FIXME: remove once [Default] removed and just use argument.default_val ue
236 'has_default': 'Default' in extended_attributes or default_cpp_value, 176 'has_default': 'Default' in extended_attributes or default_cpp_value,
237 'has_type_checking_interface': 177 'has_type_checking_interface':
238 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or 178 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
239 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and 179 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
240 idl_type.is_wrapper_type, 180 idl_type.is_wrapper_type,
241 'has_type_checking_unrestricted': 181 'has_type_checking_unrestricted':
242 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or 182 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or
243 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and 183 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and
244 idl_type.name in ('Float', 'Double'), 184 idl_type.name in ('Float', 'Double'),
245 # Dictionary is special-cased, but arrays and sequences shouldn't be
246 'idl_type': idl_type.base_type, 185 'idl_type': idl_type.base_type,
247 'idl_type_object': idl_type, 186 'idl_type_object': idl_type,
248 'index': index, 187 'index': index,
249 'is_clamp': 'Clamp' in extended_attributes,
250 'is_callback_interface': idl_type.is_callback_interface, 188 'is_callback_interface': idl_type.is_callback_interface,
251 'is_nullable': idl_type.is_nullable, 189 'is_nullable': idl_type.is_nullable,
252 'is_optional': argument.is_optional, 190 'is_optional': argument.is_optional,
253 'is_variadic_wrapper_type': is_variadic_wrapper_type,
254 'is_wrapper_type': idl_type.is_wrapper_type, 191 'is_wrapper_type': idl_type.is_wrapper_type,
255 'name': argument.name, 192 'name': argument.name,
256 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
257 argument.name, isolate='scriptState->isolate()',
258 creation_context='scriptState->context()->Global()'),
259 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
260 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
261 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, return_promise=return_promise),
262 'vector_type': 'Vector',
263 } 193 }
264 194
265 195
266 def argument_declarations_for_private_script(interface, method):
267 argument_declarations = ['LocalFrame* frame']
268 argument_declarations.append('%s* holderImpl' % interface.name)
269 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
270 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts])
271 if method.idl_type.name != 'void':
272 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu lt'))
273 return argument_declarations
274
275
276 ################################################################################ 196 ################################################################################
277 # Value handling 197 # Value handling
278 ################################################################################ 198 ################################################################################
279 199
280 def cpp_value(interface, method, number_of_arguments): 200 def cpp_value(interface, method, number_of_arguments):
281 def cpp_argument(argument): 201 def cpp_argument(argument):
282 idl_type = argument.idl_type 202 idl_type = argument.idl_type
283 if idl_type.name == 'EventListener': 203 if idl_type.name == 'EventListener':
284 return argument.name 204 return argument.name
285 if (idl_type.is_callback_interface or 205 if (idl_type.is_callback_interface or
286 idl_type.name in ['NodeFilter', 'NodeFilterOrNull']): 206 idl_type.name in ['NodeFilter', 'NodeFilterOrNull']):
287 # FIXME: remove this special case 207 # FIXME: remove this special case
288 return '%s.release()' % argument.name 208 return '%s.release()' % argument.name
289 return argument.name 209 return argument.name
290 210
291 # Truncate omitted optional arguments 211 # Truncate omitted optional arguments
292 arguments = method.arguments[:number_of_arguments] 212 arguments = method.arguments[:number_of_arguments]
293 cpp_arguments = [] 213 cpp_arguments = []
294 if 'ImplementedInPrivateScript' in method.extended_attributes:
295 cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrent Context())')
296 cpp_arguments.append('impl')
297 214
298 if method.is_constructor: 215 if method.is_constructor:
299 call_with_values = interface.extended_attributes.get('ConstructorCallWit h') 216 call_with_values = interface.extended_attributes.get('ConstructorCallWit h')
300 else: 217 else:
301 call_with_values = method.extended_attributes.get('CallWith') 218 call_with_values = method.extended_attributes.get('CallWith')
302 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) 219 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values))
303 220
304 # Members of IDL partial interface definitions are implemented in C++ as 221 # Members of IDL partial interface definitions are implemented in C++ as
305 # static member functions, which for instance members (non-static members) 222 # static member functions, which for instance members (non-static members)
306 # take *impl as their first argument 223 # take *impl as their first argument
307 if ('PartialInterfaceImplementedAs' in method.extended_attributes and 224 if ('PartialInterfaceImplementedAs' in method.extended_attributes and
308 not 'ImplementedInPrivateScript' in method.extended_attributes and
309 not method.is_static): 225 not method.is_static):
310 cpp_arguments.append('*impl') 226 cpp_arguments.append('*impl')
311 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) 227 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
312 228
313 this_union_arguments = method.idl_type and method.idl_type.union_arguments 229 this_union_arguments = method.idl_type and method.idl_type.union_arguments
314 if this_union_arguments: 230 if this_union_arguments:
315 cpp_arguments.extend([member_argument['cpp_value'] 231 cpp_arguments.extend([member_argument['cpp_value']
316 for member_argument in this_union_arguments]) 232 for member_argument in this_union_arguments])
317 233
318 if 'ImplementedInPrivateScript' in method.extended_attributes: 234 if ('RaisesException' in method.extended_attributes or
319 if method.idl_type.name != 'void':
320 cpp_arguments.append('&result')
321 elif ('RaisesException' in method.extended_attributes or
322 (method.is_constructor and 235 (method.is_constructor and
323 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): 236 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))):
324 cpp_arguments.append('exceptionState') 237 cpp_arguments.append('exceptionState')
325 238
326 if method.name == 'Constructor': 239 if method.name == 'Constructor':
327 base_name = 'create' 240 base_name = 'create'
328 elif method.name == 'NamedConstructor': 241 elif method.name == 'NamedConstructor':
329 base_name = 'createForJSConstructor' 242 base_name = 'createForJSConstructor'
330 elif 'ImplementedInPrivateScript' in method.extended_attributes:
331 base_name = '%sMethod' % method.name
332 else: 243 else:
333 base_name = v8_utilities.cpp_name(method) 244 base_name = v8_utilities.cpp_name(method)
334 245
335 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) 246 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name)
336 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) 247 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
337 248
338 249
339 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False) :
340 idl_type = method.idl_type
341 extended_attributes = method.extended_attributes
342 if not idl_type or idl_type.name == 'void':
343 # Constructors and void methods don't have a return type
344 return None
345
346 if ('ImplementedInPrivateScript' in extended_attributes and
347 not idl_type.is_wrapper_type and
348 not idl_type.is_basic_type):
349 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
350
351 release = False
352 # [CallWith=ScriptState], [RaisesException]
353 if use_local_result(method):
354 if idl_type.is_explicit_nullable:
355 # result is of type Nullable<T>
356 cpp_value = 'result.get()'
357 else:
358 cpp_value = 'result'
359 release = idl_type.release
360
361 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
362 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
363
364
365 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise): 250 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise):
366 assert argument.is_variadic 251 assert argument.is_variadic
367 idl_type = argument.idl_type 252 idl_type = argument.idl_type
368 253
369 suffix = '' 254 suffix = ''
370 255
371 macro = 'TONATIVE_VOID' 256 macro = 'TONATIVE_VOID'
372 macro_args = [ 257 macro_args = [
373 argument.name, 258 argument.name,
374 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), 259 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index),
(...skipping 15 matching lines...) Expand all
390 if argument.is_variadic: 275 if argument.is_variadic:
391 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise) 276 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise)
392 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, 277 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
393 name, index=index, declare_varia ble=False, return_promise=return_promise) 278 name, index=index, declare_varia ble=False, return_promise=return_promise)
394 279
395 280
396 ################################################################################ 281 ################################################################################
397 # Auxiliary functions 282 # Auxiliary functions
398 ################################################################################ 283 ################################################################################
399 284
400 # [NotEnumerable]
401 def property_attributes(method):
402 extended_attributes = method.extended_attributes
403 property_attributes_list = []
404 if 'NotEnumerable' in extended_attributes:
405 property_attributes_list.append('v8::DontEnum')
406 if 'Unforgeable' in extended_attributes:
407 property_attributes_list.append('v8::ReadOnly')
408 if property_attributes_list:
409 property_attributes_list.insert(0, 'v8::DontDelete')
410 return property_attributes_list
411
412
413 def union_member_argument_context(idl_type, index): 285 def union_member_argument_context(idl_type, index):
414 """Returns a context of union member for argument.""" 286 """Returns a context of union member for argument."""
415 this_cpp_value = 'result%d' % index 287 this_cpp_value = 'result%d' % index
416 this_cpp_type = idl_type.cpp_type 288 this_cpp_type = idl_type.cpp_type
417 this_cpp_type_initializer = idl_type.cpp_type_initializer 289 this_cpp_type_initializer = idl_type.cpp_type_initializer
418 cpp_return_value = this_cpp_value 290 cpp_return_value = this_cpp_value
419 291
420 if not idl_type.cpp_type_has_null_value: 292 if not idl_type.cpp_type_has_null_value:
421 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type) 293 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type)
422 this_cpp_type_initializer = '' 294 this_cpp_type_initializer = ''
423 cpp_return_value = '%s.get()' % this_cpp_value 295 cpp_return_value = '%s.get()' % this_cpp_value
424 296
425 if idl_type.is_string_type: 297 if idl_type.is_string_type:
426 null_check_value = '!%s.isNull()' % this_cpp_value 298 null_check_value = '!%s.isNull()' % this_cpp_value
427 else: 299 else:
428 null_check_value = this_cpp_value 300 null_check_value = this_cpp_value
429 301
430 return { 302 return {
431 'cpp_type': this_cpp_type, 303 'cpp_type': this_cpp_type,
432 'cpp_type_initializer': this_cpp_type_initializer, 304 'cpp_type_initializer': this_cpp_type_initializer,
433 'cpp_value': this_cpp_value, 305 'cpp_value': this_cpp_value,
434 'null_check_value': null_check_value, 306 'null_check_value': null_check_value,
435 'v8_set_return_value': idl_type.v8_set_return_value(
436 cpp_value=cpp_return_value,
437 release=idl_type.release),
438 } 307 }
439 308
440 309
441 def union_arguments(idl_type): 310 def union_arguments(idl_type):
442 return [union_member_argument_context(member_idl_type, index) 311 return [union_member_argument_context(member_idl_type, index)
443 for index, member_idl_type 312 for index, member_idl_type
444 in enumerate(idl_type.member_types)] 313 in enumerate(idl_type.member_types)]
445 314
446 315
447 def argument_default_cpp_value(argument): 316 def argument_default_cpp_value(argument):
448 if argument.idl_type.is_dictionary:
449 # We always create impl objects for IDL dictionaries.
450 return '%s::create()' % argument.idl_type.base_type
451 if not argument.default_value: 317 if not argument.default_value:
452 return None 318 return None
453 return argument.idl_type.literal_cpp_value(argument.default_value) 319 return argument.idl_type.literal_cpp_value(argument.default_value)
454 320
455 IdlTypeBase.union_arguments = None 321 IdlTypeBase.union_arguments = None
456 IdlUnionType.union_arguments = property(union_arguments) 322 IdlUnionType.union_arguments = property(union_arguments)
457 IdlArgument.default_cpp_value = property(argument_default_cpp_value) 323 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
OLDNEW
« no previous file with comments | « sky/engine/bindings2/scripts/v8_interface.py ('k') | sky/engine/bindings2/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698