| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base_idl_type = idl_type.base_type | 179 base_idl_type = idl_type.base_type |
| 180 extended_attributes = attribute.extended_attributes | 180 extended_attributes = attribute.extended_attributes |
| 181 | 181 |
| 182 cpp_value = getter_expression(interface, attribute, context) | 182 cpp_value = getter_expression(interface, attribute, context) |
| 183 # Normally we can inline the function call into the return statement to | 183 # Normally we can inline the function call into the return statement to |
| 184 # avoid the overhead of using a Ref<> temporary, but for some cases | 184 # avoid the overhead of using a Ref<> temporary, but for some cases |
| 185 # (nullable types, EventHandler, [CachedAttribute], or if there are | 185 # (nullable types, EventHandler, [CachedAttribute], or if there are |
| 186 # exceptions), we need to use a local variable. | 186 # exceptions), we need to use a local variable. |
| 187 # FIXME: check if compilers are smart enough to inline this, and if so, | 187 # FIXME: check if compilers are smart enough to inline this, and if so, |
| 188 # always use a local variable (for readability and CG simplicity). | 188 # always use a local variable (for readability and CG simplicity). |
| 189 release = False | |
| 190 if 'ImplementedInPrivateScript' in extended_attributes: | 189 if 'ImplementedInPrivateScript' in extended_attributes: |
| 191 if (not idl_type.is_wrapper_type and | 190 if (not idl_type.is_wrapper_type and |
| 192 not idl_type.is_basic_type and | 191 not idl_type.is_basic_type and |
| 193 not idl_type.is_enum): | 192 not idl_type.is_enum): |
| 194 raise Exception('Private scripts supports only primitive types and D
OM wrappers.') | 193 raise Exception('Private scripts supports only primitive types and D
OM wrappers.') |
| 195 | 194 |
| 196 context['cpp_value_original'] = cpp_value | 195 context['cpp_value_original'] = cpp_value |
| 197 cpp_value = 'result' | 196 cpp_value = 'result' |
| 198 # EventHandler has special handling | |
| 199 if base_idl_type != 'EventHandler': | |
| 200 release = idl_type.release | |
| 201 elif (idl_type.is_explicit_nullable or | 197 elif (idl_type.is_explicit_nullable or |
| 202 base_idl_type == 'EventHandler' or | 198 base_idl_type == 'EventHandler' or |
| 203 'CachedAttribute' in extended_attributes or | 199 'CachedAttribute' in extended_attributes or |
| 204 'ReflectOnly' in extended_attributes or | 200 'ReflectOnly' in extended_attributes or |
| 205 context['is_keep_alive_for_gc'] or | 201 context['is_keep_alive_for_gc'] or |
| 206 context['is_getter_raises_exception']): | 202 context['is_getter_raises_exception']): |
| 207 context['cpp_value_original'] = cpp_value | 203 context['cpp_value_original'] = cpp_value |
| 208 cpp_value = 'cppValue' | 204 cpp_value = 'cppValue' |
| 209 # EventHandler has special handling | |
| 210 if base_idl_type != 'EventHandler': | |
| 211 release = idl_type.release | |
| 212 | 205 |
| 213 def v8_set_return_value_statement(for_main_world=False): | 206 def v8_set_return_value_statement(for_main_world=False): |
| 214 if context['is_keep_alive_for_gc'] or 'CachedAttribute' in extended_attr
ibutes: | 207 if context['is_keep_alive_for_gc'] or 'CachedAttribute' in extended_attr
ibutes: |
| 215 return 'v8SetReturnValue(info, v8Value)' | 208 return 'v8SetReturnValue(info, v8Value)' |
| 216 return idl_type.v8_set_return_value( | 209 return idl_type.v8_set_return_value( |
| 217 cpp_value, extended_attributes=extended_attributes, script_wrappable
='impl', | 210 cpp_value, extended_attributes=extended_attributes, script_wrappable
='impl', |
| 218 release=release, for_main_world=for_main_world, is_static=attribute.
is_static) | 211 for_main_world=for_main_world, is_static=attribute.is_static) |
| 219 | 212 |
| 220 context.update({ | 213 context.update({ |
| 221 'cpp_value': cpp_value, | 214 'cpp_value': cpp_value, |
| 222 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( | 215 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 223 cpp_value=cpp_value, creation_context='holder', | 216 cpp_value=cpp_value, creation_context='holder', |
| 224 extended_attributes=extended_attributes), | 217 extended_attributes=extended_attributes), |
| 225 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_
main_world=True), | 218 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_
main_world=True), |
| 226 'v8_set_return_value': v8_set_return_value_statement(), | 219 'v8_set_return_value': v8_set_return_value_statement(), |
| 227 }) | 220 }) |
| 228 | 221 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 243 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and | 236 if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and |
| 244 not 'ImplementedInPrivateScript' in attribute.extended_attributes and | 237 not 'ImplementedInPrivateScript' in attribute.extended_attributes and |
| 245 not attribute.is_static): | 238 not attribute.is_static): |
| 246 arguments.append('*impl') | 239 arguments.append('*impl') |
| 247 if attribute.idl_type.is_explicit_nullable: | 240 if attribute.idl_type.is_explicit_nullable: |
| 248 arguments.append('isNull') | 241 arguments.append('isNull') |
| 249 if context['is_getter_raises_exception']: | 242 if context['is_getter_raises_exception']: |
| 250 arguments.append('exceptionState') | 243 arguments.append('exceptionState') |
| 251 if attribute.idl_type.use_output_parameter_for_result: | 244 if attribute.idl_type.use_output_parameter_for_result: |
| 252 arguments.append('result') | 245 arguments.append('result') |
| 253 return '%s(%s)' % (getter_name, ', '.join(arguments)) | 246 |
| 247 expression = '%s(%s)' % (getter_name, ', '.join(arguments)) |
| 248 # Needed to handle getter expressions returning Type& as the |
| 249 # use site for |expression| expects Type*. |
| 250 if attribute.idl_type.is_interface_type and len(arguments) == 0: |
| 251 return 'WTF::getPtr(%s)' % expression |
| 252 return expression |
| 254 | 253 |
| 255 | 254 |
| 256 CONTENT_ATTRIBUTE_GETTER_NAMES = { | 255 CONTENT_ATTRIBUTE_GETTER_NAMES = { |
| 257 'boolean': 'fastHasAttribute', | 256 'boolean': 'fastHasAttribute', |
| 258 'long': 'getIntegralAttribute', | 257 'long': 'getIntegralAttribute', |
| 259 'unsigned long': 'getUnsignedIntegralAttribute', | 258 'unsigned long': 'getUnsignedIntegralAttribute', |
| 260 } | 259 } |
| 261 | 260 |
| 262 | 261 |
| 263 def getter_base_name(interface, attribute, arguments): | 262 def getter_base_name(interface, attribute, arguments): |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 elif idl_type.base_type == 'EventHandler': | 385 elif idl_type.base_type == 'EventHandler': |
| 387 getter_name = scoped_name(interface, attribute, cpp_name(attribute)) | 386 getter_name = scoped_name(interface, attribute, cpp_name(attribute)) |
| 388 context['event_handler_getter_expression'] = '%s(%s)' % ( | 387 context['event_handler_getter_expression'] = '%s(%s)' % ( |
| 389 getter_name, ', '.join(arguments)) | 388 getter_name, ', '.join(arguments)) |
| 390 if (interface.name in ['Window', 'WorkerGlobalScope'] and | 389 if (interface.name in ['Window', 'WorkerGlobalScope'] and |
| 391 attribute.name == 'onerror'): | 390 attribute.name == 'onerror'): |
| 392 includes.add('bindings/core/v8/V8ErrorHandler.h') | 391 includes.add('bindings/core/v8/V8ErrorHandler.h') |
| 393 arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHa
ndler>(v8Value, true, ScriptState::current(info.GetIsolate()))') | 392 arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHa
ndler>(v8Value, true, ScriptState::current(info.GetIsolate()))') |
| 394 else: | 393 else: |
| 395 arguments.append('V8EventListenerList::getEventListener(ScriptState:
:current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') | 394 arguments.append('V8EventListenerList::getEventListener(ScriptState:
:current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') |
| 396 elif idl_type.is_interface_type: | |
| 397 # FIXME: should be able to eliminate WTF::getPtr in most or all cases | |
| 398 arguments.append('WTF::getPtr(cppValue)') | |
| 399 else: | 395 else: |
| 400 arguments.append('cppValue') | 396 arguments.append('cppValue') |
| 401 if context['is_setter_raises_exception']: | 397 if context['is_setter_raises_exception']: |
| 402 arguments.append('exceptionState') | 398 arguments.append('exceptionState') |
| 403 | 399 |
| 404 return '%s(%s)' % (setter_name, ', '.join(arguments)) | 400 return '%s(%s)' % (setter_name, ', '.join(arguments)) |
| 405 | 401 |
| 406 | 402 |
| 407 CONTENT_ATTRIBUTE_SETTER_NAMES = { | 403 CONTENT_ATTRIBUTE_SETTER_NAMES = { |
| 408 'boolean': 'setBooleanAttribute', | 404 'boolean': 'setBooleanAttribute', |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 lambda self: strip_suffix(self.base_type, 'Constructor')) | 513 lambda self: strip_suffix(self.base_type, 'Constructor')) |
| 518 | 514 |
| 519 | 515 |
| 520 def is_constructor_attribute(attribute): | 516 def is_constructor_attribute(attribute): |
| 521 # FIXME: replace this with [ConstructorAttribute] extended attribute | 517 # FIXME: replace this with [ConstructorAttribute] extended attribute |
| 522 return attribute.idl_type.name.endswith('Constructor') | 518 return attribute.idl_type.name.endswith('Constructor') |
| 523 | 519 |
| 524 | 520 |
| 525 def update_constructor_attribute_context(interface, attribute, context): | 521 def update_constructor_attribute_context(interface, attribute, context): |
| 526 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] or context['origin_trial_enabled_function'] # TODO(chasej):
Should/can this be true when OriginTrialEnabled is inherited from containing in
terface? | 522 context['needs_constructor_getter_callback'] = context['measure_as'] or cont
ext['deprecate_as'] or context['origin_trial_enabled_function'] # TODO(chasej):
Should/can this be true when OriginTrialEnabled is inherited from containing in
terface? |
| OLD | NEW |