Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Generate template values for a callback function. | |
| 6 | |
| 7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | |
| 8 """ | |
| 9 | |
| 10 from v8_globals import includes | |
| 11 import v8_types | |
| 12 import v8_utilities | |
| 13 | |
| 14 CALLBACK_FUNCTION_H_INCLUDES = frozenset([ | |
| 15 'bindings/core/v8/ScopedPersistent.h', | |
| 16 'platform/heap/Handle.h', | |
| 17 'wtf/text/WTFString.h', | |
| 18 ]) | |
| 19 CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ | |
| 20 'bindings/core/v8/ScriptState.h', | |
| 21 'bindings/core/v8/V8Binding.h', | |
| 22 'wtf/Assertions.h', | |
| 23 ]) | |
| 24 | |
| 25 | |
| 26 def callback_function_context(callback_function): | |
| 27 includes.clear() | |
| 28 includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) | |
| 29 idl_type = callback_function.idl_type | |
| 30 idl_type_str = str(idl_type) | |
| 31 | |
| 32 def member_cpp_type(): | |
|
bashi
2016/09/13 00:35:06
Why does this need to be a function?
lkawai
2016/09/16 05:05:50
Done.
| |
| 33 member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) | |
| 34 if idl_type.impl_should_use_nullable_container: | |
| 35 return v8_types.cpp_template_type('Nullable', member_cpp_type) | |
| 36 return member_cpp_type | |
| 37 context = { | |
| 38 'cpp_class': callback_function.name, | |
| 39 'v8_class': v8_utilities.v8_class_name(callback_function), | |
| 40 'header_includes': set(CALLBACK_FUNCTION_H_INCLUDES), | |
| 41 'cpp_includes': set(CALLBACK_FUNCTION_CPP_INCLUDES), | |
| 42 'rvalue_cpp_type': idl_type.callback_cpp_type, | |
| 43 'idl_type': idl_type_str, | |
| 44 'member_cpp_type': member_cpp_type(), | |
|
bashi
2016/09/13 00:35:06
It's not clear what 'member_cpp_type' means here.
lkawai
2016/09/16 05:05:50
Done.
| |
| 45 'v8_value_to_local_cpp_value_dict': idl_type.v8_value_to_local_cpp_value ( | |
|
bashi
2016/09/13 00:35:06
Also, please consider better naming for |v8_value_
lkawai
2016/09/16 05:05:50
Done.
| |
| 46 callback_function.extended_attributes, 'currentValue', 'cppValue', b ailout_return_value="false"), | |
| 47 } | |
| 48 context.update(arguments_context(callback_function.arguments, member_cpp_typ e())) | |
| 49 return context | |
| 50 | |
| 51 | |
| 52 def arguments_context(arguments, member_cpp_type): | |
| 53 def argument_context(argument): | |
| 54 return { | |
| 55 'handle': '%sHandle' % argument.name, | |
|
bashi
2016/09/13 00:35:06
What does 'handle' mean here?
lkawai
2016/09/16 05:05:50
Done.
| |
| 56 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( | |
| 57 argument.name, isolate='scriptState->isolate()', | |
| 58 creation_context='scriptState->context()->Global()'), | |
| 59 } | |
| 60 | |
| 61 argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scrip tWrappable'] | |
| 62 argument_declarations.extend( | |
| 63 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) | |
| 64 for argument in arguments) | |
| 65 argument_declarations.append('%s& returnValue' % member_cpp_type) | |
| 66 return { | |
| 67 'argument_declarations': argument_declarations, | |
| 68 'arguments': [argument_context(argument) for argument in arguments], | |
| 69 } | |
| OLD | NEW |