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 "V8Binding.h" 28 #include "V8Class1.h" 29 #include "V8Class2.h" 30 #include "V8CustomVoidCallback.h" 31 #include "V8DOMStringList.h" 32 #include "V8Proxy.h" 33 #include <wtf/GetPtr.h> 34 #include <wtf/RefCounted.h> 35 #include <wtf/RefPtr.h> 36 37 #include <wtf/Assertions.h> 38 39 namespace WebCore { 40 41 V8TestCallback::V8TestCallback(v8::Local<v8::Object> callback, ScriptExecutionContext* context) 42 : ActiveDOMCallback(context) 43 , m_callback(v8::Persistent<v8::Object>::New(callback)) 44 , m_worldContext(UseCurrentWorld) 45 { 46 } 47 48 V8TestCallback::~V8TestCallback() 49 { 50 m_callback.Dispose(); 51 } 52 53 // Functions 54 55 bool V8TestCallback::callbackWithNoParam() 56 { 57 if (!canInvokeCallback()) 58 return true; 59 60 v8::HandleScope handleScope; 61 62 v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); 63 if (v8Context.IsEmpty()) 64 return true; 65 66 v8::Context::Scope scope(v8Context); 67 68 69 v8::Handle<v8::Value> *argv = 0; 70 71 bool callbackReturnValue = false; 72 return !invokeCallback(m_callback, 0, argv, callbackReturnValue, scriptExecutionContext()); 73 } 74 75 bool V8TestCallback::callbackWithClass1Param(Class1* class1Param) 76 { 77 if (!canInvokeCallback()) 78 return true; 79 80 v8::HandleScope handleScope; 81 82 v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); 83 if (v8Context.IsEmpty()) 84 return true; 85 86 v8::Context::Scope scope(v8Context); 87 88 v8::Handle<v8::Value> class1ParamHandle = toV8(class1Param); 89 if (class1ParamHandle.IsEmpty()) { 90 CRASH(); 91 return true; 92 } 93 94 v8::Handle<v8::Value> argv[] = { 95 class1ParamHandle 96 }; 97 98 bool callbackReturnValue = false; 99 return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext()); 100 } 101 102 bool V8TestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg) 103 { 104 if (!canInvokeCallback()) 105 return true; 106 107 v8::HandleScope handleScope; 108 109 v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); 110 if (v8Context.IsEmpty()) 111 return true; 112 113 v8::Context::Scope scope(v8Context); 114 115 v8::Handle<v8::Value> class2ParamHandle = toV8(class2Param); 116 if (class2ParamHandle.IsEmpty()) { 117 CRASH(); 118 return true; 119 } 120 v8::Handle<v8::Value> strArgHandle = v8String(strArg); 121 if (strArgHandle.IsEmpty()) { 122 CRASH(); 123 return true; 124 } 125 126 v8::Handle<v8::Value> argv[] = { 127 class2ParamHandle, 128 strArgHandle 129 }; 130 131 bool callbackReturnValue = false; 132 return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext()); 133 } 134 135 bool V8TestCallback::callbackWithStringList(PassRefPtr<DOMStringList> listParam) 136 { 137 if (!canInvokeCallback()) 138 return true; 139 140 v8::HandleScope handleScope; 141 142 v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); 143 if (v8Context.IsEmpty()) 144 return true; 145 146 v8::Context::Scope scope(v8Context); 147 148 v8::Handle<v8::Value> listParamHandle = toV8(listParam); 149 if (listParamHandle.IsEmpty()) { 150 CRASH(); 151 return true; 152 } 153 154 v8::Handle<v8::Value> argv[] = { 155 listParamHandle 156 }; 157 158 bool callbackReturnValue = false; 159 return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext()); 160 } 161 162 } // namespace WebCore 163 164 #endif // ENABLE(DATABASE) 165