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

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

Issue 2312093003: Generated bindings for IDL callback functions (Closed)
Patch Set: Addressed win failure Created 4 years, 3 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
(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 # pylint: disable=W0403
11 import v8_utilities # pylint: disable=W0403
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 'cpp_includes': sorted(CALLBACK_FUNCTION_CPP_INCLUDES),
33 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
34 'idl_type': idl_type_str,
35 '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(
37 callback_function.extended_attributes, 'v8ReturnValue', 'cppValue',
38 bailout_return_value="false") if idl_type.cpp_type != 'void' else No ne,
39 'v8_class': v8_utilities.v8_class_name(callback_function),
40 }
41 context.update(arguments_context(callback_function.arguments, context['retur n_cpp_type']))
42 return context
43
44
45 def arguments_context(arguments, return_cpp_type):
46 def argument_context(argument):
47 return {
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 'argument_name': '%sArgument' % argument.name,
52 }
53
54 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip tWrappable']
55 argument_declarations.extend(
56 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
57 for argument in arguments)
58 if return_cpp_type:
59 argument_declarations.append('%s returnValue' % return_cpp_type)
60 return {
61 'argument_declarations': argument_declarations,
62 'arguments': [argument_context(argument) for argument in arguments],
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698