OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 import v8_utilities | 41 import v8_utilities |
42 from v8_utilities import (has_extended_attribute_value, is_unforgeable, | 42 from v8_utilities import (has_extended_attribute_value, is_unforgeable, |
43 is_legacy_interface_type_checking) | 43 is_legacy_interface_type_checking) |
44 | 44 |
45 | 45 |
46 # 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 |
47 # interface's configure*Template() function. | 47 # interface's configure*Template() function. |
48 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ | 48 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ |
49 'DoNotCheckSecurity', | 49 'DoNotCheckSecurity', |
50 'DoNotCheckSignature', | 50 'DoNotCheckSignature', |
51 'NotEnumerable', | |
52 'Unforgeable', | |
53 ]) | 51 ]) |
54 | 52 |
55 | 53 |
56 def use_local_result(method): | 54 def use_local_result(method): |
57 extended_attributes = method.extended_attributes | 55 extended_attributes = method.extended_attributes |
58 idl_type = method.idl_type | 56 idl_type = method.idl_type |
59 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or | 57 return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or |
60 'ImplementedInPrivateScript' in extended_attributes or | 58 'ImplementedInPrivateScript' in extended_attributes or |
61 'RaisesException' in extended_attributes or | 59 'RaisesException' in extended_attributes or |
62 idl_type.is_union_type or | 60 idl_type.is_union_type or |
63 idl_type.is_explicit_nullable) | 61 idl_type.is_explicit_nullable) |
64 | 62 |
65 | 63 |
66 def method_context(interface, method, is_visible=True): | 64 def method_context(interface, method, is_visible=True): |
67 arguments = method.arguments | 65 arguments = method.arguments |
68 extended_attributes = method.extended_attributes | 66 extended_attributes = method.extended_attributes |
69 idl_type = method.idl_type | 67 idl_type = method.idl_type |
70 is_static = method.is_static | 68 is_static = method.is_static |
71 name = method.name | 69 name = method.name |
72 | 70 |
73 if is_visible: | 71 if is_visible: |
74 idl_type.add_includes_for_type(extended_attributes) | 72 idl_type.add_includes_for_type(extended_attributes) |
75 | 73 |
76 this_cpp_value = cpp_value(interface, method, len(arguments)) | 74 this_cpp_value = cpp_value(interface, method, len(arguments)) |
77 | 75 |
78 def function_template(): | |
79 if is_static: | |
80 return 'functionTemplate' | |
81 if is_unforgeable(interface, method): | |
82 return 'instanceTemplate' | |
83 return 'prototypeTemplate' | |
84 | |
85 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes | 76 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_
attributes |
86 if is_implemented_in_private_script: | 77 if is_implemented_in_private_script: |
87 includes.add('bindings/core/v8/PrivateScriptRunner.h') | 78 includes.add('bindings/core/v8/PrivateScriptRunner.h') |
88 includes.add('core/frame/LocalFrame.h') | 79 includes.add('core/frame/LocalFrame.h') |
89 includes.add('platform/ScriptForbiddenScope.h') | 80 includes.add('platform/ScriptForbiddenScope.h') |
90 | 81 |
91 # [OnlyExposedToPrivateScript] | 82 # [OnlyExposedToPrivateScript] |
92 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes | 83 is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended
_attributes |
93 | 84 |
94 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi
th', 'ScriptArguments') | 85 is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWi
th', 'ScriptArguments') |
95 if is_call_with_script_arguments: | 86 if is_call_with_script_arguments: |
96 includes.update(['bindings/core/v8/ScriptCallStackFactory.h', | 87 includes.update(['bindings/core/v8/ScriptCallStack.h', |
97 'core/inspector/ScriptArguments.h']) | 88 'core/inspector/ScriptArguments.h']) |
98 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith',
'ScriptState') | 89 is_call_with_script_state = has_extended_attribute_value(method, 'CallWith',
'ScriptState') |
99 is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', '
ThisValue') | 90 is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', '
ThisValue') |
100 if is_call_with_script_state or is_call_with_this_value: | 91 if is_call_with_script_state or is_call_with_this_value: |
101 includes.add('bindings/core/v8/ScriptState.h') | 92 includes.add('bindings/core/v8/ScriptState.h') |
102 is_check_security_for_node = 'CheckSecurity' in extended_attributes | 93 |
103 if is_check_security_for_node: | 94 # [CheckSecurity] |
| 95 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes |
| 96 is_check_security_for_receiver = ( |
| 97 has_extended_attribute_value(interface, 'CheckSecurity', 'Receiver') and |
| 98 not is_do_not_check_security) |
| 99 is_check_security_for_return_value = ( |
| 100 has_extended_attribute_value(method, 'CheckSecurity', 'ReturnValue')) |
| 101 if is_check_security_for_receiver or is_check_security_for_return_value: |
104 includes.add('bindings/core/v8/BindingSecurity.h') | 102 includes.add('bindings/core/v8/BindingSecurity.h') |
| 103 |
105 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s | 104 is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attribute
s |
106 if is_custom_element_callbacks: | 105 if is_custom_element_callbacks: |
107 includes.add('core/dom/custom/CustomElementProcessingStack.h') | 106 includes.add('core/dom/custom/CustomElementProcessingStack.h') |
108 | 107 |
109 is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes | |
110 | |
111 is_check_security_for_frame = ( | |
112 has_extended_attribute_value(interface, 'CheckSecurity', 'Frame') and | |
113 not is_do_not_check_security) | |
114 | |
115 is_check_security_for_window = ( | |
116 has_extended_attribute_value(interface, 'CheckSecurity', 'Window') and | |
117 not is_do_not_check_security) | |
118 | |
119 is_raises_exception = 'RaisesException' in extended_attributes | 108 is_raises_exception = 'RaisesException' in extended_attributes |
120 is_custom_call_prologue = has_extended_attribute_value(method, 'Custom', 'Ca
llPrologue') | 109 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') | 110 is_custom_call_epilogue = has_extended_attribute_value(method, 'Custom', 'Ca
llEpilogue') |
122 is_post_message = 'PostMessage' in extended_attributes | 111 is_post_message = 'PostMessage' in extended_attributes |
123 if is_post_message: | 112 if is_post_message: |
124 includes.add('bindings/core/v8/SerializedScriptValueFactory.h') | 113 includes.add('bindings/core/v8/SerializedScriptValueFactory.h') |
125 includes.add('core/dom/DOMArrayBuffer.h') | 114 includes.add('core/dom/DOMArrayBuffer.h') |
126 includes.add('core/dom/MessagePort.h') | 115 includes.add('core/dom/MessagePort.h') |
| 116 includes.add('core/frame/ImageBitmap.h') |
127 | 117 |
128 if 'LenientThis' in extended_attributes: | 118 if 'LenientThis' in extended_attributes: |
129 raise Exception('[LenientThis] is not supported for operations.') | 119 raise Exception('[LenientThis] is not supported for operations.') |
130 | 120 |
| 121 if 'RuntimeEnabled' in extended_attributes: |
| 122 includes.add('platform/RuntimeEnabledFeatures.h') |
| 123 |
| 124 if 'OriginTrialEnabled' in extended_attributes: |
| 125 includes.add('core/inspector/ConsoleMessage.h') |
| 126 includes.add('core/origin_trials/OriginTrials.h') |
| 127 |
| 128 argument_contexts = [ |
| 129 argument_context(interface, method, argument, index, is_visible=is_visib
le) |
| 130 for index, argument in enumerate(arguments)] |
| 131 |
131 return { | 132 return { |
132 '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] |
133 'arguments': [argument_context(interface, method, argument, index, is_vi
sible=is_visible) | 134 'arguments': argument_contexts, |
134 for index, argument in enumerate(arguments)], | |
135 'argument_declarations_for_private_script': | 135 'argument_declarations_for_private_script': |
136 argument_declarations_for_private_script(interface, method), | 136 argument_declarations_for_private_script(interface, method), |
137 'conditional_string': v8_utilities.conditional_string(method), | |
138 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) | 137 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) |
139 if idl_type.is_explicit_nullable else idl_type.cpp_type), | 138 if idl_type.is_explicit_nullable else idl_type.cpp_type), |
140 'cpp_value': this_cpp_value, | 139 'cpp_value': this_cpp_value, |
141 'cpp_type_initializer': idl_type.cpp_type_initializer, | 140 'cpp_type_initializer': idl_type.cpp_type_initializer, |
142 'custom_registration_extended_attributes': | 141 'custom_registration_extended_attributes': |
143 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( | 142 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( |
144 extended_attributes.iterkeys()), | 143 extended_attributes.iterkeys()), |
145 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] | 144 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] |
146 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] | 145 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] |
147 'function_template': function_template(), | 146 # TODO(yukishiino): Retire has_custom_registration flag. Should be |
| 147 # replaced with V8DOMConfiguration::PropertyLocationConfiguration. |
148 'has_custom_registration': | 148 'has_custom_registration': |
149 is_static or | |
150 is_unforgeable(interface, method) or | |
151 v8_utilities.has_extended_attribute( | 149 v8_utilities.has_extended_attribute( |
152 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), | 150 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), |
153 'has_exception_state': | 151 'has_exception_state': |
154 is_raises_exception or | 152 is_raises_exception or |
155 is_check_security_for_frame or | 153 is_check_security_for_receiver or |
156 is_check_security_for_window or | |
157 any(argument for argument in arguments | 154 any(argument for argument in arguments |
158 if (argument.idl_type.name == 'SerializedScriptValue' or | 155 if (argument.idl_type.name == 'SerializedScriptValue' or |
159 argument_conversion_needs_exception_state(method, argument))
), | 156 argument_conversion_needs_exception_state(method, argument))
), |
| 157 'has_optional_argument_without_default_value': |
| 158 any(True for argument_context in argument_contexts |
| 159 if argument_context['is_optional_without_default_value']), |
160 'idl_type': idl_type.base_type, | 160 'idl_type': idl_type.base_type, |
| 161 'is_origin_trial_enabled': v8_utilities.origin_trial_enabled_function(me
thod) or v8_utilities.origin_trial_enabled_function(interface), # [OriginTrialE
nabled] |
161 'is_call_with_execution_context': has_extended_attribute_value(method, '
CallWith', 'ExecutionContext'), | 162 'is_call_with_execution_context': has_extended_attribute_value(method, '
CallWith', 'ExecutionContext'), |
162 'is_call_with_script_arguments': is_call_with_script_arguments, | 163 'is_call_with_script_arguments': is_call_with_script_arguments, |
163 'is_call_with_script_state': is_call_with_script_state, | 164 'is_call_with_script_state': is_call_with_script_state, |
164 'is_call_with_this_value': is_call_with_this_value, | 165 'is_call_with_this_value': is_call_with_this_value, |
165 'is_check_security_for_frame': is_check_security_for_frame, | 166 'is_check_security_for_receiver': is_check_security_for_receiver, |
166 'is_check_security_for_node': is_check_security_for_node, | 167 'is_check_security_for_return_value': is_check_security_for_return_value
, |
167 'is_check_security_for_window': is_check_security_for_window, | |
168 'is_custom': 'Custom' in extended_attributes and | 168 'is_custom': 'Custom' in extended_attributes and |
169 not (is_custom_call_prologue or is_custom_call_epilogue), | 169 not (is_custom_call_prologue or is_custom_call_epilogue), |
170 'is_custom_call_prologue': is_custom_call_prologue, | 170 'is_custom_call_prologue': is_custom_call_prologue, |
171 'is_custom_call_epilogue': is_custom_call_epilogue, | 171 'is_custom_call_epilogue': is_custom_call_epilogue, |
172 'is_custom_element_callbacks': is_custom_element_callbacks, | 172 'is_custom_element_callbacks': is_custom_element_callbacks, |
173 'is_do_not_check_security': is_do_not_check_security, | 173 'is_do_not_check_security': is_do_not_check_security, |
174 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute
s, | 174 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute
s, |
175 'is_explicit_nullable': idl_type.is_explicit_nullable, | 175 'is_explicit_nullable': idl_type.is_explicit_nullable, |
176 'is_implemented_in_private_script': is_implemented_in_private_script, | 176 'is_implemented_in_private_script': is_implemented_in_private_script, |
177 'is_partial_interface_member': | 177 'is_partial_interface_member': |
178 'PartialInterfaceImplementedAs' in extended_attributes, | 178 'PartialInterfaceImplementedAs' in extended_attributes, |
179 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, | 179 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, |
180 'is_post_message': is_post_message, | 180 'is_post_message': is_post_message, |
181 'is_raises_exception': is_raises_exception, | 181 'is_raises_exception': is_raises_exception, |
182 'is_read_only': is_unforgeable(interface, method), | |
183 'is_static': is_static, | 182 'is_static': is_static, |
| 183 'is_unforgeable': is_unforgeable(interface, method), |
184 'is_variadic': arguments and arguments[-1].is_variadic, | 184 'is_variadic': arguments and arguments[-1].is_variadic, |
185 'measure_as': v8_utilities.measure_as(method, interface), # [MeasureAs] | 185 'measure_as': v8_utilities.measure_as(method, interface), # [MeasureAs] |
186 'name': name, | 186 'name': name, |
187 'number_of_arguments': len(arguments), | 187 'number_of_arguments': len(arguments), |
188 'number_of_required_arguments': len([ | 188 'number_of_required_arguments': len([ |
189 argument for argument in arguments | 189 argument for argument in arguments |
190 if not (argument.is_optional or argument.is_variadic)]), | 190 if not (argument.is_optional or argument.is_variadic)]), |
191 'number_of_required_or_variadic_arguments': len([ | 191 'number_of_required_or_variadic_arguments': len([ |
192 argument for argument in arguments | 192 argument for argument in arguments |
193 if not argument.is_optional]), | 193 if not argument.is_optional]), |
194 'on_instance': v8_utilities.on_instance(interface, method), | 194 'on_instance': v8_utilities.on_instance(interface, method), |
195 'on_interface': v8_utilities.on_interface(interface, method), | 195 'on_interface': v8_utilities.on_interface(interface, method), |
196 'on_prototype': v8_utilities.on_prototype(interface, method), | 196 'on_prototype': v8_utilities.on_prototype(interface, method), |
197 'only_exposed_to_private_script': is_only_exposed_to_private_script, | 197 'only_exposed_to_private_script': is_only_exposed_to_private_script, |
| 198 'origin_trial_enabled': v8_utilities.origin_trial_enabled_function(metho
d), # [OriginTrialEnabled] |
| 199 'origin_trial_enabled_per_interface': v8_utilities.origin_trial_enabled_
function(interface), # [OriginTrialEnabled] |
198 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( | 200 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local
_cpp_value( |
199 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is
olate()', bailout_return_value='false'), | 201 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is
olate()', bailout_return_value='false'), |
200 'property_attributes': property_attributes(interface, method), | 202 'property_attributes': property_attributes(interface, method), |
201 'returns_promise': method.returns_promise, | 203 'returns_promise': method.returns_promise, |
202 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] | 204 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m
ethod), # [RuntimeEnabled] |
203 'should_be_exposed_to_script': not (is_implemented_in_private_script and
is_only_exposed_to_private_script), | 205 'should_be_exposed_to_script': not (is_implemented_in_private_script and
is_only_exposed_to_private_script), |
204 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig
nature' in extended_attributes else 'defaultSignature', | |
205 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res
ult, | 206 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res
ult, |
206 'use_local_result': use_local_result(method), | 207 'use_local_result': use_local_result(method), |
207 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 208 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
208 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 209 '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, | 210 'visible': is_visible, |
210 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], | 211 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended
_attributes else [''], # [PerWorldBindings], |
211 } | 212 } |
212 | 213 |
213 | 214 |
214 def argument_context(interface, method, argument, index, is_visible=True): | 215 def argument_context(interface, method, argument, index, is_visible=True): |
215 extended_attributes = argument.extended_attributes | 216 extended_attributes = argument.extended_attributes |
216 idl_type = argument.idl_type | 217 idl_type = argument.idl_type |
217 if is_visible: | 218 if is_visible: |
218 idl_type.add_includes_for_type(extended_attributes) | 219 idl_type.add_includes_for_type(extended_attributes) |
219 this_cpp_value = cpp_value(interface, method, index) | 220 this_cpp_value = cpp_value(interface, method, index) |
220 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type | 221 is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
221 | 222 |
222 # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] | 223 # [LegacyInterfaceTypeChecking] |
223 has_type_checking_interface = ( | 224 has_type_checking_interface = ( |
224 not is_legacy_interface_type_checking(interface, method) and | 225 not is_legacy_interface_type_checking(interface, method) and |
225 idl_type.is_wrapper_type) | 226 idl_type.is_wrapper_type) |
226 | 227 |
227 if ('ImplementedInPrivateScript' in extended_attributes and | 228 if ('ImplementedInPrivateScript' in extended_attributes and |
228 not idl_type.is_wrapper_type and | 229 not idl_type.is_wrapper_type and |
229 not idl_type.is_basic_type): | 230 not idl_type.is_basic_type): |
230 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 231 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
231 | 232 |
232 set_default_value = argument.set_default_value | 233 set_default_value = argument.set_default_value |
233 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, | 234 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut
es, |
234 raw_type=True, | 235 raw_type=True, |
235 used_as_variadic_argument=argument.is
_variadic) | 236 used_as_variadic_argument=argument.is
_variadic) |
236 return { | 237 context = { |
237 'cpp_type': ( | 238 'cpp_type': ( |
238 v8_types.cpp_template_type('Nullable', this_cpp_type) | 239 v8_types.cpp_template_type('Nullable', this_cpp_type) |
239 if idl_type.is_explicit_nullable and not argument.is_variadic | 240 if idl_type.is_explicit_nullable and not argument.is_variadic |
240 else this_cpp_type), | 241 else this_cpp_type), |
241 'cpp_value': this_cpp_value, | 242 'cpp_value': this_cpp_value, |
242 # FIXME: check that the default value's type is compatible with the argu
ment's | 243 # FIXME: check that the default value's type is compatible with the argu
ment's |
243 'set_default_value': set_default_value, | 244 'set_default_value': set_default_value, |
244 'enum_type': idl_type.enum_type, | 245 'enum_type': idl_type.enum_type, |
245 'enum_values': idl_type.enum_values, | 246 'enum_values': idl_type.enum_values, |
246 'handle': '%sHandle' % argument.name, | 247 'handle': '%sHandle' % argument.name, |
(...skipping 16 matching lines...) Expand all Loading... |
263 'is_wrapper_type': idl_type.is_wrapper_type, | 264 'is_wrapper_type': idl_type.is_wrapper_type, |
264 'name': argument.name, | 265 'name': argument.name, |
265 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 266 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
266 argument.name, isolate='scriptState->isolate()', | 267 argument.name, isolate='scriptState->isolate()', |
267 creation_context='scriptState->context()->Global()'), | 268 creation_context='scriptState->context()->Global()'), |
268 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in extended_attributes, | 269 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion'
in extended_attributes, |
269 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), | 270 'v8_set_return_value': v8_set_return_value(interface.name, method, this_
cpp_value), |
270 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), | 271 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name
, method, this_cpp_value, for_main_world=True), |
271 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(method, argum
ent, index), | 272 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(method, argum
ent, index), |
272 } | 273 } |
| 274 context.update({ |
| 275 'is_optional_without_default_value': |
| 276 context['is_optional'] and |
| 277 not context['has_default'] and |
| 278 not context['is_dictionary'] and |
| 279 not context['is_callback_interface'], |
| 280 }) |
| 281 return context |
273 | 282 |
274 | 283 |
275 def argument_declarations_for_private_script(interface, method): | 284 def argument_declarations_for_private_script(interface, method): |
276 argument_declarations = ['LocalFrame* frame'] | 285 argument_declarations = ['LocalFrame* frame'] |
277 argument_declarations.append('%s* holderImpl' % interface.name) | 286 argument_declarations.append('%s* holderImpl' % interface.name) |
278 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( | 287 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args( |
279 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) | 288 used_as_rvalue_type=True), argument.name) for argument in method.argumen
ts]) |
280 if method.idl_type.name != 'void': | 289 if method.idl_type.name != 'void': |
281 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu
lt')) | 290 argument_declarations.append('%s* %s' % (method.idl_type.cpp_type, 'resu
lt')) |
282 return argument_declarations | 291 return argument_declarations |
(...skipping 24 matching lines...) Expand all Loading... |
307 if method.is_constructor: | 316 if method.is_constructor: |
308 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') | 317 call_with_values = interface.extended_attributes.get('ConstructorCallWit
h') |
309 else: | 318 else: |
310 call_with_values = method.extended_attributes.get('CallWith') | 319 call_with_values = method.extended_attributes.get('CallWith') |
311 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) | 320 cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) |
312 | 321 |
313 # Members of IDL partial interface definitions are implemented in C++ as | 322 # Members of IDL partial interface definitions are implemented in C++ as |
314 # static member functions, which for instance members (non-static members) | 323 # static member functions, which for instance members (non-static members) |
315 # take *impl as their first argument | 324 # take *impl as their first argument |
316 if ('PartialInterfaceImplementedAs' in method.extended_attributes and | 325 if ('PartialInterfaceImplementedAs' in method.extended_attributes and |
317 not 'ImplementedInPrivateScript' in method.extended_attributes and | 326 'ImplementedInPrivateScript' not in method.extended_attributes and |
318 not method.is_static): | 327 not method.is_static): |
319 cpp_arguments.append('*impl') | 328 cpp_arguments.append('*impl') |
320 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) | 329 cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
321 | 330 |
322 if 'ImplementedInPrivateScript' in method.extended_attributes: | 331 if 'ImplementedInPrivateScript' in method.extended_attributes: |
323 if method.idl_type.name != 'void': | 332 if method.idl_type.name != 'void': |
324 cpp_arguments.append('&result') | 333 cpp_arguments.append('&result') |
325 elif ('RaisesException' in method.extended_attributes or | 334 elif ('RaisesException' in method.extended_attributes or |
326 (method.is_constructor and | 335 (method.is_constructor and |
327 has_extended_attribute_value(interface, 'RaisesException', 'Constructor
'))): | 336 has_extended_attribute_value(interface, 'RaisesException', 'Construct
or'))): |
328 cpp_arguments.append('exceptionState') | 337 cpp_arguments.append('exceptionState') |
329 | 338 |
330 # If a method returns an IDL dictionary or union type, the return value is | 339 # If a method returns an IDL dictionary or union type, the return value is |
331 # passed as an argument to impl classes. | 340 # passed as an argument to impl classes. |
332 idl_type = method.idl_type | 341 idl_type = method.idl_type |
333 if idl_type and idl_type.use_output_parameter_for_result: | 342 if idl_type and idl_type.use_output_parameter_for_result: |
334 cpp_arguments.append('result') | 343 cpp_arguments.append('result') |
335 | 344 |
336 if method.name == 'Constructor': | 345 if method.name == 'Constructor': |
337 base_name = 'create' | 346 base_name = 'create' |
338 elif method.name == 'NamedConstructor': | 347 elif method.name == 'NamedConstructor': |
339 base_name = 'createForJSConstructor' | 348 base_name = 'createForJSConstructor' |
340 elif 'ImplementedInPrivateScript' in method.extended_attributes: | 349 elif 'ImplementedInPrivateScript' in method.extended_attributes: |
341 base_name = '%sMethod' % method.name | 350 base_name = '%sMethod' % method.name |
342 else: | 351 else: |
343 base_name = v8_utilities.cpp_name(method) | 352 base_name = v8_utilities.cpp_name(method) |
344 | 353 |
345 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) | 354 cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) |
346 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) | 355 return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) |
347 | 356 |
348 | 357 |
349 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: | 358 def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False)
: |
350 idl_type = method.idl_type | 359 idl_type = method.idl_type |
351 extended_attributes = method.extended_attributes | 360 extended_attributes = method.extended_attributes |
352 if not idl_type or idl_type.name == 'void': | 361 if not idl_type or idl_type.name == 'void': |
353 # Constructors and void methods don't have a return type | 362 # Constructors and void methods don't have a return type |
354 return None | 363 return None |
355 | 364 |
356 if ('ImplementedInPrivateScript' in extended_attributes and | 365 if ('ImplementedInPrivateScript' in extended_attributes and |
357 not idl_type.is_wrapper_type and | 366 not idl_type.is_wrapper_type and |
358 not idl_type.is_basic_type): | 367 not idl_type.is_basic_type): |
359 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') | 368 raise Exception('Private scripts supports only primitive types and DOM w
rappers.') |
360 | 369 |
361 release = False | 370 release = False |
362 # [CallWith=ScriptState], [RaisesException] | 371 # [CallWith=ScriptState], [RaisesException] |
363 if use_local_result(method): | 372 if use_local_result(method): |
364 if idl_type.is_explicit_nullable: | 373 if idl_type.is_explicit_nullable: |
365 # result is of type Nullable<T> | 374 # result is of type Nullable<T> |
366 cpp_value = 'result.get()' | 375 cpp_value = 'result.get()' |
367 else: | 376 else: |
368 cpp_value = 'result' | 377 cpp_value = 'result' |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, | 414 return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]'
% index, |
406 name, index=index, declare_varia
ble=False, | 415 name, index=index, declare_varia
ble=False, |
407 use_exception_state=method.retur
ns_promise, | 416 use_exception_state=method.retur
ns_promise, |
408 restricted_float=restricted_floa
t) | 417 restricted_float=restricted_floa
t) |
409 | 418 |
410 | 419 |
411 ################################################################################ | 420 ################################################################################ |
412 # Auxiliary functions | 421 # Auxiliary functions |
413 ################################################################################ | 422 ################################################################################ |
414 | 423 |
415 # [NotEnumerable] | 424 # [NotEnumerable], [Unforgeable] |
416 def property_attributes(interface, method): | 425 def property_attributes(interface, method): |
417 extended_attributes = method.extended_attributes | 426 extended_attributes = method.extended_attributes |
418 property_attributes_list = [] | 427 property_attributes_list = [] |
419 if 'NotEnumerable' in extended_attributes: | 428 if 'NotEnumerable' in extended_attributes: |
420 property_attributes_list.append('v8::DontEnum') | 429 property_attributes_list.append('v8::DontEnum') |
421 if is_unforgeable(interface, method): | 430 if is_unforgeable(interface, method): |
422 property_attributes_list.append('v8::ReadOnly') | 431 property_attributes_list.append('v8::ReadOnly') |
423 if property_attributes_list: | 432 property_attributes_list.append('v8::DontDelete') |
424 property_attributes_list.insert(0, 'v8::DontDelete') | |
425 return property_attributes_list | 433 return property_attributes_list |
426 | 434 |
427 | 435 |
428 def argument_set_default_value(argument): | 436 def argument_set_default_value(argument): |
429 idl_type = argument.idl_type | 437 idl_type = argument.idl_type |
430 default_value = argument.default_value | 438 default_value = argument.default_value |
431 if not default_value: | 439 if not default_value: |
432 return None | 440 return None |
433 if idl_type.is_dictionary: | 441 if idl_type.is_dictionary: |
434 if not argument.default_value.is_null: | 442 if not argument.default_value.is_null: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return method.idl_type and method.idl_type.name == 'Promise' | 482 return method.idl_type and method.idl_type.name == 'Promise' |
475 | 483 |
476 IdlOperation.returns_promise = property(method_returns_promise) | 484 IdlOperation.returns_promise = property(method_returns_promise) |
477 | 485 |
478 | 486 |
479 def argument_conversion_needs_exception_state(method, argument): | 487 def argument_conversion_needs_exception_state(method, argument): |
480 idl_type = argument.idl_type | 488 idl_type = argument.idl_type |
481 return (idl_type.v8_conversion_needs_exception_state or | 489 return (idl_type.v8_conversion_needs_exception_state or |
482 argument.is_variadic or | 490 argument.is_variadic or |
483 (method.returns_promise and idl_type.is_string_type)) | 491 (method.returns_promise and idl_type.is_string_type)) |
OLD | NEW |