OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 """Generate template values for a callback function. | |
6 | |
7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | |
8 """ | |
9 | |
10 from v8_globals import includes | |
11 import v8_utilities | |
12 | |
13 CALLBACK_FUNCTION_H_INCLUDES = frozenset([ | |
14 'bindings/core/v8/ScopedPersistent.h', | |
15 'platform/heap/Handle.h', | |
16 'wtf/text/WTFString.h', | |
17 ]) | |
18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ | |
19 'bindings/core/v8/ScriptState.h', | |
20 'bindings/core/v8/V8Binding.h', | |
21 'wtf/Assertions.h', | |
22 ]) | |
23 | |
24 | |
25 def callback_function_context(callback_function): | |
26 includes.clear() | |
27 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) | |
28 idl_type = callback_function.idl_type | |
29 idl_type_str = str(idl_type) | |
30 context = { | |
31 'cpp_class': callback_function.name, | |
32 'v8_class': v8_utilities.v8_class_name(callback_function), | |
bashi
2016/09/16 05:51:19
nit: alphabetical order
lkawai
2016/09/16 10:03:19
Done.
| |
33 'header_includes': set(CALLBACK_FUNCTION_H_INCLUDES), | |
34 'cpp_includes': set(CALLBACK_FUNCTION_CPP_INCLUDES), | |
35 'return_cpp_type': idl_type.cpp_type + '&', | |
36 'idl_type': idl_type_str, | |
37 'return_cpp_value': idl_type.v8_value_to_local_cpp_value( | |
peria
2016/09/16 05:48:18
This entry has not a value but a function, so I pr
lkawai
2016/09/16 10:03:19
Done.
| |
38 callback_function.extended_attributes, 'currentValue', 'cppValue', b ailout_return_value="false"), | |
39 } | |
40 context.update(arguments_context(callback_function.arguments, context['retur n_cpp_type'])) | |
41 return context | |
42 | |
43 | |
44 def arguments_context(arguments, return_cpp_type): | |
45 def argument_context(argument): | |
46 return { | |
47 'handle_name': '%sHandle' % argument.name, | |
bashi
2016/09/16 05:51:19
nit: alphabetical order
lkawai
2016/09/16 10:03:19
Done.
| |
48 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( | |
49 argument.name, isolate='scriptState->isolate()', | |
50 creation_context='scriptState->context()->Global()'), | |
51 } | |
52 | |
53 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip tWrappable'] | |
54 argument_declarations.extend( | |
55 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) | |
56 for argument in arguments) | |
57 if return_cpp_type != 'void': | |
peria
2016/09/16 05:48:18
|return_cpp_type| has a suffix '&' as you defined
lkawai
2016/09/16 10:03:19
Done.
| |
58 argument_declarations.append('%s returnValue' % return_cpp_type) | |
59 return { | |
60 'argument_declarations': argument_declarations, | |
61 'arguments': [argument_context(argument) for argument in arguments], | |
62 } | |
OLD | NEW |