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

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

Issue 215993002: Clean up callback interface code and template (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/templates/callback_interface.cpp » ('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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([ 46 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
47 'bindings/v8/V8Binding.h', 47 'bindings/v8/V8Binding.h',
48 'bindings/v8/V8Callback.h', 48 'bindings/v8/V8Callback.h',
49 'core/dom/ExecutionContext.h', 49 'core/dom/ExecutionContext.h',
50 'wtf/Assertions.h', 50 'wtf/Assertions.h',
51 'wtf/GetPtr.h', 51 'wtf/GetPtr.h',
52 'wtf/RefPtr.h', 52 'wtf/RefPtr.h',
53 ]) 53 ])
54 54
55 55
56 def cpp_to_v8_conversion(idl_type, name):
57 # FIXME: setting creation_context=v8::Handle<v8::Object>() is wrong,
58 # as toV8 then implicitly uses the current context, which causes leaks
59 # between isolate worlds if a different context should be used.
60 cpp_value_to_v8_value = idl_type.cpp_value_to_v8_value(name,
61 isolate='m_isolate', creation_context='v8::Handle<v8::Object>()')
62 return 'v8::Handle<v8::Value> {name}Handle = {cpp_to_v8};'.format(
63 name=name, cpp_to_v8=cpp_value_to_v8_value)
64
65
66 def cpp_type(idl_type): 56 def cpp_type(idl_type):
67 # FIXME: remove this function by making callback types consistent 57 # FIXME: remove this function by making callback types consistent
68 # (always use usual v8_types.cpp_type) 58 # (always use usual v8_types.cpp_type)
69 idl_type_name = idl_type.name 59 idl_type_name = idl_type.name
70 if idl_type_name == 'String': 60 if idl_type_name == 'String':
71 return 'const String&' 61 return 'const String&'
72 if idl_type_name == 'void': 62 if idl_type_name == 'void':
73 return 'void' 63 return 'void'
74 # Callbacks use raw pointers, so used_as_argument=True 64 # Callbacks use raw pointers, so used_as_argument=True
75 usual_cpp_type = idl_type.cpp_type_args(used_as_argument=True) 65 usual_cpp_type = idl_type.cpp_type_args(used_as_argument=True)
76 if usual_cpp_type.startswith(('Vector', 'WillBeHeapVector')): 66 if usual_cpp_type.startswith(('Vector', 'WillBeHeapVector')):
77 return 'const %s&' % usual_cpp_type 67 return 'const %s&' % usual_cpp_type
78 return usual_cpp_type 68 return usual_cpp_type
79 69
80 IdlType.callback_cpp_type = property(cpp_type) 70 IdlType.callback_cpp_type = property(cpp_type)
81 71
82 72
83 def generate_callback_interface(callback_interface): 73 def generate_callback_interface(callback_interface):
84 includes.clear() 74 includes.clear()
85 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) 75 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
86 name = callback_interface.name 76 return {
87
88 methods = [generate_method(operation)
89 for operation in callback_interface.operations]
90 template_contents = {
91 'conditional_string': v8_utilities.conditional_string(callback_interface ), 77 'conditional_string': v8_utilities.conditional_string(callback_interface ),
92 'cpp_class': name, 78 'cpp_class': callback_interface.name,
93 'v8_class': v8_utilities.v8_class_name(callback_interface), 79 'v8_class': v8_utilities.v8_class_name(callback_interface),
94 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES), 80 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
95 'methods': methods, 81 'methods': [generate_method(operation)
82 for operation in callback_interface.operations],
96 } 83 }
97 return template_contents
98 84
99 85
100 def add_includes_for_operation(operation): 86 def add_includes_for_operation(operation):
101 operation.idl_type.add_includes_for_type() 87 operation.idl_type.add_includes_for_type()
102 for argument in operation.arguments: 88 for argument in operation.arguments:
103 argument.idl_type.add_includes_for_type() 89 argument.idl_type.add_includes_for_type()
104 90
105 91
106 def generate_method(operation): 92 def generate_method(operation):
107 extended_attributes = operation.extended_attributes 93 extended_attributes = operation.extended_attributes
(...skipping 13 matching lines...) Expand all
121 'idl_type': idl_type_str, 107 'idl_type': idl_type_str,
122 'name': operation.name, 108 'name': operation.name,
123 } 109 }
124 contents.update(generate_arguments_contents(operation.arguments, call_with_t his_handle)) 110 contents.update(generate_arguments_contents(operation.arguments, call_with_t his_handle))
125 return contents 111 return contents
126 112
127 113
128 def generate_arguments_contents(arguments, call_with_this_handle): 114 def generate_arguments_contents(arguments, call_with_this_handle):
129 def generate_argument(argument): 115 def generate_argument(argument):
130 return { 116 return {
131 'name': argument.name, 117 'handle': '%sHandle' % argument.name,
132 'cpp_to_v8_conversion': cpp_to_v8_conversion(argument.idl_type, argu ment.name), 118 # FIXME: setting creation_context=v8::Handle<v8::Object>() is
119 # wrong, as toV8 then implicitly uses the current context, which
120 # causes leaks between isolated worlds if a different context is
121 # used.
122 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value(
123 argument.name, isolate='m_isolate',
124 creation_context='v8::Handle<v8::Object>()'),
133 } 125 }
134 126
135 argument_declarations = [ 127 argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle e lse []
136 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) 128 argument_declarations.extend(
137 for argument in arguments] 129 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
138 if call_with_this_handle: 130 for argument in arguments)
139 argument_declarations.insert(0, 'ScriptValue thisValue')
140 return { 131 return {
141 'argument_declarations': argument_declarations, 132 'argument_declarations': argument_declarations,
142 'arguments': [generate_argument(argument) for argument in arguments], 133 'arguments': [generate_argument(argument) for argument in arguments],
143 'handles': ['%sHandle' % argument.name for argument in arguments],
144 } 134 }
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/templates/callback_interface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698