Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
| diff --git a/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4c1bab5b527e22fa5ecd483c7b6ed3020d91a899 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
| @@ -0,0 +1,69 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Generate template values for a callback function. |
| + |
| +Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| +""" |
| + |
| +from v8_globals import includes |
| +import v8_types |
| +import v8_utilities |
| + |
| +CALLBACK_FUNCTION_H_INCLUDES = frozenset([ |
| + 'bindings/core/v8/ScopedPersistent.h', |
| + 'platform/heap/Handle.h', |
| + 'wtf/text/WTFString.h', |
| +]) |
| +CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ |
| + 'bindings/core/v8/ScriptState.h', |
| + 'bindings/core/v8/V8Binding.h', |
| + 'wtf/Assertions.h', |
| +]) |
| + |
| + |
| +def callback_function_context(callback_function): |
| + includes.clear() |
| + includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) |
| + idl_type = callback_function.idl_type |
| + idl_type_str = str(idl_type) |
| + |
| + 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.
|
| + member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
| + if idl_type.impl_should_use_nullable_container: |
| + return v8_types.cpp_template_type('Nullable', member_cpp_type) |
| + return member_cpp_type |
| + context = { |
| + 'cpp_class': callback_function.name, |
| + 'v8_class': v8_utilities.v8_class_name(callback_function), |
| + 'header_includes': set(CALLBACK_FUNCTION_H_INCLUDES), |
| + 'cpp_includes': set(CALLBACK_FUNCTION_CPP_INCLUDES), |
| + 'rvalue_cpp_type': idl_type.callback_cpp_type, |
| + 'idl_type': idl_type_str, |
| + '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.
|
| + '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.
|
| + callback_function.extended_attributes, 'currentValue', 'cppValue', bailout_return_value="false"), |
| + } |
| + context.update(arguments_context(callback_function.arguments, member_cpp_type())) |
| + return context |
| + |
| + |
| +def arguments_context(arguments, member_cpp_type): |
| + def argument_context(argument): |
| + return { |
| + 'handle': '%sHandle' % argument.name, |
|
bashi
2016/09/13 00:35:06
What does 'handle' mean here?
lkawai
2016/09/16 05:05:50
Done.
|
| + 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( |
| + argument.name, isolate='scriptState->isolate()', |
| + creation_context='scriptState->context()->Global()'), |
| + } |
| + |
| + argument_declarations = ['ScriptState* scriptState', 'ScriptWrappable* scriptWrappable'] |
| + argument_declarations.extend( |
| + '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) |
| + for argument in arguments) |
| + argument_declarations.append('%s& returnValue' % member_cpp_type) |
| + return { |
| + 'argument_declarations': argument_declarations, |
| + 'arguments': [argument_context(argument) for argument in arguments], |
| + } |