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

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

Issue 581453002: Dartium Roll 38 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Sync'd w/ r 182210 Created 6 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 | Annotate | Revision Log
« no previous file with comments | « bindings/scripts/v8_attributes.py ('k') | bindings/scripts/v8_dictionary.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 10 matching lines...) Expand all
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """Generate template values for a callback interface. 29 """Generate template values for a callback interface.
30 30
31 Extends IdlType with property |callback_cpp_type|. 31 Extends IdlTypeBase with property |callback_cpp_type|.
32 32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """ 34 """
35 35
36 from idl_types import IdlType 36 from idl_types import IdlTypeBase
37 from v8_globals import includes 37 from v8_globals import includes
38 import v8_types 38 import v8_types
39 import v8_utilities 39 import v8_utilities
40 40
41 CALLBACK_INTERFACE_H_INCLUDES = frozenset([ 41 CALLBACK_INTERFACE_H_INCLUDES = frozenset([
42 'bindings/v8/ActiveDOMCallback.h', 42 'bindings/core/v8/ActiveDOMCallback.h',
43 'bindings/v8/DOMWrapperWorld.h', 43 'bindings/core/v8/DOMWrapperWorld.h',
44 'bindings/v8/ScopedPersistent.h', 44 'bindings/core/v8/ScopedPersistent.h',
45 ]) 45 ])
46 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([ 46 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
47 'bindings/v8/V8Binding.h', 47 'bindings/core/v8/ScriptController.h',
48 'bindings/v8/V8Callback.h', 48 'bindings/core/v8/V8Binding.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_type(idl_type): 56 def cpp_type(idl_type):
57 # FIXME: remove this function by making callback types consistent 57 # FIXME: remove this function by making callback types consistent
58 # (always use usual v8_types.cpp_type) 58 # (always use usual v8_types.cpp_type)
59 idl_type_name = idl_type.name 59 idl_type_name = idl_type.name
60 if idl_type_name == 'String': 60 if idl_type_name == 'String':
61 return 'const String&' 61 return 'const String&'
62 if idl_type_name == 'void': 62 if idl_type_name == 'void':
63 return 'void' 63 return 'void'
64 # Callbacks use raw pointers, so used_as_argument=True 64 # Callbacks use raw pointers, so raw_type=True
65 usual_cpp_type = idl_type.cpp_type_args(used_as_argument=True) 65 raw_cpp_type = idl_type.cpp_type_args(raw_type=True)
66 if usual_cpp_type.startswith(('Vector', 'HeapVector', 'WillBeHeapVector')): 66 if raw_cpp_type.startswith(('Vector', 'HeapVector', 'WillBeHeapVector')):
67 return 'const %s&' % usual_cpp_type 67 return 'const %s&' % raw_cpp_type
68 return usual_cpp_type 68 return raw_cpp_type
69 69
70 IdlType.callback_cpp_type = property(cpp_type) 70 IdlTypeBase.callback_cpp_type = property(cpp_type)
71 71
72 72
73 def generate_callback_interface(callback_interface): 73 def callback_interface_context(callback_interface):
74 includes.clear() 74 includes.clear()
75 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) 75 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
76 return { 76 return {
77 'conditional_string': v8_utilities.conditional_string(callback_interface ), 77 'conditional_string': v8_utilities.conditional_string(callback_interface ),
78 'cpp_class': callback_interface.name, 78 'cpp_class': callback_interface.name,
79 'v8_class': v8_utilities.v8_class_name(callback_interface), 79 'v8_class': v8_utilities.v8_class_name(callback_interface),
80 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES), 80 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
81 'methods': [generate_method(operation) 81 'methods': [method_context(operation)
82 for operation in callback_interface.operations 82 for operation in callback_interface.operations
83 if not v8_utilities.dart_custom_method(operation.extended_at tributes)], 83 if not v8_utilities.dart_custom_method(operation.extended_at tributes)],
84 } 84 }
85 85
86 86
87 def add_includes_for_operation(operation): 87 def add_includes_for_operation(operation):
88 operation.idl_type.add_includes_for_type() 88 operation.idl_type.add_includes_for_type()
89 for argument in operation.arguments: 89 for argument in operation.arguments:
90 argument.idl_type.add_includes_for_type() 90 argument.idl_type.add_includes_for_type()
91 91
92 92
93 def generate_method(operation): 93 def method_context(operation):
94 extended_attributes = operation.extended_attributes 94 extended_attributes = operation.extended_attributes
95 idl_type = operation.idl_type 95 idl_type = operation.idl_type
96 idl_type_str = str(idl_type) 96 idl_type_str = str(idl_type)
97 if idl_type_str not in ['boolean', 'void']: 97 if idl_type_str not in ['boolean', 'void']:
98 raise Exception('We only support callbacks that return boolean or void v alues.') 98 raise Exception('We only support callbacks that return boolean or void v alues.')
99 is_custom = 'Custom' in extended_attributes 99 is_custom = 'Custom' in extended_attributes
100 if not is_custom: 100 if not is_custom:
101 add_includes_for_operation(operation) 101 add_includes_for_operation(operation)
102 call_with = extended_attributes.get('CallWith') 102 call_with = extended_attributes.get('CallWith')
103 call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_ with, 'ThisValue') 103 call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_ with, 'ThisValue')
104 contents = { 104 context = {
105 'call_with_this_handle': call_with_this_handle, 105 'call_with_this_handle': call_with_this_handle,
106 'cpp_type': idl_type.callback_cpp_type, 106 'cpp_type': idl_type.callback_cpp_type,
107 'custom': is_custom,
108 'idl_type': idl_type_str, 107 'idl_type': idl_type_str,
108 'is_custom': is_custom,
109 'name': operation.name, 109 'name': operation.name,
110 } 110 }
111 contents.update(generate_arguments_contents(operation.arguments, call_with_t his_handle)) 111 context.update(arguments_context(operation.arguments,
112 return contents 112 call_with_this_handle))
113 return context
113 114
114 115
115 def generate_arguments_contents(arguments, call_with_this_handle): 116 def arguments_context(arguments, call_with_this_handle):
116 def generate_argument(argument): 117 def argument_context(argument):
117 return { 118 return {
118 'handle': '%sHandle' % argument.name, 119 'handle': '%sHandle' % argument.name,
119 # FIXME: setting creation_context=v8::Handle<v8::Object>() is
120 # wrong, as toV8 then implicitly uses the current context, which
121 # causes leaks between isolated worlds if a different context is
122 # used.
123 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( 120 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value(
124 argument.name, isolate='isolate', 121 argument.name, isolate='m_scriptState->isolate()',
125 creation_context='m_scriptState->context()->Global()'), 122 creation_context='m_scriptState->context()->Global()'),
126 } 123 }
127 124
128 argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle e lse [] 125 argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle e lse []
129 argument_declarations.extend( 126 argument_declarations.extend(
130 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) 127 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
131 for argument in arguments) 128 for argument in arguments)
132 return { 129 return {
133 'argument_declarations': argument_declarations, 130 'argument_declarations': argument_declarations,
134 'arguments': [generate_argument(argument) for argument in arguments], 131 'arguments': [argument_context(argument) for argument in arguments],
135 } 132 }
OLDNEW
« no previous file with comments | « bindings/scripts/v8_attributes.py ('k') | bindings/scripts/v8_dictionary.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698