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

Side by Side Diff: bindings/scripts/v8_methods.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_interface.py ('k') | bindings/scripts/v8_types.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 methods. 29 """Generate template values for methods.
30 30
31 Extends IdlType and IdlUnionType with property |union_arguments|. 31 Extends IdlArgument with property |default_cpp_value|.
32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|.
32 33
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """ 35 """
35 36
36 from idl_types import IdlType, IdlUnionType, inherits_interface 37 from idl_definitions import IdlArgument
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface
37 from v8_globals import includes 39 from v8_globals import includes
38 import v8_types 40 import v8_types
39 import v8_utilities 41 import v8_utilities
40 from v8_utilities import has_extended_attribute_value 42 from v8_utilities import has_extended_attribute_value
41 43
42 44
43 # Methods with any of these require custom method registration code in the 45 # Methods with any of these require custom method registration code in the
44 # interface's configure*Template() function. 46 # interface's configure*Template() function.
45 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ 47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
46 'DoNotCheckSecurity', 48 'DoNotCheckSecurity',
47 'DoNotCheckSignature', 49 'DoNotCheckSignature',
48 'NotEnumerable', 50 'NotEnumerable',
49 'ReadOnly',
50 'Unforgeable', 51 'Unforgeable',
51 ]) 52 ])
52 53
53 54
54 def argument_needs_try_catch(argument): 55 def argument_needs_try_catch(argument, return_promise):
55 idl_type = argument.idl_type 56 idl_type = argument.idl_type
56 base_type = not idl_type.array_or_sequence_type and idl_type.base_type 57 base_type = idl_type.base_type
57 58
58 return not ( 59 return not (
59 # These cases are handled by separate code paths in the 60 # These cases are handled by separate code paths in the
60 # generate_argument() macro in Source/bindings/templates/methods.cpp. 61 # generate_argument() macro in Source/bindings/templates/methods.cpp.
61 idl_type.is_callback_interface or 62 idl_type.is_callback_interface or
62 base_type == 'SerializedScriptValue' or 63 base_type == 'SerializedScriptValue' or
63 (argument.is_variadic and idl_type.is_wrapper_type) or 64 (argument.is_variadic and idl_type.is_wrapper_type) or
64 # String and enumeration arguments converted using one of the 65 # String and enumeration arguments converted using one of the
65 # TOSTRING_* macros in Source/bindings/v8/V8BindingMacros.h don't 66 # TOSTRING_* macros except for _PROMISE variants in
66 # use a v8::TryCatch. 67 # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch.
67 (base_type == 'DOMString' and not argument.is_variadic)) 68 (base_type == 'DOMString' and not argument.is_variadic and
69 not return_promise))
68 70
69 71
70 def generate_method(interface, method): 72 def use_local_result(method):
73 extended_attributes = method.extended_attributes
74 idl_type = method.idl_type
75 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
76 'ImplementedInPrivateScript' in extended_attributes or
77 'RaisesException' in extended_attributes or
78 idl_type.is_union_type or
79 idl_type.is_explicit_nullable)
80
81
82 def method_context(interface, method):
71 arguments = method.arguments 83 arguments = method.arguments
72 extended_attributes = method.extended_attributes 84 extended_attributes = method.extended_attributes
73 idl_type = method.idl_type 85 idl_type = method.idl_type
74 is_static = method.is_static 86 is_static = method.is_static
75 name = method.name 87 name = method.name
88 return_promise = idl_type.name == 'Promise'
76 89
77 idl_type.add_includes_for_type() 90 idl_type.add_includes_for_type()
78 this_cpp_value = cpp_value(interface, method, len(arguments)) 91 this_cpp_value = cpp_value(interface, method, len(arguments))
79 92
80 def function_template(): 93 def function_template():
81 if is_static: 94 if is_static:
82 return 'functionTemplate' 95 return 'functionTemplate'
83 if 'Unforgeable' in extended_attributes: 96 if 'Unforgeable' in extended_attributes:
84 return 'instanceTemplate' 97 return 'instanceTemplate'
85 return 'prototypeTemplate' 98 return 'prototypeTemplate'
86 99
100 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes
101 if is_implemented_in_private_script:
102 includes.add('bindings/core/v8/PrivateScriptRunner.h')
103 includes.add('core/frame/LocalFrame.h')
104 includes.add('platform/ScriptForbiddenScope.h')
105
106 # [OnlyExposedToPrivateScript]
107 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended _attributes
108
87 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments') 109 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments')
88 if is_call_with_script_arguments: 110 if is_call_with_script_arguments:
89 includes.update(['bindings/v8/ScriptCallStackFactory.h', 111 includes.update(['bindings/core/v8/ScriptCallStackFactory.h',
90 'core/inspector/ScriptArguments.h']) 112 'core/inspector/ScriptArguments.h'])
91 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') 113 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
92 if is_call_with_script_state: 114 if is_call_with_script_state:
93 includes.add('bindings/v8/V8ScriptState.h') 115 includes.add('bindings/core/v8/V8ScriptState.h')
94 is_check_security_for_node = 'CheckSecurity' in extended_attributes 116 is_check_security_for_node = 'CheckSecurity' in extended_attributes
95 if is_check_security_for_node: 117 if is_check_security_for_node:
96 includes.add('bindings/common/BindingSecurity.h') 118 includes.add('bindings/common/BindingSecurity.h')
97 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 119 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
98 if is_custom_element_callbacks: 120 if is_custom_element_callbacks:
99 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') 121 includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
100 122
101 has_event_listener_argument = any(
102 argument for argument in arguments
103 if argument.idl_type.name == 'EventListener')
104 is_check_security_for_frame = ( 123 is_check_security_for_frame = (
105 'CheckSecurity' in interface.extended_attributes and 124 'CheckSecurity' in interface.extended_attributes and
106 'DoNotCheckSecurity' not in extended_attributes) 125 'DoNotCheckSecurity' not in extended_attributes)
107 is_raises_exception = 'RaisesException' in extended_attributes 126 is_raises_exception = 'RaisesException' in extended_attributes
108 127
109 arguments_need_try_catch = any(argument_needs_try_catch(argument) 128 arguments_need_try_catch = (
110 for argument in arguments) 129 any(argument_needs_try_catch(argument, return_promise)
130 for argument in arguments))
111 131
112 return { 132 return {
113 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 133 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
114 'arguments': [generate_argument(interface, method, argument, index) 134 'arguments': [argument_context(interface, method, argument, index)
115 for index, argument in enumerate(arguments)], 135 for index, argument in enumerate(arguments)],
136 'argument_declarations_for_private_script':
137 argument_declarations_for_private_script(interface, method),
116 'arguments_need_try_catch': arguments_need_try_catch, 138 'arguments_need_try_catch': arguments_need_try_catch,
117 'conditional_string': v8_utilities.conditional_string(method), 139 'conditional_string': v8_utilities.conditional_string(method),
118 'cpp_type': idl_type.cpp_type, 140 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
141 if idl_type.is_explicit_nullable else idl_type.cpp_type),
119 'cpp_value': this_cpp_value, 142 'cpp_value': this_cpp_value,
143 'cpp_type_initializer': idl_type.cpp_type_initializer,
120 'custom_registration_extended_attributes': 144 'custom_registration_extended_attributes':
121 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 145 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
122 extended_attributes.iterkeys()), 146 extended_attributes.iterkeys()),
123 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 147 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
148 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
124 'function_template': function_template(), 149 'function_template': function_template(),
125 'has_custom_registration': is_static or 150 'has_custom_registration': is_static or
126 v8_utilities.has_extended_attribute( 151 v8_utilities.has_extended_attribute(
127 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 152 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
128 'has_event_listener_argument': has_event_listener_argument,
129 'has_exception_state': 153 'has_exception_state':
130 has_event_listener_argument or
131 is_raises_exception or 154 is_raises_exception or
132 is_check_security_for_frame or 155 is_check_security_for_frame or
156 interface.name == 'EventTarget' or # FIXME: merge with is_check_sec urity_for_frame http://crbug.com/383699
133 any(argument for argument in arguments 157 any(argument for argument in arguments
134 if argument.idl_type.name in ('ByteString', 158 if argument.idl_type.name == 'SerializedScriptValue' or
135 'ScalarValueString', 159 argument.idl_type.may_raise_exception_on_conversion),
136 'SerializedScriptValue') or
137 argument.idl_type.is_integer_type),
138 'idl_type': idl_type.base_type, 160 'idl_type': idl_type.base_type,
139 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 161 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
140 'is_call_with_script_arguments': is_call_with_script_arguments, 162 'is_call_with_script_arguments': is_call_with_script_arguments,
141 'is_call_with_script_state': is_call_with_script_state, 163 'is_call_with_script_state': is_call_with_script_state,
142 'is_check_security_for_frame': is_check_security_for_frame, 164 'is_check_security_for_frame': is_check_security_for_frame,
143 'is_check_security_for_node': is_check_security_for_node, 165 'is_check_security_for_node': is_check_security_for_node,
144 'is_custom': 'Custom' in extended_attributes, 166 'is_custom': 'Custom' in extended_attributes,
145 'is_custom_element_callbacks': is_custom_element_callbacks, 167 'is_custom_element_callbacks': is_custom_element_callbacks,
146 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes, 168 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
147 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s, 169 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
170 'is_explicit_nullable': idl_type.is_explicit_nullable,
171 'is_implemented_in_private_script': is_implemented_in_private_script,
148 'is_partial_interface_member': 172 'is_partial_interface_member':
149 'PartialInterfaceImplementedAs' in extended_attributes, 173 'PartialInterfaceImplementedAs' in extended_attributes,
150 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 174 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
151 'is_raises_exception': is_raises_exception, 175 'is_raises_exception': is_raises_exception,
152 'is_read_only': 'ReadOnly' in extended_attributes, 176 'is_read_only': 'Unforgeable' in extended_attributes,
153 'is_static': is_static, 177 'is_static': is_static,
154 'is_variadic': arguments and arguments[-1].is_variadic, 178 'is_variadic': arguments and arguments[-1].is_variadic,
155 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] 179 'measure_as': v8_utilities.measure_as(method), # [MeasureAs]
156 'name': name, 180 'name': name,
157 'number_of_arguments': len(arguments), 181 'number_of_arguments': len(arguments),
158 'number_of_required_arguments': len([ 182 'number_of_required_arguments': len([
159 argument for argument in arguments 183 argument for argument in arguments
160 if not (argument.is_optional or argument.is_variadic)]), 184 if not (argument.is_optional or argument.is_variadic)]),
161 'number_of_required_or_variadic_arguments': len([ 185 'number_of_required_or_variadic_arguments': len([
162 argument for argument in arguments 186 argument for argument in arguments
163 if not argument.is_optional]), 187 if not argument.is_optional]),
188 'only_exposed_to_private_script': is_only_exposed_to_private_script,
164 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] 189 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled]
190 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value(
191 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True),
165 'property_attributes': property_attributes(method), 192 'property_attributes': property_attributes(method),
166 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 193 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
194 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script),
167 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', 195 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
168 'union_arguments': idl_type.union_arguments, 196 'union_arguments': idl_type.union_arguments,
197 'use_local_result': use_local_result(method),
198 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
169 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 199 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
170 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 200 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
171 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings]
172 } 201 }
173 202
174 203
175 def generate_argument(interface, method, argument, index): 204 def argument_context(interface, method, argument, index):
176 extended_attributes = argument.extended_attributes 205 extended_attributes = argument.extended_attributes
177 idl_type = argument.idl_type 206 idl_type = argument.idl_type
178 this_cpp_value = cpp_value(interface, method, index) 207 this_cpp_value = cpp_value(interface, method, index)
179 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 208 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
209 return_promise = (method.idl_type.name == 'Promise' if method.idl_type
210 else False)
211
212 if ('ImplementedInPrivateScript' in extended_attributes and
213 not idl_type.is_wrapper_type and
214 not idl_type.is_basic_type):
215 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
180 216
181 return { 217 return {
182 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, 218 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es,
183 used_as_argument=True, 219 raw_type=True,
184 used_as_variadic_argument=argument.is _variadic), 220 used_as_variadic_argument=argument.is _variadic),
221 'cpp_type_initializer': idl_type.cpp_type_initializer,
185 'cpp_value': this_cpp_value, 222 'cpp_value': this_cpp_value,
186 # FIXME: check that the default value's type is compatible with the argu ment's 223 # FIXME: check that the default value's type is compatible with the argu ment's
187 'default_value': str(argument.default_value) if argument.default_value e lse None, 224 'default_value': argument.default_cpp_value,
188 'enum_validation_expression': idl_type.enum_validation_expression, 225 'enum_validation_expression': idl_type.enum_validation_expression,
226 'handle': '%sHandle' % argument.name,
189 # FIXME: remove once [Default] removed and just use argument.default_val ue 227 # FIXME: remove once [Default] removed and just use argument.default_val ue
190 'has_default': 'Default' in extended_attributes or argument.default_valu e, 228 'has_default': 'Default' in extended_attributes or argument.default_valu e,
191 'has_event_listener_argument': any(
192 argument_so_far for argument_so_far in method.arguments[:index]
193 if argument_so_far.idl_type.name == 'EventListener'),
194 'has_type_checking_interface': 229 'has_type_checking_interface':
195 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or 230 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
196 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and 231 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
197 idl_type.is_wrapper_type, 232 idl_type.is_wrapper_type,
198 'has_type_checking_unrestricted': 233 'has_type_checking_unrestricted':
199 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or 234 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or
200 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and 235 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and
201 idl_type.name in ('Float', 'Double'), 236 idl_type.name in ('Float', 'Double'),
202 # Dictionary is special-cased, but arrays and sequences shouldn't be 237 # Dictionary is special-cased, but arrays and sequences shouldn't be
203 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 238 'idl_type': idl_type.base_type,
204 'idl_type_object': idl_type, 239 'idl_type_object': idl_type,
205 'index': index, 240 'index': index,
206 'is_clamp': 'Clamp' in extended_attributes, 241 'is_clamp': 'Clamp' in extended_attributes,
207 'is_callback_interface': idl_type.is_callback_interface, 242 'is_callback_interface': idl_type.is_callback_interface,
208 'is_nullable': idl_type.is_nullable, 243 'is_nullable': idl_type.is_nullable,
209 'is_optional': argument.is_optional, 244 'is_optional': argument.is_optional,
210 'is_variadic_wrapper_type': is_variadic_wrapper_type, 245 'is_variadic_wrapper_type': is_variadic_wrapper_type,
211 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
212 'is_wrapper_type': idl_type.is_wrapper_type, 246 'is_wrapper_type': idl_type.is_wrapper_type,
213 'name': argument.name, 247 'name': argument.name,
248 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
249 argument.name, isolate='scriptState->isolate()',
250 creation_context='scriptState->context()->Global()'),
251 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
214 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 252 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
215 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 253 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, return_promise=return_promise),
216 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex), 254 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
217 } 255 }
218 256
219 257
258 def argument_declarations_for_private_script(interface, method):
259 argument_declarations = ['LocalFrame* frame']
260 argument_declarations.append('%s* holderImpl' % interface.name)
261 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
262 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts])
263 if method.idl_type.name != 'void':
264 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu lt'))
265 return argument_declarations
266
267
220 ################################################################################ 268 ################################################################################
221 # Value handling 269 # Value handling
222 ################################################################################ 270 ################################################################################
223 271
224 def cpp_value(interface, method, number_of_arguments): 272 def cpp_value(interface, method, number_of_arguments):
225 def cpp_argument(argument): 273 def cpp_argument(argument):
226 idl_type = argument.idl_type 274 idl_type = argument.idl_type
227 if idl_type.name == 'EventListener': 275 if idl_type.name == 'EventListener':
228 if (interface.name == 'EventTarget' and
229 method.name == 'removeEventListener'):
230 # FIXME: remove this special case by moving get() into
231 # EventTarget::removeEventListener
232 return '%s.get()' % argument.name
233 return argument.name 276 return argument.name
234 if (idl_type.is_callback_interface or 277 if (idl_type.is_callback_interface or
235 idl_type.name in ['NodeFilter', 'XPathNSResolver']): 278 idl_type.name in ['NodeFilter', 'NodeFilterOrNull',
279 'XPathNSResolver', 'XPathNSResolverOrNull']):
236 # FIXME: remove this special case 280 # FIXME: remove this special case
237 return '%s.release()' % argument.name 281 return '%s.release()' % argument.name
238 return argument.name 282 return argument.name
239 283
240 # Truncate omitted optional arguments 284 # Truncate omitted optional arguments
241 arguments = method.arguments[:number_of_arguments] 285 arguments = method.arguments[:number_of_arguments]
242 cpp_arguments = [] 286 cpp_arguments = []
287 if 'ImplementedInPrivateScript' in method.extended_attributes:
288 cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrent Context())')
289 cpp_arguments.append('impl')
290
243 if method.is_constructor: 291 if method.is_constructor:
244 call_with_values = interface.extended_attributes.get('ConstructorCallWit h') 292 call_with_values = interface.extended_attributes.get('ConstructorCallWit h')
245 else: 293 else:
246 call_with_values = method.extended_attributes.get('CallWith') 294 call_with_values = method.extended_attributes.get('CallWith')
247 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) 295 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values))
296
248 # Members of IDL partial interface definitions are implemented in C++ as 297 # Members of IDL partial interface definitions are implemented in C++ as
249 # static member functions, which for instance members (non-static members) 298 # static member functions, which for instance members (non-static members)
250 # take *impl as their first argument 299 # take *impl as their first argument
251 if ('PartialInterfaceImplementedAs' in method.extended_attributes and 300 if ('PartialInterfaceImplementedAs' in method.extended_attributes and
301 not 'ImplementedInPrivateScript' in method.extended_attributes and
252 not method.is_static): 302 not method.is_static):
253 cpp_arguments.append('*impl') 303 cpp_arguments.append('*impl')
254 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) 304 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
305
255 this_union_arguments = method.idl_type and method.idl_type.union_arguments 306 this_union_arguments = method.idl_type and method.idl_type.union_arguments
256 if this_union_arguments: 307 if this_union_arguments:
257 cpp_arguments.extend(this_union_arguments) 308 cpp_arguments.extend([member_argument['cpp_value']
309 for member_argument in this_union_arguments])
258 310
259 if ('RaisesException' in method.extended_attributes or 311 if 'ImplementedInPrivateScript' in method.extended_attributes:
312 if method.idl_type.name != 'void':
313 cpp_arguments.append('&result')
314 elif ('RaisesException' in method.extended_attributes or
260 (method.is_constructor and 315 (method.is_constructor and
261 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): 316 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))):
262 cpp_arguments.append('exceptionState') 317 cpp_arguments.append('exceptionState')
263 318
264 if method.name == 'Constructor': 319 if method.name == 'Constructor':
265 base_name = 'create' 320 base_name = 'create'
266 elif method.name == 'NamedConstructor': 321 elif method.name == 'NamedConstructor':
267 base_name = 'createForJSConstructor' 322 base_name = 'createForJSConstructor'
323 elif 'ImplementedInPrivateScript' in method.extended_attributes:
324 base_name = '%sMethod' % method.name
268 else: 325 else:
269 base_name = v8_utilities.cpp_name(method) 326 base_name = v8_utilities.cpp_name(method)
270 327
271 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) 328 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name)
272 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) 329 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
273 330
274 331
275 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False) : 332 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False) :
276 idl_type = method.idl_type 333 idl_type = method.idl_type
277 extended_attributes = method.extended_attributes 334 extended_attributes = method.extended_attributes
278 if not idl_type or idl_type.name == 'void': 335 if not idl_type or idl_type.name == 'void':
279 # Constructors and void methods don't have a return type 336 # Constructors and void methods don't have a return type
280 return None 337 return None
281 338
339 if ('ImplementedInPrivateScript' in extended_attributes and
340 not idl_type.is_wrapper_type and
341 not idl_type.is_basic_type):
342 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
343
282 release = False 344 release = False
283 # [CallWith=ScriptState], [RaisesException] 345 # [CallWith=ScriptState], [RaisesException]
284 if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 346 if use_local_result(method):
285 'RaisesException' in extended_attributes or 347 if idl_type.is_explicit_nullable:
286 idl_type.is_union_type): 348 # result is of type Nullable<T>
287 cpp_value = 'result' # use local variable for value 349 cpp_value = 'result.get()'
350 else:
351 cpp_value = 'result'
288 release = idl_type.release 352 release = idl_type.release
289 353
290 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 354 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
291 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 355 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world)
292 356
293 357
294 def v8_value_to_local_cpp_variadic_value(argument, index): 358 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise):
295 assert argument.is_variadic 359 assert argument.is_variadic
296 idl_type = argument.idl_type 360 idl_type = argument.idl_type
297 361
298 macro = 'TONATIVE_VOID_INTERNAL' 362 suffix = ''
363
364 macro = 'TONATIVE_VOID'
299 macro_args = [ 365 macro_args = [
300 argument.name, 366 argument.name,
301 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), 367 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index),
302 ] 368 ]
303 369
304 return '%s(%s)' % (macro, ', '.join(macro_args)) 370 if return_promise:
371 suffix += '_PROMISE'
372 macro_args.append('info')
373
374 suffix += '_INTERNAL'
375
376 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args))
305 377
306 378
307 def v8_value_to_local_cpp_value(argument, index): 379 def v8_value_to_local_cpp_value(argument, index, return_promise=False):
308 extended_attributes = argument.extended_attributes 380 extended_attributes = argument.extended_attributes
309 idl_type = argument.idl_type 381 idl_type = argument.idl_type
310 name = argument.name 382 name = argument.name
311 if argument.is_variadic: 383 if argument.is_variadic:
312 return v8_value_to_local_cpp_variadic_value(argument, index) 384 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise)
313 # FIXME: This special way of handling string arguments with null defaults 385 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
314 # can go away once we fully support default values. 386 name, index=index, declare_varia ble=False, return_promise=return_promise)
315 if (argument.is_optional and
316 idl_type.name in ('String', 'ByteString', 'ScalarValueString') and
317 argument.default_value and argument.default_value.is_null):
318 v8_value = 'argumentOrNull(info, %s)' % index
319 else:
320 v8_value = 'info[%s]' % index
321 return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value,
322 name, index=index, declare_varia ble=False)
323 387
324 388
325 ################################################################################ 389 ################################################################################
326 # Auxiliary functions 390 # Auxiliary functions
327 ################################################################################ 391 ################################################################################
328 392
329 # [NotEnumerable] 393 # [NotEnumerable]
330 def property_attributes(method): 394 def property_attributes(method):
331 extended_attributes = method.extended_attributes 395 extended_attributes = method.extended_attributes
332 property_attributes_list = [] 396 property_attributes_list = []
333 if 'NotEnumerable' in extended_attributes: 397 if 'NotEnumerable' in extended_attributes:
334 property_attributes_list.append('v8::DontEnum') 398 property_attributes_list.append('v8::DontEnum')
335 if 'ReadOnly' in extended_attributes: 399 if 'Unforgeable' in extended_attributes:
336 property_attributes_list.append('v8::ReadOnly') 400 property_attributes_list.append('v8::ReadOnly')
337 if property_attributes_list: 401 if property_attributes_list:
338 property_attributes_list.insert(0, 'v8::DontDelete') 402 property_attributes_list.insert(0, 'v8::DontDelete')
339 return property_attributes_list 403 return property_attributes_list
340 404
341 405
406 def union_member_argument_context(idl_type, index):
407 """Returns a context of union member for argument."""
408 this_cpp_value = 'result%d' % index
409 this_cpp_type = idl_type.cpp_type
410 cpp_return_value = this_cpp_value
411
412 if not idl_type.cpp_type_has_null_value:
413 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type)
414 cpp_return_value = '%s.get()' % this_cpp_value
415
416 if idl_type.is_string_type:
417 null_check_value = '!%s.isNull()' % this_cpp_value
418 else:
419 null_check_value = this_cpp_value
420
421 return {
422 'cpp_type': this_cpp_type,
423 'cpp_value': this_cpp_value,
424 'null_check_value': null_check_value,
425 'v8_set_return_value': idl_type.v8_set_return_value(
426 cpp_value=cpp_return_value,
427 release=idl_type.release),
428 }
429
430
342 def union_arguments(idl_type): 431 def union_arguments(idl_type):
343 """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for u nion types, for use in setting return value""" 432 return [union_member_argument_context(member_idl_type, index)
344 return [arg 433 for index, member_idl_type
345 for i in range(len(idl_type.member_types)) 434 in enumerate(idl_type.member_types)]
346 for arg in ['result%sEnabled' % i, 'result%s' % i]]
347 435
348 IdlType.union_arguments = property(lambda self: None) 436
437 def argument_default_cpp_value(argument):
438 if not argument.default_value:
439 return None
440 return argument.idl_type.literal_cpp_value(argument.default_value)
441
442 IdlTypeBase.union_arguments = None
349 IdlUnionType.union_arguments = property(union_arguments) 443 IdlUnionType.union_arguments = property(union_arguments)
444 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
OLDNEW
« no previous file with comments | « bindings/scripts/v8_interface.py ('k') | bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698