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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/v8_callback_function.py

Issue 2367543004: Extended implementation to use interface as arguments (Closed)
Patch Set: Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 values for a callback function. 5 """Generate template values for a callback function.
6 6
7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
8 """ 8 """
9 9
10 from v8_globals import includes # pylint: disable=W0403 10 from v8_globals import includes # pylint: disable=W0403
11 import v8_utilities # pylint: disable=W0403 11 import v8_utilities # pylint: disable=W0403
12 12
13 CALLBACK_FUNCTION_H_INCLUDES = frozenset([ 13 CALLBACK_FUNCTION_H_INCLUDES = frozenset([
14 'bindings/core/v8/ScopedPersistent.h', 14 'bindings/core/v8/ScopedPersistent.h',
15 'platform/heap/Handle.h', 15 'platform/heap/Handle.h',
16 'wtf/text/WTFString.h', 16 'wtf/text/WTFString.h',
17 ]) 17 ])
18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ 18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([
19 'bindings/core/v8/ScriptState.h', 19 'bindings/core/v8/ScriptState.h',
20 'bindings/core/v8/V8Binding.h', 20 'bindings/core/v8/V8Binding.h',
21 'wtf/Assertions.h', 21 'wtf/Assertions.h',
22 ]) 22 ])
23 23
24 24
25 def callback_function_context(callback_function): 25 def callback_function_context(callback_function):
26 includes.clear() 26 includes.clear()
27 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) 27 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
28 idl_type = callback_function.idl_type 28 idl_type = callback_function.idl_type
29 idl_type_str = str(idl_type) 29 idl_type_str = str(idl_type)
30 cpp_includes = set(CALLBACK_FUNCTION_CPP_INCLUDES)
peria 2016/09/23 02:50:05 you can use |includes| instead of this?
lkawai 2016/09/23 05:35:44 Done.
31 forward_declarations = []
32 for argument in callback_function.arguments:
33 for argument_type in list(argument.idl_type.idl_types()):
34 if argument_type.is_interface_type:
bashi 2016/09/23 02:16:05 why simply do following won't work? if argument.i
lkawai 2016/09/23 02:43:42 As I defined callback function using array of inte
peria 2016/09/23 02:50:05 I recommend to make a utility function which takes
bashi 2016/09/23 02:57:56 Hmm, I'm not sure why you need to use IdlArrayType
lkawai 2016/09/23 05:35:44 Acknowledged.
lkawai 2016/09/23 05:35:44 Done.
lkawai 2016/09/23 05:35:45 Done.
35 forward_declarations.append('%s' % argument_type.name)
peria 2016/09/23 02:50:05 do we need "'%s' %"?
lkawai 2016/09/23 05:35:44 Done.
36 cpp_includes.update(argument.idl_type.includes_for_type(callback_functio n.extended_attributes))
bashi 2016/09/23 02:16:05 Could you use idl_type.add_includes_for_type inste
lkawai 2016/09/23 02:43:42 Done.
peria 2016/09/23 02:50:05 Not related to this CL, but I feel the name idl_ty
bashi 2016/09/23 03:04:05 Yeah, I totally agree we should avoid using global
lkawai 2016/09/23 05:35:44 Acknowledged.
30 context = { 37 context = {
31 'cpp_class': callback_function.name, 38 'cpp_class': callback_function.name,
32 'cpp_includes': sorted(CALLBACK_FUNCTION_CPP_INCLUDES), 39 'cpp_includes': sorted(cpp_includes),
bashi 2016/09/23 02:16:05 cpp_includes -> includes
lkawai 2016/09/23 02:43:42 Done.
40 'forward_declarations': forward_declarations,
33 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES), 41 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
34 'idl_type': idl_type_str, 42 'idl_type': idl_type_str,
35 'return_cpp_type': (idl_type.cpp_type + '&') if idl_type.cpp_type != 'vo id' else None, 43 'return_cpp_type': (idl_type.cpp_type + '&') if idl_type.cpp_type != 'vo id' else None,
36 'return_value': idl_type.v8_value_to_local_cpp_value( 44 'return_value': idl_type.v8_value_to_local_cpp_value(
37 callback_function.extended_attributes, 'v8ReturnValue', 'cppValue', 45 callback_function.extended_attributes, 'v8ReturnValue', 'cppValue',
38 bailout_return_value="false") if idl_type.cpp_type != 'void' else No ne, 46 bailout_return_value="false") if idl_type.cpp_type != 'void' else No ne,
39 'v8_class': v8_utilities.v8_class_name(callback_function), 47 'v8_class': v8_utilities.v8_class_name(callback_function),
40 } 48 }
41 context.update(arguments_context(callback_function.arguments, context['retur n_cpp_type'])) 49 context.update(arguments_context(callback_function.arguments, context['retur n_cpp_type']))
42 return context 50 return context
(...skipping 11 matching lines...) Expand all
54 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip tWrappable'] 62 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip tWrappable']
55 argument_declarations.extend( 63 argument_declarations.extend(
56 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) 64 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
57 for argument in arguments) 65 for argument in arguments)
58 if return_cpp_type: 66 if return_cpp_type:
59 argument_declarations.append('%s returnValue' % return_cpp_type) 67 argument_declarations.append('%s returnValue' % return_cpp_type)
60 return { 68 return {
61 'argument_declarations': argument_declarations, 69 'argument_declarations': argument_declarations,
62 'arguments': [argument_context(argument) for argument in arguments], 70 'arguments': [argument_context(argument) for argument in arguments],
63 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698