Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: third_party/WebKit/Source/bindings/scripts/v8_callback_function.py

Issue 2312093003: Generated bindings for IDL callback functions (Closed)
Patch Set: Changed BUILD.gn Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/scripts/v8_callback_function.py
diff --git a/third_party/WebKit/Source/bindings/scripts/v8_callback_interface.py b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py
similarity index 50%
copy from third_party/WebKit/Source/bindings/scripts/v8_callback_interface.py
copy to third_party/WebKit/Source/bindings/scripts/v8_callback_function.py
index d6316bddb0d23352e2db9f542d5efa6b0b78d7aa..264bf310635a7e196d8217ff69a618fb6f02e071 100644
--- a/third_party/WebKit/Source/bindings/scripts/v8_callback_interface.py
+++ b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py
@@ -1,19 +1,3 @@
-# Copyright (C) 2013 Google Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -26,9 +10,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-"""Generate template values for a callback interface.
+"""Generate template values for a callback function.
-Extends IdlTypeBase with property |callback_cpp_type|.
+ Extends IdlTypeBase with property |callback_cpp_type|.
Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
"""
@@ -38,18 +22,16 @@ from v8_globals import includes
import v8_types
import v8_utilities
-CALLBACK_INTERFACE_H_INCLUDES = frozenset([
+CALLBACK_FUNCTION_H_INCLUDES = frozenset([
'bindings/core/v8/ActiveDOMCallback.h',
'bindings/core/v8/DOMWrapperWorld.h',
'bindings/core/v8/ScopedPersistent.h',
Yuki 2016/09/07 10:04:02 I think it's fine to start with copy&pasting, but
lkawai 2016/09/08 09:11:31 Done.
])
-CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
+CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([
'bindings/core/v8/ScriptController.h',
'bindings/core/v8/V8Binding.h',
- 'core/dom/ExecutionContext.h',
+ 'bindings/core/v8/V8PrivateProperty.h',
'wtf/Assertions.h',
Yuki 2016/09/07 10:04:02 Ditto. I think we don't need ScriptController.h a
lkawai 2016/09/08 09:11:31 Done.
- 'wtf/GetPtr.h',
- 'wtf/RefPtr.h',
])
@@ -71,48 +53,33 @@ def cpp_type(idl_type):
IdlTypeBase.callback_cpp_type = property(cpp_type)
Yuki 2016/09/07 10:04:02 v8_callback_interface.py already updated this prop
lkawai 2016/09/08 09:11:31 Done.
-def callback_interface_context(callback_interface):
+def callback_function_context(callback_function):
includes.clear()
- includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
- return {
- 'cpp_class': callback_interface.name,
- 'v8_class': v8_utilities.v8_class_name(callback_interface),
- 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
- 'methods': [method_context(operation)
- for operation in callback_interface.operations],
- }
-
-
-def add_includes_for_operation(operation):
- operation.idl_type.add_includes_for_type()
- for argument in operation.arguments:
- argument.idl_type.add_includes_for_type()
-
-
-def method_context(operation):
- extended_attributes = operation.extended_attributes
- idl_type = operation.idl_type
+ includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
+ idl_type = callback_function.idl_type
idl_type_str = str(idl_type)
- if idl_type_str not in ['boolean', 'void']:
- raise Exception('We only support callbacks that return boolean or void values.')
- is_custom = 'Custom' in extended_attributes
- if not is_custom:
- add_includes_for_operation(operation)
- call_with = extended_attributes.get('CallWith')
- call_with_this_handle = v8_utilities.extended_attribute_value_contains(call_with, 'ThisValue')
+
+ def member_cpp_type():
+ 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 = {
- 'call_with_this_handle': call_with_this_handle,
- 'cpp_type': idl_type.callback_cpp_type,
+ '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,
- 'is_custom': is_custom,
- 'name': operation.name,
+ 'member_cpp_type': member_cpp_type(),
+ 'v8_value_to_local_cpp_value_dict': idl_type.v8_value_to_local_cpp_value(
+ callback_function.extended_attributes, 'currentValue', 'cppValue', bailout_return_value="false"),
}
- context.update(arguments_context(operation.arguments,
- call_with_this_handle))
+ context.update(arguments_context(callback_function.arguments))
return context
-def arguments_context(arguments, call_with_this_handle):
+def arguments_context(arguments):
def argument_context(argument):
return {
'handle': '%sHandle' % argument.name,
@@ -121,11 +88,11 @@ def arguments_context(arguments, call_with_this_handle):
creation_context='m_scriptState->context()->Global()'),
}
- argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle else []
+ argument_declarations = ['ScriptValue thisValue']
argument_declarations.extend(
'%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
for argument in arguments)
- return {
+ return {
'argument_declarations': argument_declarations,
'arguments': [argument_context(argument) for argument in arguments],
}

Powered by Google App Engine
This is Rietveld 408576698