Commit 9448506a authored by nbarth@chromium.org's avatar nbarth@chromium.org

Clean up callback interface code and template

The callback interface code was the first code and template we wrote.
Since then we've improved style and template usage; this simplifies
the code and brings it up-to-date.

TBR=haraken
BUG=345503

Review URL: https://codereview.chromium.org/215993002

git-svn-id: svn://svn.chromium.org/blink/trunk@170254 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ba71bbcb
...@@ -53,16 +53,6 @@ CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([ ...@@ -53,16 +53,6 @@ CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
]) ])
def cpp_to_v8_conversion(idl_type, name):
# FIXME: setting creation_context=v8::Handle<v8::Object>() is wrong,
# as toV8 then implicitly uses the current context, which causes leaks
# between isolate worlds if a different context should be used.
cpp_value_to_v8_value = idl_type.cpp_value_to_v8_value(name,
isolate='m_isolate', creation_context='v8::Handle<v8::Object>()')
return 'v8::Handle<v8::Value> {name}Handle = {cpp_to_v8};'.format(
name=name, cpp_to_v8=cpp_value_to_v8_value)
def cpp_type(idl_type): def cpp_type(idl_type):
# FIXME: remove this function by making callback types consistent # FIXME: remove this function by making callback types consistent
# (always use usual v8_types.cpp_type) # (always use usual v8_types.cpp_type)
...@@ -83,18 +73,14 @@ IdlType.callback_cpp_type = property(cpp_type) ...@@ -83,18 +73,14 @@ IdlType.callback_cpp_type = property(cpp_type)
def generate_callback_interface(callback_interface): def generate_callback_interface(callback_interface):
includes.clear() includes.clear()
includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
name = callback_interface.name return {
methods = [generate_method(operation)
for operation in callback_interface.operations]
template_contents = {
'conditional_string': v8_utilities.conditional_string(callback_interface), 'conditional_string': v8_utilities.conditional_string(callback_interface),
'cpp_class': name, 'cpp_class': callback_interface.name,
'v8_class': v8_utilities.v8_class_name(callback_interface), 'v8_class': v8_utilities.v8_class_name(callback_interface),
'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES), 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
'methods': methods, 'methods': [generate_method(operation)
for operation in callback_interface.operations],
} }
return template_contents
def add_includes_for_operation(operation): def add_includes_for_operation(operation):
...@@ -128,17 +114,21 @@ def generate_method(operation): ...@@ -128,17 +114,21 @@ def generate_method(operation):
def generate_arguments_contents(arguments, call_with_this_handle): def generate_arguments_contents(arguments, call_with_this_handle):
def generate_argument(argument): def generate_argument(argument):
return { return {
'name': argument.name, 'handle': '%sHandle' % argument.name,
'cpp_to_v8_conversion': cpp_to_v8_conversion(argument.idl_type, argument.name), # FIXME: setting creation_context=v8::Handle<v8::Object>() is
# wrong, as toV8 then implicitly uses the current context, which
# causes leaks between isolated worlds if a different context is
# used.
'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value(
argument.name, isolate='m_isolate',
creation_context='v8::Handle<v8::Object>()'),
} }
argument_declarations = [ argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle else []
'%s %s' % (argument.idl_type.callback_cpp_type, argument.name) argument_declarations.extend(
for argument in arguments] '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
if call_with_this_handle: for argument in arguments)
argument_declarations.insert(0, 'ScriptValue thisValue')
return { return {
'argument_declarations': argument_declarations, 'argument_declarations': argument_declarations,
'arguments': [generate_argument(argument) for argument in arguments], 'arguments': [generate_argument(argument) for argument in arguments],
'handles': ['%sHandle' % argument.name for argument in arguments],
} }
...@@ -51,15 +51,15 @@ namespace WebCore { ...@@ -51,15 +51,15 @@ namespace WebCore {
ASSERT(thisHandle->IsObject()); ASSERT(thisHandle->IsObject());
{% endif %} {% endif %}
{% for argument in method.arguments %} {% for argument in method.arguments %}
{{argument.cpp_to_v8_conversion | indent}} v8::Handle<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}};
if ({{argument.name}}Handle.IsEmpty()) { if ({{argument.handle}}.IsEmpty()) {
if (!isScriptControllerTerminating()) if (!isScriptControllerTerminating())
CRASH(); CRASH();
{{return_default}}; {{return_default}};
} }
{% endfor %} {% endfor %}
{% if method.arguments %} {% if method.arguments %}
v8::Handle<v8::Value> argv[] = { {{method.handles | join(', ')}} }; v8::Handle<v8::Value> argv[] = { {{method.arguments | join(', ', attribute='handle')}} };
{% else %} {% else %}
v8::Handle<v8::Value> *argv = 0; v8::Handle<v8::Value> *argv = 0;
{% endif %} {% endif %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment