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 "V8TestTypedefs.h" 9 10 #include "bindings/core/v8/ExceptionState.h" 11 #include "bindings/core/v8/V8DOMConfiguration.h" 12 #include "bindings/core/v8/V8HiddenValue.h" 13 #include "bindings/core/v8/V8ObjectConstructor.h" 14 #include "bindings/core/v8/V8TestCallbackInterface.h" 15 #include "bindings/core/v8/V8TestInterface.h" 16 #include "bindings/core/v8/V8TestInterfaceEmpty.h" 17 #include "core/dom/ContextFeatures.h" 18 #include "core/dom/Document.h" 19 #include "core/frame/LocalDOMWindow.h" 20 #include "platform/RuntimeEnabledFeatures.h" 21 #include "platform/TraceEvent.h" 22 #include "wtf/GetPtr.h" 23 #include "wtf/RefPtr.h" 24 25 namespace blink { 26 27 const WrapperTypeInfo V8TestTypedefs::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestTypedefs::domTemplate, V8TestTypedefs::refObject, V8TestTypedefs::derefObject, V8TestTypedefs::createPersistentHandle, 0, 0, 0, V8TestTypedefs::installConditionallyEnabledMethods, V8TestTypedefs::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::RefCountedObject }; 28 29 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in TestTypedefs.h. 30 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in 31 // bindings/core/v8/ScriptWrappable.h. 32 const WrapperTypeInfo& TestTypedefs::s_wrapperTypeInfo = V8TestTypedefs::wrapperTypeInfo; 33 34 namespace TestTypedefsV8Internal { 35 36 template <typename T> void V8_USE(T) { } 37 38 static void uLongLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 39 { 40 v8::Handle<v8::Object> holder = info.Holder(); 41 TestTypedefs* impl = V8TestTypedefs::toImpl(holder); 42 v8SetReturnValue(info, static_cast<double>(impl->uLongLongAttribute())); 43 } 44 45 static void uLongLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 46 { 47 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 48 TestTypedefsV8Internal::uLongLongAttributeAttributeGetter(info); 49 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 50 } 51 52 static void uLongLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 53 { 54 v8::Handle<v8::Object> holder = info.Holder(); 55 ExceptionState exceptionState(ExceptionState::SetterContext, "uLongLongAttribute", "TestTypedefs", holder, info.GetIsolate()); 56 TestTypedefs* impl = V8TestTypedefs::toImpl(holder); 57 TONATIVE_VOID_EXCEPTIONSTATE(unsigned long long, cppValue, toUInt64(v8Value, exceptionState), exceptionState); 58 impl->setULongLongAttribute(cppValue); 59 } 60 61 static void uLongLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 62 { 63 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter"); 64 TestTypedefsV8Internal::uLongLongAttributeAttributeSetter(v8Value, info); 65 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 66 } 67 68 static void TestTypedefsConstructorGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 69 { 70 v8::Handle<v8::Value> data = info.Data(); 71 ASSERT(data->IsExternal()); 72 V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext()); 73 if (!perContextData) 74 return; 75 v8SetReturnValue(info, perContextData->constructorForType(WrapperTypeInfo::unwrap(data))); 76 } 77 78 static void TestTypedefsForceSetAttributeOnThis(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 79 { 80 if (info.This()->IsObject()) 81 v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value); 82 } 83 84 static void TestTypedefsForceSetAttributeOnThisCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 85 { 86 TestTypedefsV8Internal::TestTypedefsForceSetAttributeOnThis(name, v8Value, info); 87 } 88 89 static void voidMethodArrayOfLongsArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 90 { 91 ExceptionState exceptionState(ExceptionState::ExecutionContext, "voidMethodArrayOfLongsArg", "TestTypedefs", info.Holder(), info.GetIsolate()); 92 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 93 Vector<int> arrayOfLongsArg; 94 { 95 if (UNLIKELY(info.Length() <= 0)) { 96 impl->voidMethodArrayOfLongsArg(); 97 return; 98 } 99 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(arrayOfLongsArg, toImplArray<int>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); 100 } 101 impl->voidMethodArrayOfLongsArg(arrayOfLongsArg); 102 } 103 104 static void voidMethodArrayOfLongsArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 105 { 106 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 107 TestTypedefsV8Internal::voidMethodArrayOfLongsArgMethod(info); 108 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 109 } 110 111 static void voidMethodFloatArgStringArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 112 { 113 ExceptionState exceptionState(ExceptionState::ExecutionContext, "voidMethodFloatArgStringArg", "TestTypedefs", info.Holder(), info.GetIsolate()); 114 if (UNLIKELY(info.Length() < 2)) { 115 setMinimumArityTypeError(exceptionState, 2, info.Length()); 116 exceptionState.throwIfNeeded(); 117 return; 118 } 119 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 120 float floatArg; 121 V8StringResource<> stringArg; 122 { 123 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(floatArg, toFloat(info[0], exceptionState), exceptionState); 124 TOSTRING_VOID_INTERNAL(stringArg, info[1]); 125 } 126 impl->voidMethodFloatArgStringArg(floatArg, stringArg); 127 } 128 129 static void voidMethodFloatArgStringArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 130 { 131 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 132 TestTypedefsV8Internal::voidMethodFloatArgStringArgMethod(info); 133 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 134 } 135 136 static void voidMethodTestCallbackInterfaceTypeArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 137 { 138 if (UNLIKELY(info.Length() < 1)) { 139 V8ThrowException::throwException(createMinimumArityTypeErrorForMethod("voidMethodTestCallbackInterfaceTypeArg", "TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate()); 140 return; 141 } 142 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 143 TestCallbackInterface* testCallbackInterfaceTypeArg; 144 { 145 if (info.Length() <= 0 || !info[0]->IsFunction()) { 146 V8ThrowException::throwTypeError(ExceptionMessages::failedToExecute("voidMethodTestCallbackInterfaceTypeArg", "TestTypedefs", "The callback provided as parameter 1 is not a function."), info.GetIsolate()); 147 return; 148 } 149 testCallbackInterfaceTypeArg = V8TestCallbackInterface::create(v8::Handle<v8::Function>::Cast(info[0]), ScriptState::current(info.GetIsolate())); 150 } 151 impl->voidMethodTestCallbackInterfaceTypeArg(testCallbackInterfaceTypeArg); 152 } 153 154 static void voidMethodTestCallbackInterfaceTypeArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 155 { 156 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 157 TestTypedefsV8Internal::voidMethodTestCallbackInterfaceTypeArgMethod(info); 158 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 159 } 160 161 static void uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 162 { 163 ExceptionState exceptionState(ExceptionState::ExecutionContext, "uLongLongMethodTestInterfaceEmptyTypeSequenceArg", "TestTypedefs", info.Holder(), info.GetIsolate()); 164 if (UNLIKELY(info.Length() < 1)) { 165 setMinimumArityTypeError(exceptionState, 1, info.Length()); 166 exceptionState.throwIfNeeded(); 167 return; 168 } 169 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 170 Vector<RefPtr<TestInterfaceEmpty> > testInterfaceEmptyTypeSequenceArg; 171 { 172 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(testInterfaceEmptyTypeSequenceArg, (toRefPtrNativeArray<TestInterfaceEmpty, V8TestInterfaceEmpty>(info[0], 1, info.GetIsolate(), exceptionState)), exceptionState); 173 } 174 v8SetReturnValue(info, static_cast<double>(impl->uLongLongMethodTestInterfaceEmptyTypeSequenceArg(testInterfaceEmptyTypeSequenceArg))); 175 } 176 177 static void uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 178 { 179 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 180 TestTypedefsV8Internal::uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethod(info); 181 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 182 } 183 184 static void testInterfaceOrTestInterfaceEmptyMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 185 { 186 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 187 RefPtr<TestInterfaceImplementation> result0 = nullptr; 188 RefPtr<TestInterfaceEmpty> result1 = nullptr; 189 impl->testInterfaceOrTestInterfaceEmptyMethod(result0, result1); 190 if (result0) { 191 v8SetReturnValue(info, result0.release()); 192 return; 193 } 194 if (result1) { 195 v8SetReturnValue(info, result1.release()); 196 return; 197 } 198 v8SetReturnValueNull(info); 199 } 200 201 static void testInterfaceOrTestInterfaceEmptyMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 202 { 203 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 204 TestTypedefsV8Internal::testInterfaceOrTestInterfaceEmptyMethodMethod(info); 205 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 206 } 207 208 static void domStringOrDoubleMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 209 { 210 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 211 String result0; 212 Nullable<double> result1; 213 impl->domStringOrDoubleMethod(result0, result1); 214 if (!result0.isNull()) { 215 v8SetReturnValueString(info, result0, info.GetIsolate()); 216 return; 217 } 218 if (result1) { 219 v8SetReturnValue(info, result1.get()); 220 return; 221 } 222 v8SetReturnValueNull(info); 223 } 224 225 static void domStringOrDoubleMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 226 { 227 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 228 TestTypedefsV8Internal::domStringOrDoubleMethodMethod(info); 229 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 230 } 231 232 static void arrayOfStringsMethodArrayOfStringsArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 233 { 234 ExceptionState exceptionState(ExceptionState::ExecutionContext, "arrayOfStringsMethodArrayOfStringsArg", "TestTypedefs", info.Holder(), info.GetIsolate()); 235 if (UNLIKELY(info.Length() < 1)) { 236 setMinimumArityTypeError(exceptionState, 1, info.Length()); 237 exceptionState.throwIfNeeded(); 238 return; 239 } 240 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 241 Vector<String> arrayOfStringsArg; 242 { 243 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(arrayOfStringsArg, toImplArray<String>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); 244 } 245 v8SetReturnValue(info, v8Array(impl->arrayOfStringsMethodArrayOfStringsArg(arrayOfStringsArg), info.Holder(), info.GetIsolate())); 246 } 247 248 static void arrayOfStringsMethodArrayOfStringsArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 249 { 250 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 251 TestTypedefsV8Internal::arrayOfStringsMethodArrayOfStringsArgMethod(info); 252 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 253 } 254 255 static void stringArrayMethodStringArrayArgMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 256 { 257 ExceptionState exceptionState(ExceptionState::ExecutionContext, "stringArrayMethodStringArrayArg", "TestTypedefs", info.Holder(), info.GetIsolate()); 258 if (UNLIKELY(info.Length() < 1)) { 259 setMinimumArityTypeError(exceptionState, 1, info.Length()); 260 exceptionState.throwIfNeeded(); 261 return; 262 } 263 TestTypedefs* impl = V8TestTypedefs::toImpl(info.Holder()); 264 Vector<String> stringArrayArg; 265 { 266 TONATIVE_VOID_EXCEPTIONSTATE_INTERNAL(stringArrayArg, toImplArray<String>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); 267 } 268 v8SetReturnValue(info, v8Array(impl->stringArrayMethodStringArrayArg(stringArrayArg), info.Holder(), info.GetIsolate())); 269 } 270 271 static void stringArrayMethodStringArrayArgMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 272 { 273 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 274 TestTypedefsV8Internal::stringArrayMethodStringArrayArgMethod(info); 275 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 276 } 277 278 static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) 279 { 280 if (UNLIKELY(info.Length() < 1)) { 281 V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor("TestTypedefs", 1, info.Length(), info.GetIsolate()), info.GetIsolate()); 282 return; 283 } 284 V8StringResource<> stringArg; 285 { 286 TOSTRING_VOID_INTERNAL(stringArg, info[0]); 287 } 288 RefPtr<TestTypedefs> impl = TestTypedefs::create(stringArg); 289 v8::Handle<v8::Object> wrapper = info.Holder(); 290 impl->associateWithWrapper(&V8TestTypedefs::wrapperTypeInfo, wrapper, info.GetIsolate()); 291 v8SetReturnValue(info, wrapper); 292 } 293 294 } // namespace TestTypedefsV8Internal 295 296 static const V8DOMConfiguration::AttributeConfiguration V8TestTypedefsAttributes[] = { 297 {"uLongLongAttribute", TestTypedefsV8Internal::uLongLongAttributeAttributeGetterCallback, TestTypedefsV8Internal::uLongLongAttributeAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 298 {"tAttribute", TestTypedefsV8Internal::TestTypedefsConstructorGetter, TestTypedefsV8Internal::TestTypedefsForceSetAttributeOnThisCallback, 0, 0, const_cast<WrapperTypeInfo*>(&V8TestInterface::wrapperTypeInfo), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::DontEnum), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 299 }; 300 301 static const V8DOMConfiguration::MethodConfiguration V8TestTypedefsMethods[] = { 302 {"voidMethodArrayOfLongsArg", TestTypedefsV8Internal::voidMethodArrayOfLongsArgMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts}, 303 {"voidMethodFloatArgStringArg", TestTypedefsV8Internal::voidMethodFloatArgStringArgMethodCallback, 0, 2, V8DOMConfiguration::ExposedToAllScripts}, 304 {"voidMethodTestCallbackInterfaceTypeArg", TestTypedefsV8Internal::voidMethodTestCallbackInterfaceTypeArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts}, 305 {"uLongLongMethodTestInterfaceEmptyTypeSequenceArg", TestTypedefsV8Internal::uLongLongMethodTestInterfaceEmptyTypeSequenceArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts}, 306 {"testInterfaceOrTestInterfaceEmptyMethod", TestTypedefsV8Internal::testInterfaceOrTestInterfaceEmptyMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts}, 307 {"domStringOrDoubleMethod", TestTypedefsV8Internal::domStringOrDoubleMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts}, 308 {"arrayOfStringsMethodArrayOfStringsArg", TestTypedefsV8Internal::arrayOfStringsMethodArrayOfStringsArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts}, 309 {"stringArrayMethodStringArrayArg", TestTypedefsV8Internal::stringArrayMethodStringArrayArgMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts}, 310 }; 311 312 void V8TestTypedefs::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 313 { 314 TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor"); 315 if (!info.IsConstructCall()) { 316 V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestTypedefs"), info.GetIsolate()); 317 return; 318 } 319 320 if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) { 321 v8SetReturnValue(info, info.Holder()); 322 return; 323 } 324 325 TestTypedefsV8Internal::constructor(info); 326 } 327 328 static void installV8TestTypedefsTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 329 { 330 functionTemplate->ReadOnlyPrototype(); 331 332 v8::Local<v8::Signature> defaultSignature; 333 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestTypedefs", v8::Local<v8::FunctionTemplate>(), V8TestTypedefs::internalFieldCount, 334 V8TestTypedefsAttributes, WTF_ARRAY_LENGTH(V8TestTypedefsAttributes), 335 0, 0, 336 V8TestTypedefsMethods, WTF_ARRAY_LENGTH(V8TestTypedefsMethods), 337 isolate); 338 functionTemplate->SetCallHandler(V8TestTypedefs::constructorCallback); 339 functionTemplate->SetLength(1); 340 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 341 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 342 343 // Custom toString template 344 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 345 } 346 347 v8::Handle<v8::FunctionTemplate> V8TestTypedefs::domTemplate(v8::Isolate* isolate) 348 { 349 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestTypedefsTemplate); 350 } 351 352 bool V8TestTypedefs::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 353 { 354 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 355 } 356 357 v8::Handle<v8::Object> V8TestTypedefs::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 358 { 359 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 360 } 361 362 TestTypedefs* V8TestTypedefs::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 363 { 364 return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<TestTypedefs>() : 0; 365 } 366 367 368 void V8TestTypedefs::refObject(ScriptWrappableBase* internalPointer) 369 { 370 internalPointer->toImpl<TestTypedefs>()->ref(); 371 } 372 373 void V8TestTypedefs::derefObject(ScriptWrappableBase* internalPointer) 374 { 375 internalPointer->toImpl<TestTypedefs>()->deref(); 376 } 377 378 WrapperPersistentNode* V8TestTypedefs::createPersistentHandle(ScriptWrappableBase* internalPointer) 379 { 380 ASSERT_NOT_REACHED(); 381 return 0; 382 } 383 384 template<> 385 v8::Handle<v8::Value> toV8NoInline(TestTypedefs* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 386 { 387 return toV8(impl, creationContext, isolate); 388 } 389 390 } // namespace blink 391