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

Unified Diff: third_party/WebKit/Source/bindings/templates/callback_function.cpp

Issue 2312093003: Generated bindings for IDL callback functions (Closed)
Patch Set: Addressed comments 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/templates/callback_function.cpp
diff --git a/third_party/WebKit/Source/bindings/templates/callback_function.cpp b/third_party/WebKit/Source/bindings/templates/callback_function.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b47281ff1492e366e6b4393e9e51545950f106f1
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/templates/callback_function.cpp
@@ -0,0 +1,58 @@
+{% from 'utilities.cpp' import v8_value_to_local_cpp_value %}
+{% filter format_blink_cpp_source_code %}
+
+{% include 'copyright_block.txt' %}
+#include "{{v8_class}}.h"
+
+{% for filename in cpp_includes %}
+#include "{{filename}}"
+{% endfor %}
+
+namespace blink {
+
+{{v8_class}}::{{v8_class}}(v8::Local<v8::Function> callback, ScriptState* scriptState)
peria 2016/09/15 01:14:32 [style] redundant space after ','
lkawai 2016/09/16 05:05:50 Done.
+ : m_callback(scriptState->isolate(), callback)
+{
+ m_callback.setPhantom();
+}
+
+DEFINE_TRACE({{v8_class}})
+{
+}
+
+bool {{v8_class}}::call({{argument_declarations | join(', ')}})
+{
+ {% set return_default = 'return false' %}
bashi 2016/09/13 00:35:06 Remove this and simply use 'return false' where {{
lkawai 2016/09/16 05:05:50 Done.
+ if (!scriptState->contextIsValid())
+ {{return_default}};
+
+ if (m_callback.isEmpty())
+ {{return_default}};
+
+ {% for argument in arguments %}
+ v8::Local<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}};
+ {% endfor %}
+ {% if arguments %}
+ v8::Local<v8::Value> argv[] = { {{arguments | join(', ', 'handle')}} };
+ {% else %}
+ {# Empty array initializers are illegal, and don\'t compile in MSVC. #}
+ v8::Local<v8::Value> *argv = 0;
peria 2016/09/15 01:14:32 [style] s/0/nullptr/
lkawai 2016/09/16 05:05:50 Done.
+ {% endif %}
+
+ v8::Local<v8::Value> currentValue;
+ v8::TryCatch exceptionCatcher(scriptState->isolate());
+ exceptionCatcher.SetVerbose(true);
+ if (V8ScriptRunner::callFunction(m_callback.newLocal(scriptState->isolate()), scriptState->getExecutionContext(), scriptState->context()->Global(), {{arguments | length}}, argv, scriptState->isolate()).ToLocal(&currentValue))
+ {
+ {% if rvalue_cpp_type != 'void' %}
bashi 2016/09/13 00:35:06 Did you try generating bindings for a callback of
lkawai 2016/09/16 05:05:50 Done.
+ {{v8_value_to_local_cpp_value(v8_value_to_local_cpp_value_dict)}}
+ {% endif %}
+ returnValue = cppValue;
+ return true;
+ }
+ else { return false; }
bashi 2016/09/13 00:35:06 Remove else clause and simply return false.
lkawai 2016/09/16 05:05:50 Done.
+}
+
+} // namespace blink
+
+{% endfilter %}{# format_blink_cpp_source_code #}

Powered by Google App Engine
This is Rietveld 408576698