Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / templates / callback_interface.cpp
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY!
6
7 #include "config.h"
8 {% filter conditional(conditional_string) %}
9 #include "{{v8_class}}.h"
10
11 {% for filename in cpp_includes %}
12 #include "{{filename}}"
13 {% endfor %}
14
15 namespace WebCore {
16
17 {{v8_class}}::{{v8_class}}(v8::Handle<v8::Function> callback, ExecutionContext* context)
18     : ActiveDOMCallback(context)
19 {
20     v8::Isolate* isolate = toIsolate(context);
21     m_callback.set(isolate, callback);
22     m_scriptState = ScriptState::current(isolate);
23 }
24
25 {{v8_class}}::~{{v8_class}}()
26 {
27 }
28
29 {% for method in methods if not method.custom %}
30 {{method.cpp_type}} {{v8_class}}::{{method.name}}({{method.argument_declarations | join(', ')}})
31 {
32     {% set return_default = 'return true'
33            if method.idl_type == 'boolean' else 'return' %}{# void #}
34     if (!canInvokeCallback())
35         {{return_default}};
36
37     v8::Isolate* isolate = m_scriptState->isolate();
38     if (m_scriptState->contextIsEmpty())
39         {{return_default}};
40
41     ScriptState::Scope scope(m_scriptState.get());
42     {% if method.call_with_this_handle %}
43     v8::Handle<v8::Value> thisHandle = thisValue.v8Value();
44     if (thisHandle.IsEmpty()) {
45         if (!isScriptControllerTerminating())
46             CRASH();
47         {{return_default}};
48     }
49     ASSERT(thisHandle->IsObject());
50     {% endif %}
51     {% for argument in method.arguments %}
52     v8::Handle<v8::Value> {{argument.handle}} = {{argument.cpp_value_to_v8_value}};
53     if ({{argument.handle}}.IsEmpty()) {
54         if (!isScriptControllerTerminating())
55             CRASH();
56         {{return_default}};
57     }
58     {% endfor %}
59     {% if method.arguments %}
60     v8::Handle<v8::Value> argv[] = { {{method.arguments | join(', ', 'handle')}} };
61     {% else %}
62     v8::Handle<v8::Value> *argv = 0;
63     {% endif %}
64
65     {% set this_handle_parameter = 'v8::Handle<v8::Object>::Cast(thisHandle), ' if method.call_with_this_handle else '' %}
66     {% if method.idl_type == 'boolean' %}
67     return invokeCallback(m_callback.newLocal(isolate), {{this_handle_parameter}}{{method.arguments | length}}, argv, executionContext(), isolate);
68     {% else %}{# void #}
69     invokeCallback(m_callback.newLocal(isolate), {{this_handle_parameter}}{{method.arguments | length}}, argv, executionContext(), isolate);
70     {% endif %}
71 }
72
73 {% endfor %}
74 } // namespace WebCore
75 {% endfilter %}