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_v8.py. DO NOT MODIFY! 6 7 #include "config.h" 8 #include "V8TestCallbackInterface.h" 9 10 #include "bindings/core/v8/ScriptController.h" 11 #include "bindings/core/v8/V8Binding.h" 12 #include "bindings/core/v8/V8TestInterfaceEmpty.h" 13 #include "bindings/core/v8/V8TestInterfaceWillBeGarbageCollected.h" 14 #include "core/dom/ExecutionContext.h" 15 #include "wtf/Assertions.h" 16 #include "wtf/GetPtr.h" 17 #include "wtf/RefPtr.h" 18 19 namespace blink { 20 21 V8TestCallbackInterface::V8TestCallbackInterface(v8::Handle<v8::Function> callback, ScriptState* scriptState) 22 : ActiveDOMCallback(scriptState->executionContext()) 23 , m_scriptState(scriptState) 24 { 25 m_callback.set(scriptState->isolate(), callback); 26 } 27 28 V8TestCallbackInterface::~V8TestCallbackInterface() 29 { 30 } 31 32 void V8TestCallbackInterface::voidMethod() 33 { 34 if (!canInvokeCallback()) 35 return; 36 37 if (m_scriptState->contextIsValid()) 38 return; 39 40 ScriptState::Scope scope(m_scriptState.get()); 41 v8::Handle<v8::Value> *argv = 0; 42 43 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 0, argv, m_scriptState->isolate()); 44 } 45 46 bool V8TestCallbackInterface::booleanMethod() 47 { 48 if (!canInvokeCallback()) 49 return true; 50 51 if (m_scriptState->contextIsValid()) 52 return true; 53 54 ScriptState::Scope scope(m_scriptState.get()); 55 v8::Handle<v8::Value> *argv = 0; 56 57 v8::TryCatch exceptionCatcher; 58 exceptionCatcher.SetVerbose(true); 59 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 0, argv, m_scriptState->isolate()); 60 return !exceptionCatcher.HasCaught(); 61 } 62 63 void V8TestCallbackInterface::voidMethodBooleanArg(bool boolArg) 64 { 65 if (!canInvokeCallback()) 66 return; 67 68 if (m_scriptState->contextIsValid()) 69 return; 70 71 ScriptState::Scope scope(m_scriptState.get()); 72 v8::Handle<v8::Value> boolArgHandle = v8Boolean(boolArg, m_scriptState->isolate()); 73 if (boolArgHandle.IsEmpty()) { 74 if (!isScriptControllerTerminating()) 75 CRASH(); 76 return; 77 } 78 v8::Handle<v8::Value> argv[] = { boolArgHandle }; 79 80 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 81 } 82 83 void V8TestCallbackInterface::voidMethodSequenceArg(const Vector<RefPtr<TestInterfaceEmpty> >& sequenceArg) 84 { 85 if (!canInvokeCallback()) 86 return; 87 88 if (m_scriptState->contextIsValid()) 89 return; 90 91 ScriptState::Scope scope(m_scriptState.get()); 92 v8::Handle<v8::Value> sequenceArgHandle = v8Array(sequenceArg, m_scriptState->context()->Global(), m_scriptState->isolate()); 93 if (sequenceArgHandle.IsEmpty()) { 94 if (!isScriptControllerTerminating()) 95 CRASH(); 96 return; 97 } 98 v8::Handle<v8::Value> argv[] = { sequenceArgHandle }; 99 100 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 101 } 102 103 void V8TestCallbackInterface::voidMethodFloatArg(float floatArg) 104 { 105 if (!canInvokeCallback()) 106 return; 107 108 if (m_scriptState->contextIsValid()) 109 return; 110 111 ScriptState::Scope scope(m_scriptState.get()); 112 v8::Handle<v8::Value> floatArgHandle = v8::Number::New(m_scriptState->isolate(), floatArg); 113 if (floatArgHandle.IsEmpty()) { 114 if (!isScriptControllerTerminating()) 115 CRASH(); 116 return; 117 } 118 v8::Handle<v8::Value> argv[] = { floatArgHandle }; 119 120 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 121 } 122 123 void V8TestCallbackInterface::voidMethodTestInterfaceEmptyArg(TestInterfaceEmpty* testInterfaceEmptyArg) 124 { 125 if (!canInvokeCallback()) 126 return; 127 128 if (m_scriptState->contextIsValid()) 129 return; 130 131 ScriptState::Scope scope(m_scriptState.get()); 132 v8::Handle<v8::Value> testInterfaceEmptyArgHandle = toV8(testInterfaceEmptyArg, m_scriptState->context()->Global(), m_scriptState->isolate()); 133 if (testInterfaceEmptyArgHandle.IsEmpty()) { 134 if (!isScriptControllerTerminating()) 135 CRASH(); 136 return; 137 } 138 v8::Handle<v8::Value> argv[] = { testInterfaceEmptyArgHandle }; 139 140 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 141 } 142 143 void V8TestCallbackInterface::voidMethodTestInterfaceEmptyStringArg(TestInterfaceEmpty* testInterfaceEmptyArg, const String& stringArg) 144 { 145 if (!canInvokeCallback()) 146 return; 147 148 if (m_scriptState->contextIsValid()) 149 return; 150 151 ScriptState::Scope scope(m_scriptState.get()); 152 v8::Handle<v8::Value> testInterfaceEmptyArgHandle = toV8(testInterfaceEmptyArg, m_scriptState->context()->Global(), m_scriptState->isolate()); 153 if (testInterfaceEmptyArgHandle.IsEmpty()) { 154 if (!isScriptControllerTerminating()) 155 CRASH(); 156 return; 157 } 158 v8::Handle<v8::Value> stringArgHandle = v8String(m_scriptState->isolate(), stringArg); 159 if (stringArgHandle.IsEmpty()) { 160 if (!isScriptControllerTerminating()) 161 CRASH(); 162 return; 163 } 164 v8::Handle<v8::Value> argv[] = { testInterfaceEmptyArgHandle, stringArgHandle }; 165 166 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 2, argv, m_scriptState->isolate()); 167 } 168 169 void V8TestCallbackInterface::callbackWithThisValueVoidMethodStringArg(ScriptValue thisValue, const String& stringArg) 170 { 171 if (!canInvokeCallback()) 172 return; 173 174 if (m_scriptState->contextIsValid()) 175 return; 176 177 ScriptState::Scope scope(m_scriptState.get()); 178 v8::Handle<v8::Value> thisHandle = thisValue.v8Value(); 179 if (thisHandle.IsEmpty()) { 180 if (!isScriptControllerTerminating()) 181 CRASH(); 182 return; 183 } 184 v8::Handle<v8::Value> stringArgHandle = v8String(m_scriptState->isolate(), stringArg); 185 if (stringArgHandle.IsEmpty()) { 186 if (!isScriptControllerTerminating()) 187 CRASH(); 188 return; 189 } 190 v8::Handle<v8::Value> argv[] = { stringArgHandle }; 191 192 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), thisHandle, 1, argv, m_scriptState->isolate()); 193 } 194 195 void V8TestCallbackInterface::voidMethodWillBeGarbageCollectedSequenceArg(const WillBeHeapVector<RefPtrWillBeMember<TestInterfaceWillBeGarbageCollected> >& sequenceArg) 196 { 197 if (!canInvokeCallback()) 198 return; 199 200 if (m_scriptState->contextIsValid()) 201 return; 202 203 ScriptState::Scope scope(m_scriptState.get()); 204 v8::Handle<v8::Value> sequenceArgHandle = v8Array(sequenceArg, m_scriptState->context()->Global(), m_scriptState->isolate()); 205 if (sequenceArgHandle.IsEmpty()) { 206 if (!isScriptControllerTerminating()) 207 CRASH(); 208 return; 209 } 210 v8::Handle<v8::Value> argv[] = { sequenceArgHandle }; 211 212 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 213 } 214 215 void V8TestCallbackInterface::voidMethodWillBeGarbageCollectedArrayArg(const WillBeHeapVector<RefPtrWillBeMember<TestInterfaceWillBeGarbageCollected> >& arrayArg) 216 { 217 if (!canInvokeCallback()) 218 return; 219 220 if (m_scriptState->contextIsValid()) 221 return; 222 223 ScriptState::Scope scope(m_scriptState.get()); 224 v8::Handle<v8::Value> arrayArgHandle = v8Array(arrayArg, m_scriptState->context()->Global(), m_scriptState->isolate()); 225 if (arrayArgHandle.IsEmpty()) { 226 if (!isScriptControllerTerminating()) 227 CRASH(); 228 return; 229 } 230 v8::Handle<v8::Value> argv[] = { arrayArgHandle }; 231 232 ScriptController::callFunction(m_scriptState->executionContext(), m_callback.newLocal(m_scriptState->isolate()), m_scriptState->context()->Global(), 1, argv, m_scriptState->isolate()); 233 } 234 235 } // namespace blink 236