| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generate template values for a callback function. | 5 """Generate template values for a callback function. |
| 6 | 6 |
| 7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 from v8_globals import includes # pylint: disable=W0403 | 10 from v8_globals import includes # pylint: disable=W0403 |
| 11 import v8_utilities # pylint: disable=W0403 | 11 import v8_utilities # pylint: disable=W0403 |
| 12 | 12 |
| 13 CALLBACK_FUNCTION_H_INCLUDES = frozenset([ | 13 CALLBACK_FUNCTION_H_INCLUDES = frozenset([ |
| 14 'bindings/core/v8/ExceptionState.h', |
| 14 'bindings/core/v8/ScopedPersistent.h', | 15 'bindings/core/v8/ScopedPersistent.h', |
| 15 'platform/heap/Handle.h', | 16 'platform/heap/Handle.h', |
| 16 'wtf/text/WTFString.h', | 17 'wtf/text/WTFString.h', |
| 17 ]) | 18 ]) |
| 18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ | 19 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ |
| 19 'bindings/core/v8/ScriptState.h', | 20 'bindings/core/v8/ScriptState.h', |
| 20 'bindings/core/v8/ToV8.h', | 21 'bindings/core/v8/ToV8.h', |
| 21 'bindings/core/v8/V8Binding.h', | 22 'bindings/core/v8/V8Binding.h', |
| 22 'wtf/Assertions.h', | 23 'wtf/Assertions.h', |
| 23 ]) | 24 ]) |
| 24 | 25 |
| 25 | 26 |
| 26 def callback_function_context(callback_function): | 27 def callback_function_context(callback_function): |
| 27 includes.clear() | 28 includes.clear() |
| 28 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) | 29 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) |
| 29 idl_type = callback_function.idl_type | 30 idl_type = callback_function.idl_type |
| 30 idl_type_str = str(idl_type) | 31 idl_type_str = str(idl_type) |
| 31 forward_declarations = [] | 32 forward_declarations = [] |
| 32 for argument in callback_function.arguments: | 33 for argument in callback_function.arguments: |
| 33 if argument.idl_type.is_interface_type: | 34 if argument.idl_type.is_interface_type: |
| 34 forward_declarations.append(argument.idl_type) | 35 forward_declarations.append(argument.idl_type) |
| 35 argument.idl_type.add_includes_for_type(callback_function.extended_attri
butes) | 36 argument.idl_type.add_includes_for_type(callback_function.extended_attri
butes) |
| 37 |
| 36 context = { | 38 context = { |
| 37 'cpp_class': callback_function.name, | 39 'cpp_class': callback_function.name, |
| 38 'cpp_includes': sorted(includes), | 40 'cpp_includes': sorted(includes), |
| 39 'forward_declarations': sorted(forward_declarations), | 41 'forward_declarations': sorted(forward_declarations), |
| 40 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES), | 42 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES), |
| 41 'idl_type': idl_type_str, | 43 'idl_type': idl_type_str, |
| 42 'return_cpp_type': (idl_type.cpp_type + '&') if idl_type.cpp_type != 'vo
id' else None, | |
| 43 'return_value': idl_type.v8_value_to_local_cpp_value( | |
| 44 callback_function.extended_attributes, 'v8ReturnValue', 'cppValue', | |
| 45 bailout_return_value="false") if idl_type.cpp_type != 'void' else No
ne, | |
| 46 'v8_class': v8_utilities.v8_class_name(callback_function), | 44 'v8_class': v8_utilities.v8_class_name(callback_function), |
| 47 } | 45 } |
| 48 context.update(arguments_context(callback_function.arguments, context['retur
n_cpp_type'])) | 46 |
| 47 if idl_type_str != 'void': |
| 48 context.update({ |
| 49 'return_cpp_type': idl_type.cpp_type + '&', |
| 50 'return_value': idl_type.v8_value_to_local_cpp_value( |
| 51 callback_function.extended_attributes, |
| 52 'v8ReturnValue', 'cppValue', |
| 53 isolate='scriptState->isolate()', bailout_return_value='false'), |
| 54 }) |
| 55 |
| 56 context.update(arguments_context(callback_function.arguments, context.get('r
eturn_cpp_type'))) |
| 49 return context | 57 return context |
| 50 | 58 |
| 51 | 59 |
| 52 def arguments_context(arguments, return_cpp_type): | 60 def arguments_context(arguments, return_cpp_type): |
| 53 def argument_context(argument): | 61 def argument_context(argument): |
| 54 return { | 62 return { |
| 55 'argument_name': '%sArgument' % argument.name, | 63 'argument_name': '%sArgument' % argument.name, |
| 56 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( | 64 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( |
| 57 argument.name, isolate='scriptState->isolate()', | 65 argument.name, isolate='scriptState->isolate()', |
| 58 creation_context='scriptState->context()->Global()'), | 66 creation_context='scriptState->context()->Global()'), |
| 59 } | 67 } |
| 60 | 68 |
| 61 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip
tWrappable'] | 69 argument_declarations = [ |
| 70 'ScriptState* scriptState', |
| 71 'ScriptWrappable* scriptWrappable', |
| 72 'ExceptionState& exceptionState', |
| 73 ] |
| 62 argument_declarations.extend( | 74 argument_declarations.extend( |
| 63 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) | 75 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) |
| 64 for argument in arguments) | 76 for argument in arguments) |
| 65 if return_cpp_type: | 77 if return_cpp_type: |
| 66 argument_declarations.append('%s returnValue' % return_cpp_type) | 78 argument_declarations.append('%s returnValue' % return_cpp_type) |
| 67 return { | 79 return { |
| 68 'argument_declarations': argument_declarations, | 80 'argument_declarations': argument_declarations, |
| 69 'arguments': [argument_context(argument) for argument in arguments], | 81 'arguments': [argument_context(argument) for argument in arguments], |
| 70 } | 82 } |
| OLD | NEW |