| 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/ScopedPersistent.h', | 14 'bindings/core/v8/ScopedPersistent.h', |
| 15 'platform/heap/Handle.h', | 15 'platform/heap/Handle.h', |
| 16 'wtf/text/WTFString.h', | 16 'wtf/text/WTFString.h', |
| 17 ]) | 17 ]) |
| 18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ | 18 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ |
| 19 'bindings/core/v8/ExceptionState.h', |
| 19 'bindings/core/v8/ScriptState.h', | 20 'bindings/core/v8/ScriptState.h', |
| 21 'bindings/core/v8/ToV8.h', |
| 20 'bindings/core/v8/V8Binding.h', | 22 'bindings/core/v8/V8Binding.h', |
| 21 'wtf/Assertions.h', | 23 'wtf/Assertions.h', |
| 22 ]) | 24 ]) |
| 23 | 25 |
| 24 | 26 |
| 25 def callback_function_context(callback_function): | 27 def callback_function_context(callback_function): |
| 26 includes.clear() | 28 includes.clear() |
| 27 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) | 29 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) |
| 28 idl_type = callback_function.idl_type | 30 idl_type = callback_function.idl_type |
| 29 idl_type_str = str(idl_type) | 31 idl_type_str = str(idl_type) |
| 32 |
| 30 context = { | 33 context = { |
| 31 'cpp_class': callback_function.name, | 34 'cpp_class': callback_function.name, |
| 32 'cpp_includes': sorted(CALLBACK_FUNCTION_CPP_INCLUDES), | 35 'cpp_includes': sorted(CALLBACK_FUNCTION_CPP_INCLUDES), |
| 33 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES), | 36 'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES), |
| 34 'idl_type': idl_type_str, | 37 'idl_type': idl_type_str, |
| 35 'return_cpp_type': (idl_type.cpp_type + '&') if idl_type.cpp_type != 'vo
id' else None, | |
| 36 'return_value': idl_type.v8_value_to_local_cpp_value( | |
| 37 callback_function.extended_attributes, 'v8ReturnValue', 'cppValue', | |
| 38 bailout_return_value="false") if idl_type.cpp_type != 'void' else No
ne, | |
| 39 'v8_class': v8_utilities.v8_class_name(callback_function), | 38 'v8_class': v8_utilities.v8_class_name(callback_function), |
| 40 } | 39 } |
| 41 context.update(arguments_context(callback_function.arguments, context['retur
n_cpp_type'])) | 40 |
| 41 if idl_type_str != 'void': |
| 42 context.update({ |
| 43 'return_cpp_type': idl_type.cpp_type + '&', |
| 44 'return_value': idl_type.v8_value_to_local_cpp_value( |
| 45 callback_function.extended_attributes, |
| 46 'v8ReturnValue', 'cppValue', |
| 47 isolate='scriptState->isolate()', bailout_return_value='false'), |
| 48 }) |
| 49 |
| 50 context.update(arguments_context(callback_function.arguments, context.get('r
eturn_cpp_type'))) |
| 42 return context | 51 return context |
| 43 | 52 |
| 44 | 53 |
| 45 def arguments_context(arguments, return_cpp_type): | 54 def arguments_context(arguments, return_cpp_type): |
| 46 def argument_context(argument): | 55 def argument_context(argument): |
| 47 return { | 56 return { |
| 48 'argument_name': '%sArgument' % argument.name, | 57 'argument_name': '%sArgument' % argument.name, |
| 49 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( | 58 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( |
| 50 argument.name, isolate='scriptState->isolate()', | 59 argument.name, isolate='scriptState->isolate()', |
| 51 creation_context='scriptState->context()->Global()'), | 60 creation_context='scriptState->context()->Global()'), |
| 52 } | 61 } |
| 53 | 62 |
| 54 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip
tWrappable'] | 63 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip
tWrappable'] |
| 55 argument_declarations.extend( | 64 argument_declarations.extend( |
| 56 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) | 65 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) |
| 57 for argument in arguments) | 66 for argument in arguments) |
| 58 if return_cpp_type: | 67 if return_cpp_type: |
| 59 argument_declarations.append('%s returnValue' % return_cpp_type) | 68 argument_declarations.append('%s returnValue' % return_cpp_type) |
| 60 return { | 69 return { |
| 61 'argument_declarations': argument_declarations, | 70 'argument_declarations': argument_declarations, |
| 62 'arguments': [argument_context(argument) for argument in arguments], | 71 'arguments': [argument_context(argument) for argument in arguments], |
| 63 } | 72 } |
| OLD | NEW |