OSDN Git Service

Merge WebKit at r78450: Initial merge by git.
[android-x86/external-webkit.git] / Source / WebCore / bindings / scripts / test / V8 / V8TestCallback.cpp
1 /*
2     This file is part of the WebKit open source project.
3     This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18     Boston, MA 02111-1307, USA.
19 */
20
21 #include "config.h"
22 #include "V8TestCallback.h"
23
24 #if ENABLE(DATABASE)
25
26 #include "ScriptExecutionContext.h"
27 #include "V8Class1.h"
28 #include "V8Class2.h"
29 #include "V8CustomVoidCallback.h"
30 #include "V8DOMString.h"
31 #include "V8Proxy.h"
32 #include <wtf/GetPtr.h>
33 #include <wtf/RefCounted.h>
34 #include <wtf/RefPtr.h>
35
36 #include <wtf/Assertions.h>
37
38 namespace WebCore {
39
40 V8TestCallback::V8TestCallback(v8::Local<v8::Object> callback, ScriptExecutionContext* context)
41     : ActiveDOMCallback(context)
42     , m_callback(v8::Persistent<v8::Object>::New(callback))
43     , m_worldContext(UseCurrentWorld)
44 {
45 }
46
47 V8TestCallback::~V8TestCallback()
48 {
49     m_callback.Dispose();
50 }
51
52 // Functions
53
54 bool V8TestCallback::callbackWithNoParam()
55 {
56     if (!canInvokeCallback())
57         return true;
58
59     v8::HandleScope handleScope;
60
61     v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);
62     if (v8Context.IsEmpty())
63         return true;
64
65     v8::Context::Scope scope(v8Context);
66
67
68     v8::Handle<v8::Value> *argv = 0;
69
70     bool callbackReturnValue = false;
71     return !invokeCallback(m_callback, 0, argv, callbackReturnValue, scriptExecutionContext());
72 }
73
74 bool V8TestCallback::callbackWithClass1Param(Class1* class1Param)
75 {
76     if (!canInvokeCallback())
77         return true;
78
79     v8::HandleScope handleScope;
80
81     v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);
82     if (v8Context.IsEmpty())
83         return true;
84
85     v8::Context::Scope scope(v8Context);
86
87     v8::Handle<v8::Value> class1ParamHandle = toV8(class1Param);
88     if (class1ParamHandle.IsEmpty()) {
89         CRASH();
90         return true;
91     }
92
93     v8::Handle<v8::Value> argv[] = {
94         class1ParamHandle
95     };
96
97     bool callbackReturnValue = false;
98     return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext());
99 }
100
101 bool V8TestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg)
102 {
103     if (!canInvokeCallback())
104         return true;
105
106     v8::HandleScope handleScope;
107
108     v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);
109     if (v8Context.IsEmpty())
110         return true;
111
112     v8::Context::Scope scope(v8Context);
113
114     v8::Handle<v8::Value> class2ParamHandle = toV8(class2Param);
115     if (class2ParamHandle.IsEmpty()) {
116         CRASH();
117         return true;
118     }
119     v8::Handle<v8::Value> strArgHandle = v8String(strArg);
120     if (strArgHandle.IsEmpty()) {
121         CRASH();
122         return true;
123     }
124
125     v8::Handle<v8::Value> argv[] = {
126         class2ParamHandle,
127         strArgHandle
128     };
129
130     bool callbackReturnValue = false;
131     return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext());
132 }
133
134 } // namespace WebCore
135
136 #endif // ENABLE(DATABASE)