Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / bindings / templates / callback_interface.cpp
blob5bf45619423f1acdd627af5562e5aefa2bfb6ab0
1 {% include 'copyright_block.txt' %}
2 #include "config.h"
3 {% filter conditional(conditional_string) %}
4 #include "{{v8_class}}.h"
6 {% for filename in cpp_includes %}
7 #include "{{filename}}"
8 {% endfor %}
10 namespace blink {
12 {{v8_class}}::{{v8_class}}(v8::Local<v8::Function> callback, ScriptState* scriptState)
13 : ActiveDOMCallback(scriptState->executionContext())
14 , m_scriptState(scriptState)
16 m_callback.set(scriptState->isolate(), callback);
19 {{v8_class}}::~{{v8_class}}()
23 DEFINE_TRACE({{v8_class}})
25 {{cpp_class}}::trace(visitor);
26 ActiveDOMCallback::trace(visitor);
29 {% for method in methods if not method.is_custom %}
30 {{method.cpp_type}} {{v8_class}}::{{method.name}}({{method.argument_declarations | join(', ')}})
32 {% set return_default = 'return true'
33 if method.idl_type == 'boolean' else 'return' %}{# void #}
34 if (!canInvokeCallback())
35 {{return_default}};
37 if (!m_scriptState->contextIsValid())
38 {{return_default}};
40 ScriptState::Scope scope(m_scriptState.get());
41 {% if method.call_with_this_handle %}
42 v8::Local<v8::Value> thisHandle = thisValue.v8Value();
43 if (thisHandle.IsEmpty()) {
44 if (!isScriptControllerTerminating())
45 CRASH();
46 {{return_default}};
48 {% endif %}
49 {% for argument in method.arguments %}
50 v8::Local<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}};
51 if ({{argument.handle}}.IsEmpty()) {
52 if (!isScriptControllerTerminating())
53 CRASH();
54 {{return_default}};
56 {% endfor %}
57 {% if method.arguments %}
58 v8::Local<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} };
59 {% else %}
60 {# Empty array initializers are illegal, and don't compile in MSVC. #}
61 v8::Local<v8::Value> *argv = 0;
62 {% endif %}
64 {% set this_handle_parameter = 'thisHandle, ' if method.call_with_this_handle else 'v8::Undefined(m_scriptState->isolate()), ' %}
65 {% if method.idl_type == 'boolean' %}
66 v8::TryCatch exceptionCatcher;
67 exceptionCatcher.SetVerbose(true);
68 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), {{this_handle_parameter}}{{method.arguments | length}}, argv, m_scriptState->isolate());
69 return !exceptionCatcher.HasCaught();
70 {% else %}{# void #}
71 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), {{this_handle_parameter}}{{method.arguments | length}}, argv, m_scriptState->isolate());
72 {% endif %}
75 {% endfor %}
76 } // namespace blink
77 {% endfilter %}