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