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

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

Issue 1660113002: Updated to Chrome 45 (2454) moved from SVN to git. Base URL: https://github.com/dart-lang/webcore.git@roll_45
Patch Set: Created 4 years, 10 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
« 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 21 matching lines...) Expand all
32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|. 32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|.
33 33
34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
35 """ 35 """
36 36
37 from idl_definitions import IdlArgument, IdlOperation 37 from idl_definitions import IdlArgument, IdlOperation
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface 38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface
39 from v8_globals import includes 39 from v8_globals import includes
40 import v8_types 40 import v8_types
41 import v8_utilities 41 import v8_utilities
42 from v8_utilities import has_extended_attribute_value 42 from v8_utilities import (has_extended_attribute_value, is_unforgeable,
43 is_legacy_interface_type_checking)
43 44
44 45
45 # Methods with any of these require custom method registration code in the 46 # Methods with any of these require custom method registration code in the
46 # interface's configure*Template() function. 47 # interface's configure*Template() function.
47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ 48 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
48 'DoNotCheckSecurity', 49 'DoNotCheckSecurity',
49 'DoNotCheckSignature', 50 'DoNotCheckSignature',
50 'NotEnumerable', 51 'NotEnumerable',
51 'Unforgeable', 52 'Unforgeable',
52 ]) 53 ])
53 54
54 55
55 def use_local_result(method): 56 def use_local_result(method):
56 extended_attributes = method.extended_attributes 57 extended_attributes = method.extended_attributes
57 idl_type = method.idl_type 58 idl_type = method.idl_type
58 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 59 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
59 'ImplementedInPrivateScript' in extended_attributes or 60 'ImplementedInPrivateScript' in extended_attributes or
60 'RaisesException' in extended_attributes or 61 'RaisesException' in extended_attributes or
61 idl_type.is_union_type or 62 idl_type.is_union_type or
62 idl_type.is_explicit_nullable) 63 idl_type.is_explicit_nullable)
63 64
64 65
65 def method_context(interface, method): 66 def method_context(interface, method, is_visible=True):
66 arguments = method.arguments 67 arguments = method.arguments
67 extended_attributes = method.extended_attributes 68 extended_attributes = method.extended_attributes
68 idl_type = method.idl_type 69 idl_type = method.idl_type
69 is_static = method.is_static 70 is_static = method.is_static
70 name = method.name 71 name = method.name
71 72
72 idl_type.add_includes_for_type() 73 if is_visible:
74 idl_type.add_includes_for_type(extended_attributes)
75
73 this_cpp_value = cpp_value(interface, method, len(arguments)) 76 this_cpp_value = cpp_value(interface, method, len(arguments))
74 77
75 def function_template(): 78 def function_template():
76 if is_static: 79 if is_static:
77 return 'functionTemplate' 80 return 'functionTemplate'
78 if 'Unforgeable' in extended_attributes: 81 if is_unforgeable(interface, method):
79 return 'instanceTemplate' 82 return 'instanceTemplate'
80 return 'prototypeTemplate' 83 return 'prototypeTemplate'
81 84
82 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes 85 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes
83 if is_implemented_in_private_script: 86 if is_implemented_in_private_script:
84 includes.add('bindings/core/v8/PrivateScriptRunner.h') 87 includes.add('bindings/core/v8/PrivateScriptRunner.h')
85 includes.add('core/frame/LocalFrame.h') 88 includes.add('core/frame/LocalFrame.h')
86 includes.add('platform/ScriptForbiddenScope.h') 89 includes.add('platform/ScriptForbiddenScope.h')
87 90
88 # [OnlyExposedToPrivateScript] 91 # [OnlyExposedToPrivateScript]
89 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended _attributes 92 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended _attributes
90 93
91 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments') 94 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi th', 'ScriptArguments')
92 if is_call_with_script_arguments: 95 if is_call_with_script_arguments:
93 includes.update(['bindings/core/v8/ScriptCallStackFactory.h', 96 includes.update(['bindings/core/v8/ScriptCallStackFactory.h',
94 'core/inspector/ScriptArguments.h']) 97 'core/inspector/ScriptArguments.h'])
95 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') 98 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
96 if is_call_with_script_state: 99 is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', ' ThisValue')
97 includes.add('bindings/core/v8/V8ScriptState.h') 100 if is_call_with_script_state or is_call_with_this_value:
101 includes.add('bindings/core/v8/ScriptState.h')
98 is_check_security_for_node = 'CheckSecurity' in extended_attributes 102 is_check_security_for_node = 'CheckSecurity' in extended_attributes
99 if is_check_security_for_node: 103 if is_check_security_for_node:
100 includes.add('bindings/common/BindingSecurity.h') 104 includes.add('bindings/core/v8/BindingSecurity.h')
101 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s 105 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute s
102 if is_custom_element_callbacks: 106 if is_custom_element_callbacks:
103 includes.add('core/dom/custom/CustomElementProcessingStack.h') 107 includes.add('core/dom/custom/CustomElementProcessingStack.h')
104 108
105 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes 109 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes
106 110
107 is_check_security_for_frame = ( 111 is_check_security_for_frame = (
108 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and 112 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and
109 not is_do_not_check_security) 113 not is_do_not_check_security)
110 114
111 is_check_security_for_window = ( 115 is_check_security_for_window = (
112 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and 116 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and
113 not is_do_not_check_security) 117 not is_do_not_check_security)
114 118
115 is_raises_exception = 'RaisesException' in extended_attributes 119 is_raises_exception = 'RaisesException' in extended_attributes
120 is_custom_call_prologue = has_extended_attribute_value(method, 'Custom', 'Ca llPrologue')
121 is_custom_call_epilogue = has_extended_attribute_value(method, 'Custom', 'Ca llEpilogue')
122 is_post_message = 'PostMessage' in extended_attributes
123 if is_post_message:
124 includes.add('bindings/core/v8/SerializedScriptValueFactory.h')
125 includes.add('core/dom/DOMArrayBuffer.h')
126 includes.add('core/dom/MessagePort.h')
127
128 if 'LenientThis' in extended_attributes:
129 raise Exception('[LenientThis] is not supported for operations.')
116 130
117 return { 131 return {
118 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging] 132 'activity_logging_world_list': v8_utilities.activity_logging_world_list( method), # [ActivityLogging]
119 'arguments': [argument_context(interface, method, argument, index) 133 'arguments': [argument_context(interface, method, argument, index, is_vi sible=is_visible)
120 for index, argument in enumerate(arguments)], 134 for index, argument in enumerate(arguments)],
121 'argument_declarations_for_private_script': 135 'argument_declarations_for_private_script':
122 argument_declarations_for_private_script(interface, method), 136 argument_declarations_for_private_script(interface, method),
123 'conditional_string': v8_utilities.conditional_string(method), 137 'conditional_string': v8_utilities.conditional_string(method),
124 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 138 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
125 if idl_type.is_explicit_nullable else idl_type.cpp_type), 139 if idl_type.is_explicit_nullable else idl_type.cpp_type),
126 'cpp_value': this_cpp_value, 140 'cpp_value': this_cpp_value,
127 'cpp_type_initializer': idl_type.cpp_type_initializer, 141 'cpp_type_initializer': idl_type.cpp_type_initializer,
128 'custom_registration_extended_attributes': 142 'custom_registration_extended_attributes':
129 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 143 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
130 extended_attributes.iterkeys()), 144 extended_attributes.iterkeys()),
131 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 145 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
132 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 146 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
133 'function_template': function_template(), 147 'function_template': function_template(),
134 'has_custom_registration': is_static or 148 'has_custom_registration':
149 is_static or
150 is_unforgeable(interface, method) or
135 v8_utilities.has_extended_attribute( 151 v8_utilities.has_extended_attribute(
136 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 152 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
137 'has_exception_state': 153 'has_exception_state':
138 is_raises_exception or 154 is_raises_exception or
139 is_check_security_for_frame or 155 is_check_security_for_frame or
140 is_check_security_for_window or 156 is_check_security_for_window or
141 any(argument for argument in arguments 157 any(argument for argument in arguments
142 if (argument.idl_type.name == 'SerializedScriptValue' or 158 if (argument.idl_type.name == 'SerializedScriptValue' or
143 argument_conversion_needs_exception_state(method, argument)) ), 159 argument_conversion_needs_exception_state(method, argument)) ),
144 'idl_type': idl_type.base_type, 160 'idl_type': idl_type.base_type,
145 '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'),
146 'is_call_with_script_arguments': is_call_with_script_arguments, 162 'is_call_with_script_arguments': is_call_with_script_arguments,
147 'is_call_with_script_state': is_call_with_script_state, 163 'is_call_with_script_state': is_call_with_script_state,
164 'is_call_with_this_value': is_call_with_this_value,
148 'is_check_security_for_frame': is_check_security_for_frame, 165 'is_check_security_for_frame': is_check_security_for_frame,
149 'is_check_security_for_node': is_check_security_for_node, 166 'is_check_security_for_node': is_check_security_for_node,
150 'is_check_security_for_window': is_check_security_for_window, 167 'is_check_security_for_window': is_check_security_for_window,
151 'is_custom': 'Custom' in extended_attributes, 168 'is_custom': 'Custom' in extended_attributes and
169 not (is_custom_call_prologue or is_custom_call_epilogue),
170 'is_custom_call_prologue': is_custom_call_prologue,
171 'is_custom_call_epilogue': is_custom_call_epilogue,
152 'is_custom_element_callbacks': is_custom_element_callbacks, 172 'is_custom_element_callbacks': is_custom_element_callbacks,
153 'is_do_not_check_security': is_do_not_check_security, 173 'is_do_not_check_security': is_do_not_check_security,
154 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s, 174 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
155 'is_explicit_nullable': idl_type.is_explicit_nullable, 175 'is_explicit_nullable': idl_type.is_explicit_nullable,
156 'is_implemented_in_private_script': is_implemented_in_private_script, 176 'is_implemented_in_private_script': is_implemented_in_private_script,
157 'is_partial_interface_member': 177 'is_partial_interface_member':
158 'PartialInterfaceImplementedAs' in extended_attributes, 178 'PartialInterfaceImplementedAs' in extended_attributes,
159 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 179 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
180 'is_post_message': is_post_message,
160 'is_raises_exception': is_raises_exception, 181 'is_raises_exception': is_raises_exception,
161 'is_read_only': 'Unforgeable' in extended_attributes, 182 'is_read_only': is_unforgeable(interface, method),
162 'is_static': is_static, 183 'is_static': is_static,
163 'is_variadic': arguments and arguments[-1].is_variadic, 184 'is_variadic': arguments and arguments[-1].is_variadic,
164 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] 185 'measure_as': v8_utilities.measure_as(method, interface), # [MeasureAs]
165 'name': name, 186 'name': name,
166 'number_of_arguments': len(arguments), 187 'number_of_arguments': len(arguments),
167 'number_of_required_arguments': len([ 188 'number_of_required_arguments': len([
168 argument for argument in arguments 189 argument for argument in arguments
169 if not (argument.is_optional or argument.is_variadic)]), 190 if not (argument.is_optional or argument.is_variadic)]),
170 'number_of_required_or_variadic_arguments': len([ 191 'number_of_required_or_variadic_arguments': len([
171 argument for argument in arguments 192 argument for argument in arguments
172 if not argument.is_optional]), 193 if not argument.is_optional]),
194 'on_instance': v8_utilities.on_instance(interface, method),
195 'on_interface': v8_utilities.on_interface(interface, method),
196 'on_prototype': v8_utilities.on_prototype(interface, method),
173 'only_exposed_to_private_script': is_only_exposed_to_private_script, 197 'only_exposed_to_private_script': is_only_exposed_to_private_script,
174 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled]
175 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value( 198 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value(
176 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True), 199 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', bailout_return_value='false'),
177 'property_attributes': property_attributes(method), 200 'property_attributes': property_attributes(interface, method),
201 'returns_promise': method.returns_promise,
178 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 202 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
179 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), 203 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script),
180 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', 204 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
181 'union_arguments': idl_type.union_arguments, 205 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res ult,
182 'use_local_result': use_local_result(method), 206 'use_local_result': use_local_result(method),
183 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 207 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
184 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 208 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
209 'visible': is_visible,
185 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], 210 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
186 } 211 }
187 212
188 213
189 def argument_context(interface, method, argument, index): 214 def argument_context(interface, method, argument, index, is_visible=True):
190 extended_attributes = argument.extended_attributes 215 extended_attributes = argument.extended_attributes
191 idl_type = argument.idl_type 216 idl_type = argument.idl_type
217 if is_visible:
218 idl_type.add_includes_for_type(extended_attributes)
192 this_cpp_value = cpp_value(interface, method, index) 219 this_cpp_value = cpp_value(interface, method, index)
193 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type 220 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type
194 221
222 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking]
223 has_type_checking_interface = (
224 not is_legacy_interface_type_checking(interface, method) and
225 idl_type.is_wrapper_type)
226
195 if ('ImplementedInPrivateScript' in extended_attributes and 227 if ('ImplementedInPrivateScript' in extended_attributes and
196 not idl_type.is_wrapper_type and 228 not idl_type.is_wrapper_type and
197 not idl_type.is_basic_type): 229 not idl_type.is_basic_type):
198 raise Exception('Private scripts supports only primitive types and DOM w rappers.') 230 raise Exception('Private scripts supports only primitive types and DOM w rappers.')
199 231
200 default_cpp_value = argument.default_cpp_value 232 set_default_value = argument.set_default_value
233 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es,
234 raw_type=True,
235 used_as_variadic_argument=argument.is _variadic)
201 return { 236 return {
202 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attribut es, 237 'cpp_type': (
203 raw_type=True, 238 v8_types.cpp_template_type('Nullable', this_cpp_type)
204 used_as_variadic_argument=argument.is _variadic), 239 if idl_type.is_explicit_nullable and not argument.is_variadic
240 else this_cpp_type),
205 'cpp_value': this_cpp_value, 241 'cpp_value': this_cpp_value,
206 # FIXME: check that the default value's type is compatible with the argu ment's 242 # FIXME: check that the default value's type is compatible with the argu ment's
207 'default_value': default_cpp_value, 243 'set_default_value': set_default_value,
208 'enum_validation_expression': idl_type.enum_validation_expression, 244 'enum_type': idl_type.enum_type,
245 'enum_values': idl_type.enum_values,
209 'handle': '%sHandle' % argument.name, 246 'handle': '%sHandle' % argument.name,
210 # FIXME: remove once [Default] removed and just use argument.default_val ue 247 # FIXME: remove once [Default] removed and just use argument.default_val ue
211 'has_default': 'Default' in extended_attributes or default_cpp_value, 248 'has_default': 'Default' in extended_attributes or set_default_value,
212 'has_type_checking_interface': 249 'has_type_checking_interface': has_type_checking_interface,
213 (has_extended_attribute_value(interface, 'TypeChecking', 'Interface' ) or
214 has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and
215 idl_type.is_wrapper_type,
216 'has_type_checking_unrestricted':
217 (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestrict ed') or
218 has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted' )) and
219 idl_type.name in ('Float', 'Double'),
220 # Dictionary is special-cased, but arrays and sequences shouldn't be 250 # Dictionary is special-cased, but arrays and sequences shouldn't be
221 'idl_type': idl_type.base_type, 251 'idl_type': idl_type.base_type,
222 'idl_type_object': idl_type, 252 'idl_type_object': idl_type,
223 'index': index, 253 'index': index,
254 'is_callback_function': idl_type.is_callback_function,
224 'is_callback_interface': idl_type.is_callback_interface, 255 'is_callback_interface': idl_type.is_callback_interface,
225 # FIXME: Remove generic 'Dictionary' special-casing 256 # FIXME: Remove generic 'Dictionary' special-casing
226 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio nary', 257 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictio nary',
258 'is_explicit_nullable': idl_type.is_explicit_nullable,
227 'is_nullable': idl_type.is_nullable, 259 'is_nullable': idl_type.is_nullable,
228 'is_optional': argument.is_optional, 260 'is_optional': argument.is_optional,
261 'is_variadic': argument.is_variadic,
229 'is_variadic_wrapper_type': is_variadic_wrapper_type, 262 'is_variadic_wrapper_type': is_variadic_wrapper_type,
230 'is_wrapper_type': idl_type.is_wrapper_type, 263 'is_wrapper_type': idl_type.is_wrapper_type,
231 'name': argument.name, 264 'name': argument.name,
232 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 265 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(
233 argument.name, isolate='scriptState->isolate()', 266 argument.name, isolate='scriptState->isolate()',
234 creation_context='scriptState->context()->Global()'), 267 creation_context='scriptState->context()->Global()'),
268 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in extended_attributes,
235 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 269 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
236 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 270 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
237 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, ind ex, return_promise=method.returns_promise), 271 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(method, argum ent, index),
238 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc _type),
239 } 272 }
240 273
241 274
242 def argument_declarations_for_private_script(interface, method): 275 def argument_declarations_for_private_script(interface, method):
243 argument_declarations = ['LocalFrame* frame'] 276 argument_declarations = ['LocalFrame* frame']
244 argument_declarations.append('%s* holderImpl' % interface.name) 277 argument_declarations.append('%s* holderImpl' % interface.name)
245 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( 278 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(
246 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts]) 279 used_as_rvalue_type=True), argument.name) for argument in method.argumen ts])
247 if method.idl_type.name != 'void': 280 if method.idl_type.name != 'void':
248 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu lt')) 281 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu lt'))
249 return argument_declarations 282 return argument_declarations
250 283
251 284
252 ################################################################################ 285 ################################################################################
253 # Value handling 286 # Value handling
254 ################################################################################ 287 ################################################################################
255 288
256 def cpp_value(interface, method, number_of_arguments): 289 def cpp_value(interface, method, number_of_arguments):
257 def cpp_argument(argument): 290 def cpp_argument(argument):
258 idl_type = argument.idl_type 291 idl_type = argument.idl_type
259 if idl_type.name == 'EventListener': 292 if idl_type.name == 'EventListener':
260 return argument.name 293 return argument.name
261 if idl_type.is_dictionary:
262 return '*%s' % argument.name
263 if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull', 294 if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull',
264 'XPathNSResolver', 'XPathNSResolverOrNull']): 295 'XPathNSResolver', 'XPathNSResolverOrNull']):
265 # FIXME: remove this special case 296 # FIXME: remove this special case
266 return '%s.release()' % argument.name 297 return '%s.release()' % argument.name
267 return argument.name 298 return argument.name
268 299
269 # Truncate omitted optional arguments 300 # Truncate omitted optional arguments
270 arguments = method.arguments[:number_of_arguments] 301 arguments = method.arguments[:number_of_arguments]
271 cpp_arguments = [] 302 cpp_arguments = []
272 if 'ImplementedInPrivateScript' in method.extended_attributes: 303 if 'ImplementedInPrivateScript' in method.extended_attributes:
273 cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrent Context())') 304 cpp_arguments.append('toLocalFrame(toFrameIfNotDetached(info.GetIsolate( )->GetCurrentContext()))')
274 cpp_arguments.append('impl') 305 cpp_arguments.append('impl')
275 306
276 if method.is_constructor: 307 if method.is_constructor:
277 call_with_values = interface.extended_attributes.get('ConstructorCallWit h') 308 call_with_values = interface.extended_attributes.get('ConstructorCallWit h')
278 else: 309 else:
279 call_with_values = method.extended_attributes.get('CallWith') 310 call_with_values = method.extended_attributes.get('CallWith')
280 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) 311 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values))
281 312
282 # Members of IDL partial interface definitions are implemented in C++ as 313 # Members of IDL partial interface definitions are implemented in C++ as
283 # static member functions, which for instance members (non-static members) 314 # static member functions, which for instance members (non-static members)
284 # take *impl as their first argument 315 # take *impl as their first argument
285 if ('PartialInterfaceImplementedAs' in method.extended_attributes and 316 if ('PartialInterfaceImplementedAs' in method.extended_attributes and
286 not 'ImplementedInPrivateScript' in method.extended_attributes and 317 not 'ImplementedInPrivateScript' in method.extended_attributes and
287 not method.is_static): 318 not method.is_static):
288 cpp_arguments.append('*impl') 319 cpp_arguments.append('*impl')
289 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) 320 cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
290 321
291 this_union_arguments = method.idl_type and method.idl_type.union_arguments
292 if this_union_arguments:
293 cpp_arguments.extend([member_argument['cpp_value']
294 for member_argument in this_union_arguments])
295
296 if 'ImplementedInPrivateScript' in method.extended_attributes: 322 if 'ImplementedInPrivateScript' in method.extended_attributes:
297 if method.idl_type.name != 'void': 323 if method.idl_type.name != 'void':
298 cpp_arguments.append('&result') 324 cpp_arguments.append('&result')
299 elif ('RaisesException' in method.extended_attributes or 325 elif ('RaisesException' in method.extended_attributes or
300 (method.is_constructor and 326 (method.is_constructor and
301 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))): 327 has_extended_attribute_value(interface, 'RaisesException', 'Constructor '))):
302 cpp_arguments.append('exceptionState') 328 cpp_arguments.append('exceptionState')
303 329
330 # If a method returns an IDL dictionary or union type, the return value is
331 # passed as an argument to impl classes.
332 idl_type = method.idl_type
333 if idl_type and idl_type.use_output_parameter_for_result:
334 cpp_arguments.append('result')
335
304 if method.name == 'Constructor': 336 if method.name == 'Constructor':
305 base_name = 'create' 337 base_name = 'create'
306 elif method.name == 'NamedConstructor': 338 elif method.name == 'NamedConstructor':
307 base_name = 'createForJSConstructor' 339 base_name = 'createForJSConstructor'
308 elif 'ImplementedInPrivateScript' in method.extended_attributes: 340 elif 'ImplementedInPrivateScript' in method.extended_attributes:
309 base_name = '%sMethod' % method.name 341 base_name = '%sMethod' % method.name
310 else: 342 else:
311 base_name = v8_utilities.cpp_name(method) 343 base_name = v8_utilities.cpp_name(method)
312 344
313 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) 345 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name)
(...skipping 16 matching lines...) Expand all
330 # [CallWith=ScriptState], [RaisesException] 362 # [CallWith=ScriptState], [RaisesException]
331 if use_local_result(method): 363 if use_local_result(method):
332 if idl_type.is_explicit_nullable: 364 if idl_type.is_explicit_nullable:
333 # result is of type Nullable<T> 365 # result is of type Nullable<T>
334 cpp_value = 'result.get()' 366 cpp_value = 'result.get()'
335 else: 367 else:
336 cpp_value = 'result' 368 cpp_value = 'result'
337 release = idl_type.release 369 release = idl_type.release
338 370
339 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' 371 script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
340 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world) 372 return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_w rappable=script_wrappable, release=release, for_main_world=for_main_world, is_st atic=method.is_static)
341 373
342 374
343 def v8_value_to_local_cpp_variadic_value(argument, index, return_promise): 375 def v8_value_to_local_cpp_variadic_value(method, argument, index, return_promise ):
344 assert argument.is_variadic 376 assert argument.is_variadic
345 idl_type = argument.idl_type 377 idl_type = argument.idl_type
378 this_cpp_type = idl_type.cpp_type
346 379
347 suffix = '' 380 if method.returns_promise:
381 check_expression = 'exceptionState.hadException()'
382 else:
383 check_expression = 'exceptionState.throwIfNeeded()'
348 384
349 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 385 if idl_type.is_dictionary or idl_type.is_union_type:
350 macro_args = [ 386 vector_type = 'HeapVector'
351 argument.name, 387 else:
352 'toImplArguments<%s>(info, %s, exceptionState)' % (idl_type.cpp_type, in dex), 388 vector_type = 'Vector'
353 'exceptionState',
354 ]
355 389
356 if return_promise: 390 return {
357 suffix += '_PROMISE' 391 'assign_expression': 'toImplArguments<%s<%s>>(info, %s, exceptionState)' % (vector_type, this_cpp_type, index),
358 macro_args.extend(['info', 'V8ScriptState::current(info.GetIsolate())']) 392 'check_expression': check_expression,
359 393 'cpp_type': this_cpp_type,
360 suffix += '_INTERNAL' 394 'cpp_name': argument.name,
361 395 'declare_variable': False,
362 return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) 396 }
363 397
364 398
365 def v8_value_to_local_cpp_value(argument, index, return_promise=False): 399 def v8_value_to_local_cpp_value(method, argument, index, return_promise=False, r estricted_float=False):
366 extended_attributes = argument.extended_attributes 400 extended_attributes = argument.extended_attributes
367 idl_type = argument.idl_type 401 idl_type = argument.idl_type
368 name = argument.name 402 name = argument.name
369 if argument.is_variadic: 403 if argument.is_variadic:
370 return v8_value_to_local_cpp_variadic_value(argument, index, return_prom ise) 404 return v8_value_to_local_cpp_variadic_value(method, argument, index, ret urn_promise)
371 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, 405 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index,
372 name, index=index, declare_varia ble=False, return_promise=return_promise) 406 name, index=index, declare_varia ble=False,
407 use_exception_state=method.retur ns_promise,
408 restricted_float=restricted_floa t)
373 409
374 410
375 ################################################################################ 411 ################################################################################
376 # Auxiliary functions 412 # Auxiliary functions
377 ################################################################################ 413 ################################################################################
378 414
379 # [NotEnumerable] 415 # [NotEnumerable]
380 def property_attributes(method): 416 def property_attributes(interface, method):
381 extended_attributes = method.extended_attributes 417 extended_attributes = method.extended_attributes
382 property_attributes_list = [] 418 property_attributes_list = []
383 if 'NotEnumerable' in extended_attributes: 419 if 'NotEnumerable' in extended_attributes:
384 property_attributes_list.append('v8::DontEnum') 420 property_attributes_list.append('v8::DontEnum')
385 if 'Unforgeable' in extended_attributes: 421 if is_unforgeable(interface, method):
386 property_attributes_list.append('v8::ReadOnly') 422 property_attributes_list.append('v8::ReadOnly')
387 if property_attributes_list: 423 if property_attributes_list:
388 property_attributes_list.insert(0, 'v8::DontDelete') 424 property_attributes_list.insert(0, 'v8::DontDelete')
389 return property_attributes_list 425 return property_attributes_list
390 426
391 427
392 def union_member_argument_context(idl_type, index): 428 def argument_set_default_value(argument):
393 """Returns a context of union member for argument.""" 429 idl_type = argument.idl_type
394 this_cpp_value = 'result%d' % index 430 default_value = argument.default_value
395 this_cpp_type = idl_type.cpp_type 431 if not default_value:
396 this_cpp_type_initializer = idl_type.cpp_type_initializer 432 return None
397 cpp_return_value = this_cpp_value 433 if idl_type.is_dictionary:
434 if not argument.default_value.is_null:
435 raise Exception('invalid default value for dictionary type')
436 return None
437 if idl_type.is_array_or_sequence_type:
438 if default_value.value != '[]':
439 raise Exception('invalid default value for sequence type: %s' % defa ult_value.value)
440 # Nothing to do when we set an empty sequence as default value, but we
441 # need to return non-empty value so that we don't generate method calls
442 # without this argument.
443 return '/* Nothing to do */'
444 if idl_type.is_union_type:
445 if argument.default_value.is_null:
446 if not idl_type.includes_nullable_type:
447 raise Exception('invalid default value for union type: null for %s'
448 % idl_type.name)
449 # Union container objects are "null" initially.
450 return '/* null default value */'
451 if isinstance(default_value.value, basestring):
452 member_type = idl_type.string_member_type
453 elif isinstance(default_value.value, (int, float)):
454 member_type = idl_type.numeric_member_type
455 elif isinstance(default_value.value, bool):
456 member_type = idl_type.boolean_member_type
457 else:
458 member_type = None
459 if member_type is None:
460 raise Exception('invalid default value for union type: %r for %s'
461 % (default_value.value, idl_type.name))
462 member_type_name = (member_type.inner_type.name
463 if member_type.is_nullable else
464 member_type.name)
465 return '%s.set%s(%s)' % (argument.name, member_type_name,
466 member_type.literal_cpp_value(default_value))
467 return '%s = %s' % (argument.name,
468 idl_type.literal_cpp_value(default_value))
398 469
399 if not idl_type.cpp_type_has_null_value: 470 IdlArgument.set_default_value = property(argument_set_default_value)
400 this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type)
401 this_cpp_type_initializer = ''
402 cpp_return_value = '%s.get()' % this_cpp_value
403
404 if idl_type.is_string_type:
405 null_check_value = '!%s.isNull()' % this_cpp_value
406 else:
407 null_check_value = this_cpp_value
408
409 return {
410 'cpp_type': this_cpp_type,
411 'cpp_type_initializer': this_cpp_type_initializer,
412 'cpp_value': this_cpp_value,
413 'null_check_value': null_check_value,
414 'v8_set_return_value': idl_type.v8_set_return_value(
415 cpp_value=cpp_return_value,
416 release=idl_type.release),
417 }
418
419
420 def union_arguments(idl_type):
421 return [union_member_argument_context(member_idl_type, index)
422 for index, member_idl_type
423 in enumerate(idl_type.member_types)]
424
425
426 def argument_default_cpp_value(argument):
427 if argument.idl_type.is_dictionary:
428 # We always create impl objects for IDL dictionaries.
429 return '%s::create()' % argument.idl_type.base_type
430 if not argument.default_value:
431 return None
432 return argument.idl_type.literal_cpp_value(argument.default_value)
433
434 IdlTypeBase.union_arguments = None
435 IdlUnionType.union_arguments = property(union_arguments)
436 IdlArgument.default_cpp_value = property(argument_default_cpp_value)
437 471
438 472
439 def method_returns_promise(method): 473 def method_returns_promise(method):
440 return method.idl_type and method.idl_type.name == 'Promise' 474 return method.idl_type and method.idl_type.name == 'Promise'
441 475
442 IdlOperation.returns_promise = property(method_returns_promise) 476 IdlOperation.returns_promise = property(method_returns_promise)
443 477
444 478
445 def argument_conversion_needs_exception_state(method, argument): 479 def argument_conversion_needs_exception_state(method, argument):
446 idl_type = argument.idl_type 480 idl_type = argument.idl_type
447 return (idl_type.v8_conversion_needs_exception_state or 481 return (idl_type.v8_conversion_needs_exception_state or
448 argument.is_variadic or 482 argument.is_variadic or
449 (method.returns_promise and (idl_type.is_string_type or 483 (method.returns_promise and idl_type.is_string_type))
450 idl_type.is_enum)))
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